Skip to content

Commit 9bf2fc7

Browse files
jairmyreesamvaity
andauthored
Tables Test Proxy Migration (Azure#34233)
* Change testBases * Disabling failing test * Minor Adjustments * Set failing RECORD tests to live only * Custom Matchers & Sanitizers * Some more progress * more adjustments * Almost ready to open PR * Update TableAsyncClientTest.java * Some bug fixes and better regex * More edits to PR. Pausing until core-test releases * Fixed Test Migration. Need to remove mock token. TODO: Remove mock token when core-test releases * Ready to open PR for review * Update sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TestUtils.java Co-authored-by: Sameeksha Vaity <savaity@microsoft.com> --------- Co-authored-by: Sameeksha Vaity <savaity@microsoft.com>
1 parent 1e42154 commit 9bf2fc7

File tree

164 files changed

+25913
-13270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+25913
-13270
lines changed

sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableAsyncClientTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
package com.azure.data.tables;
55

6+
import com.azure.core.credential.TokenCredential;
67
import com.azure.core.http.HttpClient;
78
import com.azure.core.http.policy.ExponentialBackoff;
89
import com.azure.core.http.policy.HttpLogDetailLevel;
910
import com.azure.core.http.policy.HttpLogOptions;
1011
import com.azure.core.http.policy.RetryPolicy;
1112
import com.azure.core.http.rest.Response;
1213
import com.azure.core.test.http.AssertingHttpClientBuilder;
14+
import com.azure.core.test.utils.MockTokenCredential;
1315
import com.azure.core.test.utils.TestResourceNamer;
1416
import com.azure.core.util.Configuration;
1517
import com.azure.data.tables.models.ListEntitiesOptions;
@@ -27,13 +29,11 @@
2729
import com.azure.data.tables.sas.TableSasPermission;
2830
import com.azure.data.tables.sas.TableSasProtocol;
2931
import com.azure.data.tables.sas.TableSasSignatureValues;
30-
import com.azure.identity.ClientSecretCredential;
3132
import com.azure.identity.ClientSecretCredentialBuilder;
3233
import org.junit.jupiter.api.AfterAll;
3334
import org.junit.jupiter.api.Assertions;
3435
import org.junit.jupiter.api.Assumptions;
3536
import org.junit.jupiter.api.BeforeAll;
36-
import org.junit.jupiter.api.Disabled;
3737
import org.junit.jupiter.api.Test;
3838
import reactor.test.StepVerifier;
3939

@@ -112,14 +112,19 @@ public void createTableWithMultipleTenants() {
112112
// Arrange
113113
final String tableName2 = testResourceNamer.randomName("tableName", 20);
114114

115+
TokenCredential credential = null;
116+
if (interceptorManager.isPlaybackMode()) {
117+
credential = new MockTokenCredential();
118+
} else if (interceptorManager.isRecordMode()) {
115119
// The tenant ID does not matter as the correct on will be extracted from the authentication challenge in
116120
// contained in the response the server provides to a first "naive" unauthenticated request.
117-
final ClientSecretCredential credential = new ClientSecretCredentialBuilder()
118-
.clientId(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_ID", "clientId"))
119-
.clientSecret(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_SECRET", "clientSecret"))
120-
.tenantId(testResourceNamer.randomUuid())
121-
.additionallyAllowedTenants("*")
122-
.build();
121+
credential = new ClientSecretCredentialBuilder()
122+
.clientId(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_ID", "clientId"))
123+
.clientSecret(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_SECRET", "clientSecret"))
124+
.tenantId(testResourceNamer.randomUuid())
125+
.additionallyAllowedTenants("*")
126+
.build();
127+
}
123128

124129
final TableAsyncClient tableClient2 =
125130
getClientBuilder(tableName2, Configuration.getGlobalConfiguration().get("TABLES_ENDPOINT",
@@ -1057,15 +1062,14 @@ public void generateSasTokenWithAllParameters() {
10571062
}
10581063

10591064
@Test
1060-
@Disabled
10611065
// Disabling as this currently fails and prevents merging https://github.com/Azure/azure-sdk-for-java/pull/28522.
10621066
// TODO: Will fix in a separate PR. -vicolina
10631067
public void canUseSasTokenToCreateValidTableClient() {
10641068
// SAS tokens at the table level have not been working with Cosmos endpoints.
10651069
// TODO: Will re-enable once the above is fixed. -vicolina
10661070
Assumptions.assumeFalse(IS_COSMOS_TEST, "Skipping Cosmos test.");
10671071

1068-
final OffsetDateTime expiryTime = OffsetDateTime.of(2021, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
1072+
final OffsetDateTime expiryTime = OffsetDateTime.of(2023, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
10691073
final TableSasPermission permissions = TableSasPermission.parse("a");
10701074
final TableSasProtocol protocol = TableSasProtocol.HTTPS_HTTP;
10711075

sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableClientTest.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.azure.data.tables;
55

6+
import com.azure.core.credential.TokenCredential;
67
import com.azure.core.http.HttpClient;
78
import com.azure.core.http.policy.ExponentialBackoff;
89
import com.azure.core.http.policy.HttpLogDetailLevel;
@@ -12,6 +13,7 @@
1213
import com.azure.core.http.rest.PagedResponse;
1314
import com.azure.core.http.rest.Response;
1415
import com.azure.core.test.http.AssertingHttpClientBuilder;
16+
import com.azure.core.test.utils.MockTokenCredential;
1517
import com.azure.core.test.utils.TestResourceNamer;
1618
import com.azure.core.util.Configuration;
1719
import com.azure.data.tables.models.ListEntitiesOptions;
@@ -30,12 +32,10 @@
3032
import com.azure.data.tables.sas.TableSasPermission;
3133
import com.azure.data.tables.sas.TableSasProtocol;
3234
import com.azure.data.tables.sas.TableSasSignatureValues;
33-
import com.azure.identity.ClientSecretCredential;
3435
import com.azure.identity.ClientSecretCredentialBuilder;
3536

3637
import org.junit.jupiter.api.Assertions;
3738
import org.junit.jupiter.api.Assumptions;
38-
import org.junit.jupiter.api.Disabled;
3939
import org.junit.jupiter.api.Test;
4040

4141
import java.time.Duration;
@@ -73,8 +73,11 @@ protected void beforeTest() {
7373
final String tableName = testResourceNamer.randomName("tableName", 20);
7474
final String connectionString = TestUtils.getConnectionString(interceptorManager.isPlaybackMode());
7575
tableClient = getClientBuilder(tableName, connectionString).buildClient();
76+
tableClient.createTable();
77+
}
7678

77-
tableClient.createTable();
79+
protected void afterTest() {
80+
tableClient.deleteTable();
7881
}
7982

8083
@Test
@@ -96,26 +99,31 @@ public void createTable() {
9699
public void createTableWithMultipleTenants() {
97100
// This feature works only in Storage endpoints with service version 2020_12_06.
98101
Assumptions.assumeTrue(tableClient.getTableEndpoint().contains("core.windows.net")
99-
&& tableClient.getServiceVersion() == TableServiceVersion.V2020_12_06);
102+
&& tableClient.getServiceVersion() == TableServiceVersion.V2020_12_06);
100103

101104
// Arrange
102105
final String tableName2 = testResourceNamer.randomName("tableName", 20);
103106

107+
TokenCredential credential = null;
108+
if (interceptorManager.isPlaybackMode()) {
109+
credential = new MockTokenCredential();
110+
} else if (interceptorManager.isRecordMode()) {
104111
// The tenant ID does not matter as the correct on will be extracted from the authentication challenge in
105112
// contained in the response the server provides to a first "naive" unauthenticated request.
106-
final ClientSecretCredential credential = new ClientSecretCredentialBuilder()
107-
.clientId(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_ID", "clientId"))
108-
.clientSecret(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_SECRET", "clientSecret"))
109-
.tenantId(testResourceNamer.randomUuid())
110-
.additionallyAllowedTenants("*")
111-
.build();
113+
credential = new ClientSecretCredentialBuilder()
114+
.clientId(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_ID", "clientId"))
115+
.clientSecret(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_SECRET", "clientSecret"))
116+
.tenantId(testResourceNamer.randomUuid())
117+
.additionallyAllowedTenants("*")
118+
.build();
119+
}
112120

113121
final TableClient tableClient2 =
114122
getClientBuilder(tableName2, Configuration.getGlobalConfiguration().get("TABLES_ENDPOINT",
115123
"https://tablestests.table.core.windows.com"), credential, true).buildClient();
116-
117124
// Act & Assert
118125
// This request will use the tenant ID extracted from the previous request.
126+
119127
assertNotNull(tableClient2.createTable());
120128

121129
final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
@@ -771,7 +779,8 @@ public void submitTransaction() {
771779

772780
@Test
773781
public void submitTransactionAllActions() {
774-
submitTransactionAllActionsImpl("partitionKey", "rowKey");
782+
Runnable func = () -> submitTransactionAllActionsImpl("partitionKey", "rowKey");
783+
func.run();
775784
}
776785

777786
@Test
@@ -1017,15 +1026,14 @@ public void generateSasTokenWithAllParameters() {
10171026
}
10181027

10191028
@Test
1020-
@Disabled
10211029
// Disabling as this currently fails and prevents merging https://github.com/Azure/azure-sdk-for-java/pull/28522.
10221030
// TODO: Will fix in a separate PR. -vicolina
10231031
public void canUseSasTokenToCreateValidTableClient() {
10241032
// SAS tokens at the table level have not been working with Cosmos endpoints.
10251033
// TODO: Will re-enable once the above is fixed. -vicolina
10261034
Assumptions.assumeFalse(IS_COSMOS_TEST, "Skipping Cosmos test.");
10271035

1028-
final OffsetDateTime expiryTime = OffsetDateTime.of(2021, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
1036+
final OffsetDateTime expiryTime = OffsetDateTime.of(2023, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
10291037
final TableSasPermission permissions = TableSasPermission.parse("a");
10301038
final TableSasProtocol protocol = TableSasProtocol.HTTPS_HTTP;
10311039

sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableClientTestBase.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import com.azure.core.http.policy.HttpLogDetailLevel;
99
import com.azure.core.http.policy.HttpLogOptions;
1010
import com.azure.core.http.policy.HttpPipelinePolicy;
11-
import com.azure.core.test.TestBase;
11+
import com.azure.core.test.TestProxyTestBase;
12+
1213
import org.junit.jupiter.api.Test;
1314

14-
public abstract class TableClientTestBase extends TestBase {
15+
public abstract class TableClientTestBase extends TestProxyTestBase {
1516
protected static final HttpClient DEFAULT_HTTP_CLIENT = HttpClient.createDefault();
1617
protected static final boolean IS_COSMOS_TEST = TestUtils.isCosmosTest();
1718

@@ -52,12 +53,12 @@ private TableClientBuilder configureTestClientBuilder(TableClientBuilder tableCl
5253
} else {
5354
tableClientBuilder.httpClient(buildAssertingClient(DEFAULT_HTTP_CLIENT));
5455

55-
if (!interceptorManager.isLiveMode()) {
56+
if (interceptorManager.isRecordMode()) {
5657
recordPolicy = interceptorManager.getRecordPolicy();
5758
tableClientBuilder.addPolicy(recordPolicy);
5859
}
5960
}
60-
61+
TestUtils.addTestProxyTestSanitizersAndMatchers(interceptorManager);
6162
return tableClientBuilder;
6263
}
6364

sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
package com.azure.data.tables;
55

6+
import com.azure.core.credential.TokenCredential;
67
import com.azure.core.http.HttpClient;
78
import com.azure.core.http.policy.ExponentialBackoff;
89
import com.azure.core.http.policy.HttpLogDetailLevel;
910
import com.azure.core.http.policy.HttpLogOptions;
1011
import com.azure.core.http.policy.RetryPolicy;
1112
import com.azure.core.test.http.AssertingHttpClientBuilder;
13+
import com.azure.core.test.utils.MockTokenCredential;
1214
import com.azure.core.util.Configuration;
1315
import com.azure.data.tables.models.ListTablesOptions;
1416
import com.azure.data.tables.models.TableEntity;
@@ -24,13 +26,11 @@
2426
import com.azure.data.tables.sas.TableAccountSasSignatureValues;
2527
import com.azure.data.tables.sas.TableSasIpRange;
2628
import com.azure.data.tables.sas.TableSasProtocol;
27-
import com.azure.identity.ClientSecretCredential;
2829
import com.azure.identity.ClientSecretCredentialBuilder;
2930
import org.junit.jupiter.api.AfterAll;
3031
import org.junit.jupiter.api.Assertions;
3132
import org.junit.jupiter.api.Assumptions;
3233
import org.junit.jupiter.api.BeforeAll;
33-
import org.junit.jupiter.api.Disabled;
3434
import org.junit.jupiter.api.Test;
3535
import reactor.test.StepVerifier;
3636

@@ -79,7 +79,6 @@ static void afterAll() {
7979
@Override
8080
protected void beforeTest() {
8181
final String connectionString = TestUtils.getConnectionString(interceptorManager.isPlaybackMode());
82-
8382
serviceClient = getClientBuilder(connectionString).buildAsyncClient();
8483
}
8584

@@ -108,15 +107,19 @@ public void serviceCreateTableWithMultipleTenants() {
108107
// Arrange
109108
String tableName = testResourceNamer.randomName("tableName", 20);
110109

110+
TokenCredential credential = null;
111+
if (interceptorManager.isPlaybackMode()) {
112+
credential = new MockTokenCredential();
113+
} else if (interceptorManager.isRecordMode()) {
111114
// The tenant ID does not matter as the correct on will be extracted from the authentication challenge in
112115
// contained in the response the server provides to a first "naive" unauthenticated request.
113-
final ClientSecretCredential credential = new ClientSecretCredentialBuilder()
114-
.clientId(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_ID", "clientId"))
115-
.clientSecret(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_SECRET", "clientSecret"))
116-
.tenantId(testResourceNamer.randomUuid())
117-
.additionallyAllowedTenants("*")
118-
.build();
119-
116+
credential = new ClientSecretCredentialBuilder()
117+
.clientId(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_ID", "clientId"))
118+
.clientSecret(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_SECRET", "clientSecret"))
119+
.tenantId(testResourceNamer.randomUuid())
120+
.additionallyAllowedTenants("*")
121+
.build();
122+
}
120123
final TableServiceAsyncClient tableServiceAsyncClient =
121124
getClientBuilder(Configuration.getGlobalConfiguration().get("TABLES_ENDPOINT",
122125
"https://tablestests.table.core.windows.com"), credential, true).buildAsyncClient();
@@ -402,11 +405,10 @@ public void generateAccountSasTokenWithAllParameters() {
402405
}
403406

404407
@Test
405-
@Disabled
406408
// Disabling as this currently fails and prevents merging https://github.com/Azure/azure-sdk-for-java/pull/28522.
407409
// TODO: Will fix in a separate PR. -vicolina
408410
public void canUseSasTokenToCreateValidTableClient() {
409-
final OffsetDateTime expiryTime = OffsetDateTime.of(2021, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
411+
final OffsetDateTime expiryTime = OffsetDateTime.of(2023, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
410412
final TableAccountSasPermission permissions = TableAccountSasPermission.parse("a");
411413
final TableAccountSasService services = new TableAccountSasService().setTableAccess(true);
412414
final TableAccountSasResourceType resourceTypes = new TableAccountSasResourceType().setObject(true);

sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.azure.data.tables;
55

6+
import com.azure.core.credential.TokenCredential;
67
import com.azure.core.http.HttpClient;
78
import com.azure.core.http.policy.ExponentialBackoff;
89
import com.azure.core.http.policy.HttpLogDetailLevel;
@@ -11,6 +12,7 @@
1112
import com.azure.core.http.rest.PagedResponse;
1213
import com.azure.core.http.rest.Response;
1314
import com.azure.core.test.http.AssertingHttpClientBuilder;
15+
import com.azure.core.test.utils.MockTokenCredential;
1416
import com.azure.core.util.Configuration;
1517
import com.azure.data.tables.models.ListTablesOptions;
1618
import com.azure.data.tables.models.TableEntity;
@@ -28,10 +30,8 @@
2830
import com.azure.data.tables.sas.TableAccountSasSignatureValues;
2931
import com.azure.data.tables.sas.TableSasIpRange;
3032
import com.azure.data.tables.sas.TableSasProtocol;
31-
import com.azure.identity.ClientSecretCredential;
3233
import com.azure.identity.ClientSecretCredentialBuilder;
3334
import org.junit.jupiter.api.Assumptions;
34-
import org.junit.jupiter.api.Disabled;
3535
import org.junit.jupiter.api.Test;
3636
import reactor.test.StepVerifier;
3737

@@ -72,7 +72,6 @@ protected HttpClient buildAssertingClient(HttpClient httpClient) {
7272
@Override
7373
protected void beforeTest() {
7474
final String connectionString = TestUtils.getConnectionString(interceptorManager.isPlaybackMode());
75-
7675
serviceClient = getClientBuilder(connectionString).buildClient();
7776
}
7877

@@ -97,16 +96,21 @@ public void serviceCreateTableWithMultipleTenants() {
9796

9897
// Arrange
9998
String tableName = testResourceNamer.randomName("tableName", 20);
99+
String secondTableName = testResourceNamer.randomName("secondTableName", 20);
100100

101+
TokenCredential credential = null;
102+
if (interceptorManager.isPlaybackMode()) {
103+
credential = new MockTokenCredential();
104+
} else if (interceptorManager.isRecordMode()) {
101105
// The tenant ID does not matter as the correct on will be extracted from the authentication challenge in
102106
// contained in the response the server provides to a first "naive" unauthenticated request.
103-
final ClientSecretCredential credential = new ClientSecretCredentialBuilder()
104-
.clientId(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_ID", "clientId"))
105-
.clientSecret(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_SECRET", "clientSecret"))
106-
.tenantId(testResourceNamer.randomUuid())
107-
.additionallyAllowedTenants("*")
108-
.build();
109-
107+
credential = new ClientSecretCredentialBuilder()
108+
.clientId(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_ID", "clientId"))
109+
.clientSecret(Configuration.getGlobalConfiguration().get("TABLES_CLIENT_SECRET", "clientSecret"))
110+
.tenantId(testResourceNamer.randomUuid())
111+
.additionallyAllowedTenants("*")
112+
.build();
113+
}
110114
final TableServiceClient tableServiceClient =
111115
getClientBuilder(Configuration.getGlobalConfiguration().get("TABLES_ENDPOINT",
112116
"https://tablestests.table.core.windows.com"), credential, true).buildClient();
@@ -115,10 +119,8 @@ public void serviceCreateTableWithMultipleTenants() {
115119
// This request will use the tenant ID extracted from the previous request.
116120
assertNotNull(tableServiceClient.createTable(tableName));
117121

118-
tableName = testResourceNamer.randomName("tableName", 20);
119-
120122
// All other requests will also use the tenant ID obtained from the auth challenge.
121-
assertNotNull(tableServiceClient.createTable(tableName));
123+
assertNotNull(tableServiceClient.createTable(secondTableName));
122124
}
123125

124126
@Test
@@ -349,11 +351,10 @@ public void generateAccountSasTokenWithAllParameters() {
349351
}
350352

351353
@Test
352-
@Disabled
353354
// Disabling as this currently fails and prevents merging https://github.com/Azure/azure-sdk-for-java/pull/28522.
354355
// TODO: Will fix in a separate PR. -vicolina
355356
public void canUseSasTokenToCreateValidTableClient() {
356-
final OffsetDateTime expiryTime = OffsetDateTime.of(2021, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
357+
final OffsetDateTime expiryTime = OffsetDateTime.of(2023, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
357358
final TableAccountSasPermission permissions = TableAccountSasPermission.parse("a");
358359
final TableAccountSasService services = new TableAccountSasService().setTableAccess(true);
359360
final TableAccountSasResourceType resourceTypes = new TableAccountSasResourceType().setObject(true);

0 commit comments

Comments
 (0)