Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing for Tables Autorest Code #12512

Merged
merged 34 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
576d2be
apply old
eboyd23 Jun 15, 2020
dea2498
apply old
eboyd23 Jun 15, 2020
081200a
testing works on this commit
eboyd23 Jun 16, 2020
f6ea265
stashing
eboyd23 Jun 16, 2020
1e1efd8
additional testing
eboyd23 Jul 1, 2020
2397b88
stashing
eboyd23 Jun 22, 2020
c2e8eb7
stashing
eboyd23 Jun 24, 2020
b2ebec7
adding tests
eboyd23 Jun 25, 2020
d54ae25
fixing format and POM
eboyd23 Jun 25, 2020
ac21a3d
arrange-act-assert formatting
eboyd23 Jun 29, 2020
5086d4a
stashing
eboyd23 Jun 29, 2020
68f0cea
adding tests
eboyd23 Jun 30, 2020
f13cca6
reformat
eboyd23 Jun 30, 2020
d4c187a
remove system prints
eboyd23 Jun 30, 2020
335d646
adding playback jsons
eboyd23 Jun 30, 2020
7133df8
recent changes
eboyd23 Jun 30, 2020
2281563
fix pom
eboyd23 Jul 1, 2020
ba399fe
playback mode
eboyd23 Jul 1, 2020
ca8b84c
fix incorrect changes in readme
eboyd23 Jul 1, 2020
e849c5e
fix pom
eboyd23 Jul 1, 2020
0216fde
fixing pom
eboyd23 Jul 1, 2020
8b9e906
fixing version
eboyd23 Jul 1, 2020
3558d0f
fix impl
eboyd23 Jul 1, 2020
5f24375
fixing checkstyles
eboyd23 Jul 1, 2020
229116a
fixing checkstyles p2
eboyd23 Jul 1, 2020
06e255a
connie edits
eboyd23 Jul 2, 2020
8cb259d
connie edits 2
eboyd23 Jul 2, 2020
9b19368
forgot in last commit
eboyd23 Jul 2, 2020
cef9820
add changelog
eboyd23 Jul 2, 2020
1315b59
connie comments
eboyd23 Jul 6, 2020
74c33b5
fixing pipeline issues
eboyd23 Jul 6, 2020
1351fbe
assertion for setup
eboyd23 Jul 6, 2020
b7f8400
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-java …
eboyd23 Jul 6, 2020
767bfdf
fix impl
eboyd23 Jul 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
stashing
  • Loading branch information
eboyd23 committed Jul 6, 2020
commit c2e8eb76197132c777e93c39fa4b1b074f56c603
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.storage.common.policy.StorageSharedKeyCredentialPolicy;

import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.Collator;
import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -53,7 +54,7 @@ public String getAccountName() {

public String generateAuthorizationHeader(URL requestURL, String httpMethod, Map<String, String> headers) {
String signature = StorageImplUtils.computeHMac256(this.accountKey, this.buildStringToSign(requestURL, httpMethod, headers));
return String.format("SharedKey %s:%s", this.accountName, signature);
return String.format("SharedKeyLite %s:%s", this.accountName, signature);
}

public String computeHmac256(String stringToSign) {
Expand All @@ -64,18 +65,15 @@ private String buildStringToSign(URL requestURL, String httpMethod, Map<String,
String contentLength = (String)headers.get("Content-Length");
contentLength = contentLength.equals("0") ? "" : contentLength;
String dateHeader = headers.containsKey("x-ms-date") ? "" : this.getStandardHeaderValue(headers, "Date");
String a = String.join("\n",
httpMethod,
this.getStandardHeaderValue(headers, "Content-MD5"), //content-md5
this.getStandardHeaderValue(headers, "Content-Type"), //content-type
dateHeader,
"/telboytrial/table3()&$select=name"
);
// String a = String.join("\n",
// httpMethod,
// this.getStandardHeaderValue(headers, "Content-MD5"), //content-md5
// this.getStandardHeaderValue(headers, "Content-Type"), //content-type
// dateHeader,
// "/telboytrial/table3()&$select=name"
// );

String s = String.join("\n",
httpMethod, //verb
this.getStandardHeaderValue(headers, "Content-MD5"), //content-md5
this.getStandardHeaderValue(headers, "Content-Type"), //content-type
dateHeader, //date
this.getCanonicalizedResource(requestURL)); //canonicalized resoucre
System.out.println("EB-t vvv");
Expand Down Expand Up @@ -137,9 +135,11 @@ private String getCanonicalizedResource(URL requestURL) {
String[] queryParamValues = (String[])queryParams.get(queryParamName);
Arrays.sort(queryParamValues);
String queryParamValuesStr = String.join(",", queryParamValues);
canonicalizedResource.append("\n").append(queryParamName.toLowerCase(Locale.ROOT)).append(":").append(queryParamValuesStr);
if(queryParamName.equals("comp")) {
canonicalizedResource.append("?").append(queryParamName.toLowerCase(Locale.ROOT)).append("=").append(queryParamValuesStr);
}
}

// canonicalizedResource.append("?").append("comp".toLowerCase(Locale.ROOT)).append("=").append("metadata");
return canonicalizedResource.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import com.azure.data.tables.implementation.AzureTableImplBuilder;

import com.azure.data.tables.implementation.TablesImpl;
import com.azure.data.tables.implementation.models.OdataMetadataFormat;
import com.azure.data.tables.implementation.models.QueryOptions;
import com.azure.data.tables.implementation.models.ResponseFormat;
import com.azure.data.tables.implementation.models.TableProperties;
import com.azure.data.tables.implementation.models.*;
import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.common.implementation.connectionstring.StorageAuthenticationSettings;
import com.azure.storage.common.implementation.connectionstring.StorageConnectionString;
Expand All @@ -21,6 +18,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.test.StepVerifier;
import reactor.test.publisher.TestPublisher;


import java.util.*;
Expand Down Expand Up @@ -103,30 +101,36 @@ AzureTableImpl auth () {
}

@Test
void createTable(String tableName) {

void createTable() {
String tableName = "testTable3";
AzureTableImpl azureTable = auth();

TableProperties tableProperties = new TableProperties().setTableName(tableName);
QueryOptions queryOptions = new QueryOptions();
String requestId = UUID.randomUUID().toString();


//successful path
StepVerifier.create(azureTable.getTables().createWithResponseAsync(tableProperties, requestId,
ResponseFormat.RETURN_CONTENT, queryOptions, Context.NONE))
ResponseFormat.RETURN_CONTENT, null, Context.NONE))
.assertNext(response -> {
System.out.println(response);
Assertions.assertEquals(201, response.getStatusCode());
})
.expectComplete()
.verify();

//error if it tries to create a table with the same name that already exists
StepVerifier.create(azureTable.getTables().createWithResponseAsync(tableProperties, requestId,
ResponseFormat.RETURN_CONTENT, null, Context.NONE))
.expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class)
.verify();

//delete table
//deleteTableHelper(tableName);

}


// tests deleting a table
@Test
void deleteTable(String tableName) {
void deleteTableHelper(String tableName) {

AzureTableImpl azureTable = auth();
String requestId = UUID.randomUUID().toString();
Expand All @@ -144,33 +148,167 @@ void deleteTable(String tableName) {
}

@Test
void queryTable(String tableName){
void deleteTable() {
String tableName = "testDeleteTable2";
AzureTableImpl azureTable = auth();
TableProperties tableProperties = new TableProperties().setTableName(tableName);

//create than delete a table, successful path
azureTable.getTables().createWithResponseAsync(tableProperties, UUID.randomUUID().toString(),
ResponseFormat.RETURN_CONTENT, null, Context.NONE).subscribe(Void -> {
StepVerifier.create(azureTable.getTables().deleteWithResponseAsync(tableName, UUID.randomUUID().toString(),
Context.NONE))
.assertNext(response -> {
Assertions.assertEquals(204, response.getStatusCode());
})
.expectComplete()
.verify();
});

StepVerifier.create(azureTable.getTables().deleteWithResponseAsync(tableName, UUID.randomUUID().toString(),
Context.NONE))
.expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class)
.verify();
}

@Test
void queryTable(){
String tableName = "testTable3";
AzureTableImpl azureTable = auth();
String requestId = UUID.randomUUID().toString();
QueryOptions queryOptions = new QueryOptions();
queryOptions.setTop(2);
QueryOptions queryOptions = new QueryOptions()
.setFormat(OdataMetadataFormat.APPLICATION_JSON_ODATA_MINIMALMETADATA)
.setTop(2);

StepVerifier.create(azureTable.getTables().queryWithResponseAsync(requestId, tableName,
StepVerifier.create(azureTable.getTables().queryWithResponseAsync(requestId, null,
queryOptions, Context.NONE))
.assertNext(response -> {
System.out.println(response);
System.out.println("OUT" + response.getValue().getValue().get(0).getTableName());
//System.out.println((TableQueryResponse) response);
Assertions.assertEquals(200, response.getStatusCode());
})
.expectComplete()
.verify();
}

// @Test
// void insertAndDeleteWithEtag(){
// String tableName = "table3";
// AzureTableImpl azureTable = auth();
// String requestId = UUID.randomUUID().toString();
// String pk = "Product";
// String rk = "whiteboard2";
// String etag = "";
//
// Map<String, Object> properties = new HashMap<>();
// properties.put("PartitionKey", pk);
// properties.put("RowKey", rk);
//
// TestPublisher<String> testPublisher = TestPublisher.create();
// //insert
// StepVerifier.create(azureTable.getTables().insertEntityWithResponseAsync(tableName, 500,
// requestId, ResponseFormat.RETURN_CONTENT, properties, null, Context.NONE))
// .assertNext(response -> {
// System.out.println(response);
// response.getValue().get("odata.etag");
// Assertions.assertEquals(201, response.getStatusCode());
//
// StepVerifier.create(azureTable.getTables().deleteEntityWithResponseAsync(tableName, pk,
// rk, response.getValue().get("odata.etag").toString(), 500, requestId, null, Context.NONE))
// .assertNext(response2 -> {
// System.out.println(response2);
// Assertions.assertEquals(204, response2.getStatusCode());
// })
// .expectComplete()
// .verify();
//
// })
// .expectComplete()
// .verify();
// }

@Test
void insertAndDeleteNoEtag(){
// String tableName = "table3";
// String pk = "product";
// String rk = "glue";
// insertEntity(tableName,pk, rk);
// deleteEntity(tableName,pk,rk);
}

@Test
void insertMergeDeleteEntity(){
String tableName = "table3";
Map<String, Object> properties = new HashMap<>();
properties.put("PartitionKey", "Store");
properties.put("RowKey", "Atlanta");
properties.put("Size", "200");
insertEntity(tableName, properties);
properties.put("Employees", "15");
properties.remove("Size");
mergeEntity(tableName,properties);
//deleteEntity(tableName,properties);
}

@Test
void insertUpdateDeleteEntity(){
String tableName = "table3";
Map<String, Object> properties = new HashMap<>();
properties.put("PartitionKey", "Store");
properties.put("RowKey", "Boston");
properties.put("Size", "200");
insertEntity(tableName,properties);
properties.put("Employees", "15");
properties.remove("Size");
updateEntity(tableName, properties);
deleteEntity(tableName, properties);
}

void updateEntity(String tableName, Map<String, Object> properties) {
AzureTableImpl azureTable = auth();
StepVerifier.create(azureTable.getTables().updateEntityWithResponseAsync(tableName, properties.get("PartitionKey").toString(),
properties.get("RowKey").toString(), 500, UUID.randomUUID().toString(), "*", properties, null, Context.NONE))
.assertNext(response -> {
Assertions.assertEquals(204, response.getStatusCode());
})
.expectComplete()
.verify();
}

@Test
void insertEntity(String tableName){
void mergeEntity(String tableName, Map<String, Object> properties ){
AzureTableImpl azureTable = auth();
String requestId = UUID.randomUUID().toString();

Map<String, Object> properties = new HashMap<>();
properties.put("PartitionKey", "pk");
properties.put("RowKey", "rk");
StepVerifier.create(azureTable.getTables().mergeEntityWithResponseAsync(tableName, properties.get("PartitionKey").toString(),
properties.get("RowKey").toString(), 500, UUID.randomUUID().toString(), "*", properties, null, Context.NONE))
.assertNext(response -> {
Assertions.assertEquals(204, response.getStatusCode());
})
.expectComplete()
.verify();
}

@Test
void insertEntity(String tableName, Map<String, Object> properties){
AzureTableImpl azureTable = auth();
String requestId = UUID.randomUUID().toString();

StepVerifier.create(azureTable.getTables().insertEntityWithResponseAsync(tableName, 500,
requestId, ResponseFormat.RETURN_CONTENT, properties, null, Context.NONE))
.assertNext(response -> {
Assertions.assertEquals(201, response.getStatusCode());
})
.expectComplete()
.verify();
}

@Test
void deleteEntity(String tableName, Map<String, Object> properties){
AzureTableImpl azureTable = auth();
String requestId = UUID.randomUUID().toString();

StepVerifier.create(azureTable.getTables().deleteEntityWithResponseAsync(tableName, properties.get("PartitionKey").toString(),
properties.get("RowKey").toString(), "*", 500, requestId, null, Context.NONE))
.assertNext(response -> {
System.out.println(response);
Assertions.assertEquals(204, response.getStatusCode());
Expand Down Expand Up @@ -202,7 +340,7 @@ void allTests() {
//deleteTable(tableName);
//createTable(tableName);
//insertEntity(tableName);
queryEntity(tableName);
//queryEntity(tableName);
//queryTable(tableName);
//deleteTable(tableName);

Expand Down