From 25326412ccfb1d1ce26de0fcc82d9a1367701fbc Mon Sep 17 00:00:00 2001 From: Shawn Fang Date: Tue, 3 Dec 2024 15:07:07 -0800 Subject: [PATCH] rerun maven in schemaregistry sdk --- .../SchemaRegistryAsyncClient.java | 46 +++++++++---------- .../schemaregistry/SchemaRegistryClient.java | 40 ++++++++-------- .../SchemaRegistryClientBuilder.java | 20 ++++---- .../implementation/SchemaRegistryHelper.java | 20 ++++---- .../azure/data/schemaregistry/Constants.java | 9 ++-- .../SchemaRegistryAsyncClientCustomTests.java | 11 ++--- .../SchemaRegistryAsyncClientJsonTests.java | 12 ++--- ...chemaRegistryAsyncClientPlaybackTests.java | 35 ++++++-------- .../SchemaRegistryAsyncClientTests.java | 38 ++++++++------- .../SchemaRegistryAsyncClientTestsBase.java | 44 +++++++++--------- .../SchemaRegistryClientBuilderTest.java | 34 ++++++-------- .../SchemaRegistryClientTests.java | 31 ++++++------- 12 files changed, 155 insertions(+), 185 deletions(-) diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java index 684d774f3bdac..57ad8c1e8dc5f 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java @@ -213,8 +213,7 @@ public String getFullyQualifiedNamespace() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono registerSchema(String groupName, String name, String schemaDefinition, SchemaFormat format) { - return registerSchemaWithResponse(groupName, name, schemaDefinition, format) - .map(Response::getValue); + return registerSchemaWithResponse(groupName, name, schemaDefinition, format).map(Response::getValue); } /** @@ -246,8 +245,8 @@ public Mono registerSchema(String groupName, String name, Stri @ServiceMethod(returns = ReturnType.SINGLE) public Mono> registerSchemaWithResponse(String groupName, String name, String schemaDefinition, SchemaFormat format) { - return FluxUtil.withContext(context -> registerSchemaWithResponse(groupName, name, schemaDefinition, - format, context)); + return FluxUtil + .withContext(context -> registerSchemaWithResponse(groupName, name, schemaDefinition, format, context)); } Mono> registerSchemaWithResponse(String groupName, String name, String schemaDefinition, @@ -269,11 +268,12 @@ Mono> registerSchemaWithResponse(String groupName, St final com.azure.data.schemaregistry.implementation.models.SchemaFormat contentType = SchemaRegistryHelper.getContentType(format); - return restService.getSchemas().registerWithResponseAsync(groupName, name, contentType.toString(), binaryData, - binaryData.getLength(), context) + return restService.getSchemas() + .registerWithResponseAsync(groupName, name, contentType.toString(), binaryData, binaryData.getLength(), + context) .map(response -> { - final SchemaProperties registered = SchemaRegistryHelper.getSchemaProperties( - response.getDeserializedHeaders(), response.getHeaders(), format); + final SchemaProperties registered = SchemaRegistryHelper + .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); return new SimpleResponse<>(response, registered); }); } @@ -359,11 +359,12 @@ Mono> getSchemaWithResponse(String schemaId, Cont return monoError(logger, new NullPointerException("'schemaId' should not be null.")); } - return this.restService.getSchemas().getByIdWithResponseAsync(schemaId, context) + return this.restService.getSchemas() + .getByIdWithResponseAsync(schemaId, context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .flatMap(response -> { - SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties( - response.getDeserializedHeaders(), response.getHeaders()); + SchemaProperties schemaObject = SchemaRegistryHelper + .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); return convertToString(response.getValue(), response.getHeaders()) .map(schema -> new SimpleResponse<>(response, new SchemaRegistrySchema(schemaObject, schema))); }); @@ -376,22 +377,21 @@ Mono> getSchemaWithResponse(String groupName, Str return monoError(logger, new NullPointerException("'groupName' should not be null.")); } - return this.restService.getSchemas().getSchemaVersionWithResponseAsync(groupName, schemaName, schemaVersion, - context) + return this.restService.getSchemas() + .getSchemaVersionWithResponseAsync(groupName, schemaName, schemaVersion, context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .flatMap(response -> { final Flux schemaFlux = response.getValue(); - SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties( - response.getDeserializedHeaders(), response.getHeaders()); + SchemaProperties schemaObject = SchemaRegistryHelper + .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); if (schemaFlux == null) { return Mono.error(new IllegalArgumentException(String.format( - "Schema definition should not be null. Group Name: %s. Schema Name: %s. Version: %d", - groupName, schemaName, schemaVersion))); + "Schema definition should not be null. Group Name: %s. Schema Name: %s. Version: %d", groupName, + schemaName, schemaVersion))); } return convertToString(schemaFlux, response.getHeaders()) - .map(schema -> new SimpleResponse<>( - response.getRequest(), response.getStatusCode(), + .map(schema -> new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), new SchemaRegistrySchema(schemaObject, schema))); }); } @@ -439,8 +439,8 @@ public Mono getSchemaProperties(String groupName, String name, public Mono> getSchemaPropertiesWithResponse(String groupName, String name, String schemaDefinition, SchemaFormat format) { - return FluxUtil.withContext(context -> - getSchemaPropertiesWithResponse(groupName, name, schemaDefinition, format, context)); + return FluxUtil.withContext( + context -> getSchemaPropertiesWithResponse(groupName, name, schemaDefinition, format, context)); } /** @@ -485,8 +485,8 @@ Mono> getSchemaPropertiesWithResponse(String groupNam context) .onErrorMap(ErrorException.class, SchemaRegistryAsyncClient::remapError) .map(response -> { - final SchemaProperties properties = SchemaRegistryHelper.getSchemaProperties( - response.getDeserializedHeaders(), response.getHeaders(), format); + final SchemaProperties properties = SchemaRegistryHelper + .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); return new SimpleResponse<>(response, properties); }); diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java index 18ff41bb49063..4546b398293b2 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java @@ -249,8 +249,8 @@ public Response registerSchemaWithResponse(String groupName, S final com.azure.data.schemaregistry.implementation.models.SchemaFormat contentType = SchemaRegistryHelper.getContentType(format); - ResponseBase response = restService.getSchemas().registerWithResponse(groupName, - name, contentType.toString(), binaryData, binaryData.getLength(), context); + ResponseBase response = restService.getSchemas() + .registerWithResponse(groupName, name, contentType.toString(), binaryData, binaryData.getLength(), context); final SchemaProperties registered = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); @@ -314,13 +314,13 @@ public Response getSchemaWithResponse(String schemaId, Con } try { - ResponseBase response = this.restService.getSchemas() - .getByIdWithResponse(schemaId, context); - SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), - response.getHeaders()); + ResponseBase response + = this.restService.getSchemas().getByIdWithResponse(schemaId, context); + SchemaProperties schemaObject + = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); - return new SimpleResponse<>(response, new SchemaRegistrySchema(schemaObject, - convertToString(response.getValue().toStream()))); + return new SimpleResponse<>(response, + new SchemaRegistrySchema(schemaObject, convertToString(response.getValue().toStream()))); } catch (ErrorException ex) { throw logger.logExceptionAsError(SchemaRegistryAsyncClient.remapError(ex)); } @@ -343,22 +343,22 @@ public Response getSchemaWithResponse(String schemaId, Con * @throws UncheckedIOException if an error occurred while deserializing response. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response getSchemaWithResponse(String groupName, String schemaName, - int schemaVersion, Context context) { + public Response getSchemaWithResponse(String groupName, String schemaName, int schemaVersion, + Context context) { if (Objects.isNull(groupName)) { throw logger.logExceptionAsError(new NullPointerException("'groupName' should not be null.")); } - ResponseBase response = this.restService.getSchemas() - .getSchemaVersionWithResponse(groupName, schemaName, schemaVersion, context); + ResponseBase response + = this.restService.getSchemas().getSchemaVersionWithResponse(groupName, schemaName, schemaVersion, context); InputStream schemaInputStream = response.getValue().toStream(); - SchemaProperties schemaObject = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), - response.getHeaders()); + SchemaProperties schemaObject + = SchemaRegistryHelper.getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders()); if (schemaInputStream == null) { - throw logger.logExceptionAsError(new IllegalArgumentException(String.format( - "Schema definition should not be null. Group Name: %s. Schema Name: %s. Version: %d", - groupName, schemaName, schemaVersion))); + throw logger.logExceptionAsError(new IllegalArgumentException( + String.format("Schema definition should not be null. Group Name: %s. Schema Name: %s. Version: %d", + groupName, schemaName, schemaVersion))); } return new SimpleResponse<>(response, @@ -426,11 +426,11 @@ public Response getSchemaPropertiesWithResponse(String groupNa = SchemaRegistryHelper.getContentType(format); try { - ResponseBase response = restService.getSchemas() + ResponseBase response = restService.getSchemas() .queryIdByContentWithResponse(groupName, name, contentType, binaryData, binaryData.getLength(), context); - final SchemaProperties properties = SchemaRegistryHelper.getSchemaProperties( - response.getDeserializedHeaders(), response.getHeaders(), format); + final SchemaProperties properties = SchemaRegistryHelper + .getSchemaProperties(response.getDeserializedHeaders(), response.getHeaders(), format); return new SimpleResponse<>(response, properties); } catch (ErrorException ex) { throw logger.logExceptionAsError(SchemaRegistryAsyncClient.remapError(ex)); diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java index e449c4ec96922..71ee5fc149228 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java @@ -108,11 +108,9 @@ * * */ -@ServiceClientBuilder(serviceClients = {SchemaRegistryAsyncClient.class, SchemaRegistryClient.class}) -public class SchemaRegistryClientBuilder implements - ConfigurationTrait, - HttpTrait, - TokenCredentialTrait { +@ServiceClientBuilder(serviceClients = { SchemaRegistryAsyncClient.class, SchemaRegistryClient.class }) +public class SchemaRegistryClientBuilder implements ConfigurationTrait, + HttpTrait, TokenCredentialTrait { private final ClientLogger logger = new ClientLogger(SchemaRegistryClientBuilder.class); private static final String DEFAULT_SCOPE = "https://eventhubs.azure.net/.default"; @@ -392,13 +390,12 @@ private AzureSchemaRegistryImpl getAzureSchemaRegistryImplService() { "'fullyQualifiedNamespace' cannot be null and must be set via builder.fullyQualifiedNamespace(String)"); if (CoreUtils.isNullOrEmpty(fullyQualifiedNamespace)) { - throw logger.logExceptionAsError(new IllegalArgumentException( - "'fullyQualifiedNamespace' cannot be an empty string.")); + throw logger.logExceptionAsError( + new IllegalArgumentException("'fullyQualifiedNamespace' cannot be an empty string.")); } - Configuration buildConfiguration = (configuration == null) - ? Configuration.getGlobalConfiguration() - : configuration; + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; HttpPipeline buildPipeline = this.httpPipeline; // Create a default Pipeline if it is not given @@ -435,8 +432,7 @@ private AzureSchemaRegistryImpl getAzureSchemaRegistryImplService() { policies.add(new HttpLoggingPolicy(httpLogOptions)); - buildPipeline = new HttpPipelineBuilder() - .policies(policies.toArray(new HttpPipelinePolicy[0])) + buildPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) .clientOptions(clientOptions) .build(); diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryHelper.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryHelper.java index c26c76eac38c4..7917f23d159d8 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryHelper.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/implementation/SchemaRegistryHelper.java @@ -20,16 +20,16 @@ * Helper to access private-package methods of models. */ public final class SchemaRegistryHelper { - private static final HashMap - SCHEMA_FORMAT_HASH_MAP = new HashMap<>(); + private static final HashMap SCHEMA_FORMAT_HASH_MAP + = new HashMap<>(); private static final Pattern SCHEMA_FORMAT_PATTERN = Pattern.compile("\\s"); private static SchemaRegistryModelsAccessor accessor; static { com.azure.data.schemaregistry.implementation.models.SchemaFormat.values().forEach(value -> { - final String mimeTypeLower = SCHEMA_FORMAT_PATTERN.matcher(value.toString()).replaceAll("") - .toLowerCase(Locale.ROOT); + final String mimeTypeLower + = SCHEMA_FORMAT_PATTERN.matcher(value.toString()).replaceAll("").toLowerCase(Locale.ROOT); SCHEMA_FORMAT_HASH_MAP.put(mimeTypeLower, value); }); @@ -88,8 +88,8 @@ public static SchemaProperties getSchemaProperties(SchemasGetSchemaVersionHeader deserializedHeaders.getSchemaVersion()); } - public static com.azure.data.schemaregistry.implementation.models.SchemaFormat getContentType( - SchemaFormat schemaFormat) { + public static com.azure.data.schemaregistry.implementation.models.SchemaFormat + getContentType(SchemaFormat schemaFormat) { Objects.requireNonNull(schemaFormat, "'schemaFormat' cannot be null.'"); if (schemaFormat == SchemaFormat.AVRO) { @@ -114,12 +114,11 @@ public static SchemaFormat getSchemaFormat(HttpHeaders headers) { return null; } - final String replaced = SCHEMA_FORMAT_PATTERN.matcher(contentType).replaceAll("") - .toLowerCase(Locale.ROOT); + final String replaced = SCHEMA_FORMAT_PATTERN.matcher(contentType).replaceAll("").toLowerCase(Locale.ROOT); // Default value if nothing matches is CUSTOM. - final com.azure.data.schemaregistry.implementation.models.SchemaFormat implementationFormat = - SCHEMA_FORMAT_HASH_MAP.getOrDefault(replaced, + final com.azure.data.schemaregistry.implementation.models.SchemaFormat implementationFormat + = SCHEMA_FORMAT_HASH_MAP.getOrDefault(replaced, com.azure.data.schemaregistry.implementation.models.SchemaFormat.TEXT_PLAIN_CHARSET_UTF8); if (com.azure.data.schemaregistry.implementation.models.SchemaFormat.APPLICATION_JSON_SERIALIZATION_AVRO @@ -133,4 +132,3 @@ public static SchemaFormat getSchemaFormat(HttpHeaders headers) { } } } - diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/Constants.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/Constants.java index c2eb45ccfef61..aea50c6c75930 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/Constants.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/Constants.java @@ -14,11 +14,14 @@ class Constants { static final String PLAYBACK_ENDPOINT = "https://foo.servicebus.windows.net"; - static final String SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE = "SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE"; + static final String SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE + = "SCHEMA_REGISTRY_AVRO_FULLY_QUALIFIED_NAMESPACE"; - static final String SCHEMA_REGISTRY_CUSTOM_FULLY_QUALIFIED_NAMESPACE = "SCHEMA_REGISTRY_CUSTOM_FULLY_QUALIFIED_NAMESPACE"; + static final String SCHEMA_REGISTRY_CUSTOM_FULLY_QUALIFIED_NAMESPACE + = "SCHEMA_REGISTRY_CUSTOM_FULLY_QUALIFIED_NAMESPACE"; - static final String SCHEMA_REGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE = "SCHEMA_REGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE"; + static final String SCHEMA_REGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE + = "SCHEMA_REGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE"; static final String SCHEMA_REGISTRY_GROUP = "SCHEMA_REGISTRY_GROUP"; } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientCustomTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientCustomTests.java index 4254b4078b9a1..c6ed5a849061b 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientCustomTests.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientCustomTests.java @@ -34,8 +34,8 @@ protected void beforeTest() { String endpoint; String schemaGroup; if (interceptorManager.isPlaybackMode()) { - tokenCredential = tokenRequestContext -> - Mono.fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); + tokenCredential = tokenRequestContext -> Mono + .fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); schemaGroup = PLAYBACK_TEST_GROUP; endpoint = PLAYBACK_ENDPOINT; } else { @@ -47,9 +47,7 @@ protected void beforeTest() { assertNotNull(schemaGroup, "'schemaGroup' cannot be null in LIVE/RECORD mode."); } - builder = new SchemaRegistryClientBuilder() - .credential(tokenCredential) - .fullyQualifiedNamespace(endpoint); + builder = new SchemaRegistryClientBuilder().credential(tokenCredential).fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); @@ -61,8 +59,7 @@ protected void beforeTest() { } private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { - return new AssertingHttpClientBuilder(httpClient) - .assertAsync() + return new AssertingHttpClientBuilder(httpClient).assertAsync() .skipRequest((httpRequest, context) -> false) .build(); } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientJsonTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientJsonTests.java index b3f4d5e0e8ea0..e616aa8653d78 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientJsonTests.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientJsonTests.java @@ -42,8 +42,8 @@ protected void beforeTest() { String endpoint; String schemaGroup; if (interceptorManager.isPlaybackMode()) { - tokenCredential = tokenRequestContext -> - Mono.fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); + tokenCredential = tokenRequestContext -> Mono + .fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); schemaGroup = PLAYBACK_TEST_GROUP; endpoint = PLAYBACK_ENDPOINT; } else { @@ -55,9 +55,7 @@ protected void beforeTest() { assertNotNull(schemaGroup, "'schemaGroup' cannot be null in LIVE/RECORD mode."); } - builder = new SchemaRegistryClientBuilder() - .credential(tokenCredential) - .fullyQualifiedNamespace(endpoint); + builder = new SchemaRegistryClientBuilder().credential(tokenCredential).fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); @@ -69,8 +67,7 @@ protected void beforeTest() { } private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { - return new AssertingHttpClientBuilder(httpClient) - .assertAsync() + return new AssertingHttpClientBuilder(httpClient).assertAsync() .skipRequest((httpRequest, context) -> false) .build(); } @@ -125,7 +122,6 @@ public void registerAndGetSchemaId() { testBase.registerAndGetSchemaId(client1, client2, schemaName, SCHEMA_CONTENT); } - /** * Verifies that an error is returned if we try to register an invalid schema. */ diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientPlaybackTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientPlaybackTests.java index 2014ad041c4bf..c28551a389359 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientPlaybackTests.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientPlaybackTests.java @@ -47,8 +47,8 @@ public void setupTest(TestInfo testInfo) { "Expected testInfo.getTestMethod() not be empty since we need a method for TestContextManager."); } - this.tokenCredential = tokenRequestContext -> - Mono.fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); + this.tokenCredential = tokenRequestContext -> Mono + .fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); this.endpoint = PLAYBACK_ENDPOINT; final String resourceName = "/compat/" + testInfo.getTestMethod().get().getName() + ".json"; @@ -71,8 +71,7 @@ public void getSchemaByIdFromPortal() { // Arrange final HttpClient httpClientMock = setupHttpClient(recordedData); - final SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace(endpoint) + final SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder().fullyQualifiedNamespace(endpoint) .credential(tokenCredential) .httpClient(httpClientMock) .serviceVersion(SchemaRegistryVersion.V2021_10) @@ -80,13 +79,11 @@ public void getSchemaByIdFromPortal() { final String schemaId = "f45b841fcb88401e961ca45477906be9"; // Act & Assert - StepVerifier.create(client.getSchema(schemaId)) - .assertNext(schema -> { - assertNotNull(schema.getProperties()); - assertEquals(schemaId, schema.getProperties().getId()); - assertEquals(SchemaFormat.AVRO, schema.getProperties().getFormat()); - }) - .verifyComplete(); + StepVerifier.create(client.getSchema(schemaId)).assertNext(schema -> { + assertNotNull(schema.getProperties()); + assertEquals(schemaId, schema.getProperties().getId()); + assertEquals(SchemaFormat.AVRO, schema.getProperties().getFormat()); + }).verifyComplete(); } /** @@ -98,8 +95,7 @@ public void getSchemaBackCompatibility() { // Arrange final HttpClient httpClientMock = setupHttpClient(recordedData); - final SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder() - .fullyQualifiedNamespace(endpoint) + final SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder().fullyQualifiedNamespace(endpoint) .credential(tokenCredential) .httpClient(httpClientMock) .serviceVersion(SchemaRegistryVersion.V2021_10) @@ -107,16 +103,13 @@ public void getSchemaBackCompatibility() { final String schemaId = "e5691f79e3964309ac712ec52abcccca"; // Act & Assert - StepVerifier.create(client.getSchema(schemaId)) - .assertNext(schema -> { - assertNotNull(schema.getProperties()); - assertEquals(schemaId, schema.getProperties().getId()); - assertEquals(SchemaFormat.AVRO, schema.getProperties().getFormat()); - }) - .verifyComplete(); + StepVerifier.create(client.getSchema(schemaId)).assertNext(schema -> { + assertNotNull(schema.getProperties()); + assertEquals(schemaId, schema.getProperties().getId()); + assertEquals(SchemaFormat.AVRO, schema.getProperties().getFormat()); + }).verifyComplete(); } - private static HttpClient setupHttpClient(RecordedData recordedData) { final NetworkCallRecord networkRecord = recordedData.findFirstAndRemoveNetworkCall(e -> true); return request -> { diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTests.java index 084553d314b3f..a6eb161ce9a42 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTests.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTests.java @@ -47,8 +47,8 @@ protected void beforeTest() { TokenCredential tokenCredential; String endpoint; if (interceptorManager.isPlaybackMode()) { - tokenCredential = tokenRequestContext -> - Mono.fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); + tokenCredential = tokenRequestContext -> Mono + .fromCallable(() -> new AccessToken("foo", OffsetDateTime.now().plusMinutes(20))); schemaGroup = PLAYBACK_TEST_GROUP; endpoint = PLAYBACK_ENDPOINT; } else { @@ -60,9 +60,7 @@ protected void beforeTest() { assertNotNull(schemaGroup, "'schemaGroup' cannot be null in LIVE/RECORD mode."); } - builder = new SchemaRegistryClientBuilder() - .credential(tokenCredential) - .fullyQualifiedNamespace(endpoint); + builder = new SchemaRegistryClientBuilder().credential(tokenCredential).fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { builder.httpClient(buildAsyncAssertingClient(interceptorManager.getPlaybackClient())); @@ -79,8 +77,7 @@ protected void beforeTest() { } private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { - return new AssertingHttpClientBuilder(httpClient) - .assertAsync() + return new AssertingHttpClientBuilder(httpClient).assertAsync() .skipRequest((httpRequest, context) -> false) .build(); } @@ -143,8 +140,8 @@ public void registerSchemaInvalidFormat() { final SchemaFormat unknownSchemaFormat = SchemaFormat.fromString("protobuf"); // Act & Assert - StepVerifier.create(client.registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, - unknownSchemaFormat)) + StepVerifier + .create(client.registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat)) .expectErrorSatisfies(error -> { assertTrue(error instanceof HttpResponseException); @@ -166,8 +163,9 @@ public void registerAndGetSchemaPropertiesWithInvalidFormat() { final SchemaRegistryAsyncClient client2 = builder.buildAsyncClient(); final SchemaFormat invalidFormat = SchemaFormat.fromString("protobuf"); - final SchemaProperties schemaProperties = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, - SchemaFormat.AVRO).block(Duration.ofSeconds(10)); + final SchemaProperties schemaProperties + = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, SchemaFormat.AVRO) + .block(Duration.ofSeconds(10)); assertNotNull(schemaProperties); @@ -178,7 +176,8 @@ public void registerAndGetSchemaPropertiesWithInvalidFormat() { final HttpResponseException responseException = ((HttpResponseException) error); assertEquals(404, responseException.getResponse().getStatusCode()); - }).verify(); + }) + .verify(); } /** @@ -207,12 +206,10 @@ public void getSchemaDoesNotExist() { final SchemaRegistryAsyncClient client1 = builder.buildAsyncClient(); // Act & Assert - StepVerifier.create(client1.getSchema(schemaId)) - .expectErrorSatisfies(error -> { - assertTrue(error instanceof ResourceNotFoundException); - assertEquals(404, ((ResourceNotFoundException) error).getResponse().getStatusCode()); - }) - .verify(); + StepVerifier.create(client1.getSchema(schemaId)).expectErrorSatisfies(error -> { + assertTrue(error instanceof ResourceNotFoundException); + assertEquals(404, ((ResourceNotFoundException) error).getResponse().getStatusCode()); + }).verify(); } /** @@ -239,8 +236,9 @@ public void getSchemaByGroupNameVersion() { final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); // Register a schema first. - final SchemaProperties registeredSchema = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, - SchemaFormat.AVRO).block(Duration.ofSeconds(10)); + final SchemaProperties registeredSchema + = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, SchemaFormat.AVRO) + .block(Duration.ofSeconds(10)); assertNotNull(registeredSchema); diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTestsBase.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTestsBase.java index 8b9ea2a0a342b..f87a4eef21e06 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTestsBase.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClientTestsBase.java @@ -36,20 +36,20 @@ class SchemaRegistryAsyncClientTestsBase { * 2. Gets the schema * 3. Verifies that the contents are the same. */ - void registerAndGetSchema(SchemaRegistryAsyncClient client1, SchemaRegistryAsyncClient client2, - String schemaName, String schemaContent) { + void registerAndGetSchema(SchemaRegistryAsyncClient client1, SchemaRegistryAsyncClient client2, String schemaName, + String schemaContent) { // Arrange final String schemaContentNoWhitespace = WHITESPACE_PATTERN.matcher(schemaContent).replaceAll(""); final AtomicReference schemaId = new AtomicReference<>(); - // Act & Assert StepVerifier.create(client1.registerSchema(schemaGroup, schemaName, schemaContent, schemaFormat)) .assertNext(response -> { assertNotNull(response.getId()); schemaId.set(response.getId()); - }).verifyComplete(); + }) + .verifyComplete(); // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is // cached, so it won't make a network call when getting the schema. client2 will not have this information. @@ -57,17 +57,15 @@ void registerAndGetSchema(SchemaRegistryAsyncClient client1, SchemaRegistryAsync assertNotNull(schemaIdToGet); // Act & Assert - StepVerifier.create(client2.getSchema(schemaIdToGet)) - .assertNext(schema -> { - assertNotNull(schema.getProperties()); - assertEquals(schemaIdToGet, schema.getProperties().getId()); - assertEquals(schemaFormat, schema.getProperties().getFormat()); - - // Replace white space. - final String actualContents = WHITESPACE_PATTERN.matcher(schema.getDefinition()).replaceAll(""); - assertEquals(schemaContentNoWhitespace, actualContents); - }) - .verifyComplete(); + StepVerifier.create(client2.getSchema(schemaIdToGet)).assertNext(schema -> { + assertNotNull(schema.getProperties()); + assertEquals(schemaIdToGet, schema.getProperties().getId()); + assertEquals(schemaFormat, schema.getProperties().getFormat()); + + // Replace white space. + final String actualContents = WHITESPACE_PATTERN.matcher(schema.getDefinition()).replaceAll(""); + assertEquals(schemaContentNoWhitespace, actualContents); + }).verifyComplete(); } /** @@ -86,14 +84,16 @@ void registerAndGetSchemaTwice(SchemaRegistryAsyncClient client1, SchemaRegistry assertEquals(schemaFormat, response.getFormat()); assertNotNull(response.getId()); schemaId.set(response.getId()); - }).verifyComplete(); + }) + .verifyComplete(); StepVerifier.create(client1.registerSchema(schemaGroup, schemaName, schemaContentModified, schemaFormat)) .assertNext(response -> { assertEquals(schemaFormat, response.getFormat()); assertNotNull(response.getId()); schemaId2.set(response.getId()); - }).verifyComplete(); + }) + .verifyComplete(); // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is // cached, so it won't make a network call when getting the schema. client2 will not have this information. @@ -109,8 +109,8 @@ void registerAndGetSchemaTwice(SchemaRegistryAsyncClient client1, SchemaRegistry /** * Verifies that we can register a schema and then get it by its schema group, name, and content. */ - void registerAndGetSchemaId(SchemaRegistryAsyncClient client1, SchemaRegistryAsyncClient client2, - String schemaName, String schemaContent) { + void registerAndGetSchemaId(SchemaRegistryAsyncClient client1, SchemaRegistryAsyncClient client2, String schemaName, + String schemaContent) { final AtomicReference schemaId = new AtomicReference<>(); // Act & Assert @@ -119,7 +119,8 @@ void registerAndGetSchemaId(SchemaRegistryAsyncClient client1, SchemaRegistryAsy assertSchemaProperties(response, null, schemaFormat, schemaGroup, schemaName); assertEquals(1, response.getVersion()); schemaId.set(response.getId()); - }).verifyComplete(); + }) + .verifyComplete(); // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is // cached, so it won't make a network call when getting the schema. client2 will not have this information. @@ -148,7 +149,8 @@ void registerBadRequest(SchemaRegistryAsyncClient client1, String schemaName, St final HttpResponseException exception = (HttpResponseException) error; assertEquals(400, exception.getResponse().getStatusCode()); - }).verify(); + }) + .verify(); } /** diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilderTest.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilderTest.java index b081550cdfe8b..45a93681ae7e7 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilderTest.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilderTest.java @@ -23,21 +23,17 @@ public class SchemaRegistryClientBuilderTest { @Test public void testNullCredentials() { - assertThrows(NullPointerException.class, - () -> new SchemaRegistryClientBuilder().buildAsyncClient()); + assertThrows(NullPointerException.class, () -> new SchemaRegistryClientBuilder().buildAsyncClient()); } @Test public void testNullEndpoint() { - ClientSecretCredential credential = new ClientSecretCredentialBuilder() - .tenantId("tenant-id") + ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId("tenant-id") .clientId("client-id") .clientSecret("client-secret") .build(); assertThrows(NullPointerException.class, - () -> new SchemaRegistryClientBuilder() - .credential(credential) - .buildAsyncClient()); + () -> new SchemaRegistryClientBuilder().credential(credential).buildAsyncClient()); } @Test @@ -47,8 +43,7 @@ public void testInvalidEndpoint() { // Act & Assert assertThrows(IllegalArgumentException.class, - () -> new SchemaRegistryClientBuilder() - .credential(credential) + () -> new SchemaRegistryClientBuilder().credential(credential) .fullyQualifiedNamespace("") .buildAsyncClient()); } @@ -56,14 +51,12 @@ public void testInvalidEndpoint() { @Test public void testSchemaRegistryClientCreation() { - ClientSecretCredential credential = new ClientSecretCredentialBuilder() - .tenantId("tenant-id") + ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId("tenant-id") .clientId("client-id") .clientSecret("client-secret") .build(); - Assertions.assertNotNull(new SchemaRegistryClientBuilder() - .credential(credential) + Assertions.assertNotNull(new SchemaRegistryClientBuilder().credential(credential) .fullyQualifiedNamespace("https://localhost") .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .buildAsyncClient()); @@ -71,17 +64,16 @@ public void testSchemaRegistryClientCreation() { @Test public void bothRetryOptionsAndRetryPolicySet() { - ClientSecretCredential credential = new ClientSecretCredentialBuilder() - .tenantId("tenant-id") + ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId("tenant-id") .clientId("client-id") .clientSecret("client-secret") .build(); - assertThrows(IllegalStateException.class, () -> new SchemaRegistryClientBuilder() - .credential(credential) - .fullyQualifiedNamespace("https://localhost") - .retryOptions(new RetryOptions(new ExponentialBackoffOptions())) - .retryPolicy(new RetryPolicy()) - .buildAsyncClient()); + assertThrows(IllegalStateException.class, + () -> new SchemaRegistryClientBuilder().credential(credential) + .fullyQualifiedNamespace("https://localhost") + .retryOptions(new RetryOptions(new ExponentialBackoffOptions())) + .retryPolicy(new RetryPolicy()) + .buildAsyncClient()); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientTests.java b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientTests.java index d481e81972def..59a94297d591a 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientTests.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/test/java/com/azure/data/schemaregistry/SchemaRegistryClientTests.java @@ -67,9 +67,7 @@ public AccessToken getTokenSync(TokenRequestContext request) { assertNotNull(schemaGroup, "'schemaGroup' cannot be null in LIVE/RECORD mode."); } - builder = new SchemaRegistryClientBuilder() - .credential(tokenCredential) - .fullyQualifiedNamespace(endpoint); + builder = new SchemaRegistryClientBuilder().credential(tokenCredential).fullyQualifiedNamespace(endpoint); if (interceptorManager.isPlaybackMode()) { builder.httpClient(buildSyncAssertingClient(interceptorManager.getPlaybackClient())); @@ -79,8 +77,7 @@ public AccessToken getTokenSync(TokenRequestContext request) { } private HttpClient buildSyncAssertingClient(HttpClient httpClient) { - return new AssertingHttpClientBuilder(httpClient) - .assertSync() + return new AssertingHttpClientBuilder(httpClient).assertSync() .skipRequest((httpRequest, context) -> false) .build(); } @@ -134,8 +131,8 @@ public void registerAndGetSchemaTwice() { // Expected that the second time we call this method, it will return a different schema because the contents // are different. - final SchemaProperties response2 = client1.registerSchema(schemaGroup, schemaName, schemaContentModified, - schemaFormat); + final SchemaProperties response2 + = client1.registerSchema(schemaGroup, schemaName, schemaContentModified, schemaFormat); assertSchemaProperties(response2, null, schemaFormat, schemaGroup, schemaName); // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is @@ -159,8 +156,7 @@ public void registerAndGetSchemaId() { final SchemaFormat schemaFormat = SchemaFormat.AVRO; // Act & Assert - final SchemaProperties response = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, - schemaFormat); + final SchemaProperties response = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, schemaFormat); assertSchemaProperties(response, null, schemaFormat, schemaGroup, schemaName); // Assert that we can get a schema based on its id. We registered a schema with client1 and its response is @@ -169,8 +165,8 @@ public void registerAndGetSchemaId() { assertNotNull(schemaIdToGet); // Act & Assert - final SchemaProperties schemaProperties = client2.getSchemaProperties(schemaGroup, schemaName, SCHEMA_CONTENT, - schemaFormat); + final SchemaProperties schemaProperties + = client2.getSchemaProperties(schemaGroup, schemaName, SCHEMA_CONTENT, schemaFormat); assertEquals(schemaIdToGet, schemaProperties.getId()); assertEquals(schemaFormat, schemaProperties.getFormat()); @@ -209,9 +205,8 @@ public void registerSchemaInvalidFormat() { final SchemaFormat unknownSchemaFormat = SchemaFormat.fromString("protobuf"); // Act & Assert - HttpResponseException e = assertThrows(HttpResponseException.class, - () -> client.registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat, - Context.NONE)); + HttpResponseException e = assertThrows(HttpResponseException.class, () -> client + .registerSchemaWithResponse(schemaGroup, schemaName, SCHEMA_CONTENT, unknownSchemaFormat, Context.NONE)); assertEquals(415, e.getResponse().getStatusCode()); } @@ -225,8 +220,8 @@ public void getSchemaDoesNotExist() { final SchemaRegistryClient client1 = builder.buildClient(); // Act & Assert - final ResourceNotFoundException error = assertThrows(ResourceNotFoundException.class, - () -> client1.getSchema(schemaId)); + final ResourceNotFoundException error + = assertThrows(ResourceNotFoundException.class, () -> client1.getSchema(schemaId)); assertEquals(404, error.getResponse().getStatusCode()); } @@ -253,8 +248,8 @@ public void getSchemaByGroupNameVersion() { final String schemaName = testResourceNamer.randomName("sch", RESOURCE_LENGTH); // Register a schema first. - final SchemaProperties registeredSchema = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, - SchemaFormat.AVRO); + final SchemaProperties registeredSchema + = client1.registerSchema(schemaGroup, schemaName, SCHEMA_CONTENT, SchemaFormat.AVRO); assertNotNull(registeredSchema);