From f2fcab9d889ab3a8104103658dbca2fd5fb8ed68 Mon Sep 17 00:00:00 2001 From: Xiaobing Zhu <71206407+ZhuXiaoBing-cn@users.noreply.github.com> Date: Fri, 18 Dec 2020 20:31:06 +0800 Subject: [PATCH] Modify README.md files and unit tests (#2) --- .../resources/spotbugs/spotbugs-exclude.xml | 2 + .../SpringEnvironmentTokenBuilder.java | 35 +++--- .../azure/spring/identity/package-info.java | 7 ++ .../SpringEnvironmentTokenBuilderTest.java | 108 +++++++++--------- .../azure-spring-cloud-sample-cache/README.md | 2 +- .../README.md | 12 +- .../README.md | 5 +- .../README.md | 8 +- .../README.md | 6 +- .../README.md | 10 +- .../README.md | 12 +- .../README.md | 6 +- .../README.md | 12 +- .../README.md | 6 +- .../README.md | 6 +- .../README.md | 6 +- .../README.md | 4 +- .../AzureContextAutoConfiguration.java | 1 - .../context/core/config/AzureProperties.java | 2 +- .../context/core/enums/package-info.java | 7 ++ .../context/core/impl/EventHubManager.java | 3 +- .../context/core/impl/RedisCacheManager.java | 1 - .../AzureContextAutoConfigurationTest.java | 52 +++++---- .../AzureEnvironmentConfigurationTest.java | 27 +++-- 24 files changed, 184 insertions(+), 156 deletions(-) rename sdk/spring/azure-identity-spring/src/main/java/com/azure/{identity/spring => spring/identity}/SpringEnvironmentTokenBuilder.java (91%) create mode 100644 sdk/spring/azure-identity-spring/src/main/java/com/azure/spring/identity/package-info.java rename sdk/spring/azure-identity-spring/src/test/java/com/azure/{identity/spring => spring/identity}/SpringEnvironmentTokenBuilderTest.java (53%) create mode 100644 sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/enums/package-info.java diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index cbaed2b26019..76ec052b0058 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -2285,6 +2285,7 @@ + + diff --git a/sdk/spring/azure-identity-spring/src/main/java/com/azure/identity/spring/SpringEnvironmentTokenBuilder.java b/sdk/spring/azure-identity-spring/src/main/java/com/azure/spring/identity/SpringEnvironmentTokenBuilder.java similarity index 91% rename from sdk/spring/azure-identity-spring/src/main/java/com/azure/identity/spring/SpringEnvironmentTokenBuilder.java rename to sdk/spring/azure-identity-spring/src/main/java/com/azure/spring/identity/SpringEnvironmentTokenBuilder.java index ee763819c4e8..2d5c147ce263 100644 --- a/sdk/spring/azure-identity-spring/src/main/java/com/azure/identity/spring/SpringEnvironmentTokenBuilder.java +++ b/sdk/spring/azure-identity-spring/src/main/java/com/azure/spring/identity/SpringEnvironmentTokenBuilder.java @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.identity.spring; +package com.azure.spring.identity; import java.util.HashMap; @@ -14,12 +14,11 @@ /** * A helper class to deal with credentials in a Spring environment. - * + * *

- * This helper class makes it possible to configure credentials to be used - * within a Spring context. + * This helper class makes it possible to configure credentials to be used within a Spring context. *

- * + * * * * @@ -43,7 +42,7 @@ * the path to the PEM client certificate * *
Property Tuples
- * + *

* where name is the name of the credential. Note if * name is entirely omitted it is taken to be the default * credential. Note if the default credential is omitted it is configure to use @@ -65,8 +64,7 @@ public class SpringEnvironmentTokenBuilder { private final HashMap credentials; /** - * Stores the name of the credential to be returned. If omitted, the default - * credential will be returned. + * Stores the name of the credential to be returned. If omitted, the default credential will be returned. */ private String name = ""; @@ -82,7 +80,6 @@ public SpringEnvironmentTokenBuilder() { * Populate from Environment. * * @param environment the environment. - * * @return this builder. */ public SpringEnvironmentTokenBuilder fromEnvironment(Environment environment) { @@ -98,9 +95,9 @@ public SpringEnvironmentTokenBuilder fromEnvironment(Environment environment) { } /** - * Sets a credential to override a named credential. If this credential fails to produce a token, - * the original token credential will be used. - * + * Sets a credential to override a named credential. If this credential fails to produce a token, the original token + * credential will be used. + * * @param name the name for the credential. * @param credential the token credential. * @return this builder. @@ -123,7 +120,7 @@ public SpringEnvironmentTokenBuilder overrideNamedCredential(String name, TokenC * Populate a named credential. * * @param environment the environment - * @param name the name. + * @param name the name. */ private void populateNamedCredential(Environment environment, String name) { String standardizedName = name; @@ -142,7 +139,7 @@ private void populateNamedCredential(Environment environment, String name) { if (tenantId != null && clientId != null && clientSecret != null) { TokenCredential credential = new ClientSecretCredentialBuilder().tenantId(tenantId).clientId(clientId) - .clientSecret(clientSecret).build(); + .clientSecret(clientSecret).build(); credentials.put(name, credential); return; } @@ -152,7 +149,7 @@ private void populateNamedCredential(Environment environment, String name) { if (tenantId != null && clientId != null && clientCertificatePath != null) { TokenCredential credential = new ClientCertificateCredentialBuilder().tenantId(tenantId).clientId(clientId) - .pemCertificate(clientCertificatePath).build(); + .pemCertificate(clientCertificatePath).build(); credentials.put(name, credential); return; } @@ -164,7 +161,7 @@ private void populateNamedCredential(Environment environment, String name) { /** * Sets the builder to return a credential named name - * + * * @param name the name of the credential. * @return this builder. */ @@ -175,6 +172,7 @@ public SpringEnvironmentTokenBuilder namedCredential(String name) { /** * Sets the builder to return the default credential. + * * @return the credential builder with default name. */ public SpringEnvironmentTokenBuilder defaultCredential() { @@ -185,14 +183,13 @@ public SpringEnvironmentTokenBuilder defaultCredential() { * Builds an Azure TokenCredential. * * @return the built token credential. - * @throws IllegalArgumentException if attempting to retrieve a named credential - * not defined in the environment. + * @throws IllegalArgumentException if attempting to retrieve a named credential not defined in the environment. */ public TokenCredential build() { TokenCredential result = credentials.get(name); if (result == null) { throw new IllegalArgumentException( - "Attempting to retrieve Azure credential not configured in the environment. (name=" + name + ")"); + "Attempting to retrieve Azure credential not configured in the environment. (name=" + name + ")"); } else { return result; } diff --git a/sdk/spring/azure-identity-spring/src/main/java/com/azure/spring/identity/package-info.java b/sdk/spring/azure-identity-spring/src/main/java/com/azure/spring/identity/package-info.java new file mode 100644 index 000000000000..391ffff04977 --- /dev/null +++ b/sdk/spring/azure-identity-spring/src/main/java/com/azure/spring/identity/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * Package com.azure.identity.spring; + */ +package com.azure.spring.identity; diff --git a/sdk/spring/azure-identity-spring/src/test/java/com/azure/identity/spring/SpringEnvironmentTokenBuilderTest.java b/sdk/spring/azure-identity-spring/src/test/java/com/azure/spring/identity/SpringEnvironmentTokenBuilderTest.java similarity index 53% rename from sdk/spring/azure-identity-spring/src/test/java/com/azure/identity/spring/SpringEnvironmentTokenBuilderTest.java rename to sdk/spring/azure-identity-spring/src/test/java/com/azure/spring/identity/SpringEnvironmentTokenBuilderTest.java index 2a5e3c764493..5a10e8bc44f3 100644 --- a/sdk/spring/azure-identity-spring/src/test/java/com/azure/identity/spring/SpringEnvironmentTokenBuilderTest.java +++ b/sdk/spring/azure-identity-spring/src/test/java/com/azure/spring/identity/SpringEnvironmentTokenBuilderTest.java @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.identity.spring; +package com.azure.spring.identity; import com.azure.identity.ClientSecretCredential; import org.junit.jupiter.api.Test; @@ -24,20 +24,20 @@ public class SpringEnvironmentTokenBuilderTest { /** - * Test getDefaultCredential method. - */ - @Test - public void testGetDefaultCredential() { - SpringEnvironmentTokenBuilder builder = new SpringEnvironmentTokenBuilder(); - assertNotNull(builder.build()); - assertEquals(builder.build(), builder.defaultCredential().build()); - } - - /** - * Test populate method. - */ - @Test - public void testPopulate() { + * Test getDefaultCredential method. + */ + @Test + public void testGetDefaultCredential() { + SpringEnvironmentTokenBuilder builder = new SpringEnvironmentTokenBuilder(); + assertNotNull(builder.build()); + assertEquals(builder.build(), builder.defaultCredential().build()); + } + + /** + * Test populate method. + */ + @Test + public void testPopulate() { Properties properties = new Properties(); properties.put("azure.credential.names", ""); properties.put("azure.credential.tenantId", "tenantId"); @@ -51,54 +51,54 @@ public void testPopulate() { assertTrue(builder.build() instanceof ClientSecretCredential); assertEquals(builder.build(), builder.defaultCredential().build()); - } + } - /** - * Test populate method. - */ - @Test - public void testPopulate2() { + /** + * Test populate method. + */ + @Test + public void testPopulate2() { Properties properties = new Properties(); - properties.put("azure.credential.names", "myname"); - properties.put("azure.credential.myname.tenantId", "tenantId"); - properties.put("azure.credential.myname.clientId", "clientId"); - properties.put("azure.credential.myname.clientSecret", "clientSecret"); - - SpringEnvironmentTokenBuilder builder = new SpringEnvironmentTokenBuilder(); - builder.fromEnvironment(buildEnvironment(properties)); - assertNotNull(builder.namedCredential("myname").build()); - assertTrue(builder.build() instanceof ClientSecretCredential); - assertNotEquals(builder.build(), builder.defaultCredential().build()); - - } - - /** - * Test populate method. - */ - @Test - public void testPopulate3() { + properties.put("azure.credential.names", "myname"); + properties.put("azure.credential.myname.tenantId", "tenantId"); + properties.put("azure.credential.myname.clientId", "clientId"); + properties.put("azure.credential.myname.clientSecret", "clientSecret"); + + SpringEnvironmentTokenBuilder builder = new SpringEnvironmentTokenBuilder(); + builder.fromEnvironment(buildEnvironment(properties)); + assertNotNull(builder.namedCredential("myname").build()); + assertTrue(builder.build() instanceof ClientSecretCredential); + assertNotEquals(builder.build(), builder.defaultCredential().build()); + + } + + /** + * Test populate method. + */ + @Test + public void testPopulate3() { Properties properties = new Properties(); properties.put("azure.credential.names", "myname2"); - properties.put("azure.credential.myname2.tenantId", "tenantId"); - properties.put("azure.credential.myname2.clientSecret", "clientSecret"); + properties.put("azure.credential.myname2.tenantId", "tenantId"); + properties.put("azure.credential.myname2.clientSecret", "clientSecret"); SpringEnvironmentTokenBuilder builder = new SpringEnvironmentTokenBuilder(); - try { - builder.fromEnvironment(buildEnvironment(properties)); - fail(); - } catch (Throwable t) { - assertEquals(IllegalStateException.class, t.getClass(), - "Unexpected exception class on missing configuration field."); - } - - } - - private StandardEnvironment buildEnvironment(Properties properties) { + try { + builder.fromEnvironment(buildEnvironment(properties)); + fail(); + } catch (Throwable t) { + assertEquals(IllegalStateException.class, t.getClass(), + "Unexpected exception class on missing configuration field."); + } + + } + + private StandardEnvironment buildEnvironment(Properties properties) { StandardEnvironment environment = new StandardEnvironment(); final MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(new PropertiesPropertySource("test", properties)); - + return environment; } - + } diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-cache/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-cache/README.md index dd366ef1401a..25a9c0d3c9dc 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-cache/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-cache/README.md @@ -80,7 +80,7 @@ We need to ensure that this [environment checklist][ready-to-run-checklist] is c [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-azure-cache-for-redis]: https://docs.microsoft.com/azure/azure-cache-for-redis/quickstart-create-redis [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder/README.md index 8c0140e32014..98d8047bea2a 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder/README.md @@ -31,7 +31,7 @@ Event Hub. You can choose anyone of them. 1. Create [Azure Storage][create-azure-storage] for checkpoint use. -1. Update [application.yaml](src/main/resources/application.yaml). +1. Update [application.yaml][application.yaml]. ```yaml spring: @@ -64,7 +64,7 @@ Event Hub. You can choose anyone of them. 1. Create [Azure Storage][create-azure-storage] for checkpoint use. -1. Update [application-sp.yaml](src/main/resources/application-sp.yaml). +1. Update [application-sp.yaml][application-sp.yaml]. ```yaml spring: cloud: @@ -111,7 +111,7 @@ Please follow [create managed identity][create-managed-identity] to set up manag ##### Update MSI related properties -1. Update [application-mi.yaml](src/main/resources/application-mi.yaml) +1. Update [application-mi.yaml][application-mi.yaml] ```yaml spring: cloud: @@ -193,7 +193,7 @@ spring: [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-event-hubs]: https://docs.microsoft.com/azure/event-hubs/ [create-azure-storage]: https://docs.microsoft.com/azure/storage/ [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md @@ -201,4 +201,6 @@ spring: [deploy-spring-boot-application-to-app-service]: https://docs.microsoft.com/java/azure/spring-framework/deploy-spring-boot-java-app-with-maven-plugin?toc=%2Fazure%2Fapp-service%2Fcontainers%2Ftoc.json&view=azure-java-stable [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [role-assignment]: https://docs.microsoft.com/azure/role-based-access-control/role-assignments-portal - +[application-mi.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder/src/main/resources/application-mi.yaml +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder/src/main/resources/application.yaml +[application-sp.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder/src/main/resources/application-sp.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-kafka/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-kafka/README.md index 48dfad7a0825..4e77e8467610 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-kafka/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-kafka/README.md @@ -30,7 +30,7 @@ completed before the run. ## Examples 1. Update - [application.yaml](src/main/resources/application.yaml) + [application.yaml][application.yaml] file ```yaml @@ -74,7 +74,8 @@ completed before the run. [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-event-hubs]: https://docs.microsoft.com/azure/event-hubs/ [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-kafka/src/main/resources/application.yaml \ No newline at end of file diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-multibinders/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-multibinders/README.md index f2e9b7fcd08b..aa7666d63474 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-multibinders/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-multibinders/README.md @@ -35,7 +35,7 @@ is completed before the run. ## Examples 1. Update stream binding related properties in - [application.yaml](src/main/resources/application.yaml). If you choose to use + [application.yaml][application.yaml]. If you choose to use service principal or managed identity, update the `application-sp.yaml` or `application-mi.yaml` respectively. @@ -119,7 +119,7 @@ processing. [2] New message received: 'hello' [2] Message 'hello' successfully checkpointed -6. Delete the resources on [Azure Portal](http://ms.portal.azure.com/) +6. Delete the resources on [Azure Portal][azure-portal] to avoid unexpected charges. ## Troubleshooting @@ -131,7 +131,7 @@ processing. [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-event-hubs]: https://docs.microsoft.com/azure/event-hubs/ [create-azure-storage]: https://docs.microsoft.com/azure/storage/ [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md @@ -141,4 +141,4 @@ processing. [managed-identities]: https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/ [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [role-assignment]: https://docs.microsoft.com/azure/role-based-access-control/role-assignments-portal - +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-multibinders/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-operation/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-operation/README.md index eb515a882789..19a325ace248 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-operation/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-operation/README.md @@ -24,7 +24,7 @@ completed before the run. ## Examples -1. Update [application.yaml](src/main/resources/application.yaml). +1. Update [application.yaml][application.yaml]. ```yaml spring: cloud: @@ -59,9 +59,9 @@ completed before the run. [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-event-hubs]: https://docs.microsoft.com/azure/event-hubs/ [create-azure-storage]: https://docs.microsoft.com/azure/storage/ [eventhub-operation]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-integration-eventhubs/src/main/java/com/azure/spring/integration/eventhub/api/EventHubOperation.java [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist - +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-operation/src/main/resources/application.yaml \ No newline at end of file diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-operation/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-operation/README.md index 47c87430cd2b..bbc1cbdbd187 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-operation/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-operation/README.md @@ -23,7 +23,7 @@ completed before the run. ## Examples -1. Update [application.yaml](src/main/resources/application.yaml). +1. Update [application.yaml][application.yaml]. ```yaml spring: cloud: @@ -67,11 +67,11 @@ completed before the run. [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal -[queue-controller]: src/main/java/com/azure/spring/sample/servicebus/operation/QueueController.java -[topic-controller]: src/main/java/com/azure/spring/sample/servicebus/operation/TopicController.java +[queue-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-operation/src/main/java/com/azure/spring/sample/servicebus/operation/QueueController.java +[topic-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-operation/src/main/java/com/azure/spring/sample/servicebus/operation/TopicController.java [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [servicebus-queue-operation]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-integration-servicebus/src/main/java/com/azure/spring/integration/servicebus/queue/ServiceBusQueueOperation.java [servicebus-topic-operation]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-integration-servicebus/src/main/java/com/azure/spring/integration/servicebus/topic/ServiceBusTopicOperation.java - +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-operation/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-binder/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-binder/README.md index 796eb3f1b6d5..f942fd9f02be 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-binder/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-binder/README.md @@ -27,7 +27,7 @@ Event Hub. You can choose anyone of them. 1. Create Azure Service Bus namespace and queue. Please see [how to create][create-service-bus]. -1. Update [application.yaml](src/main/resources/application.yaml). +1. Update [application.yaml][application.yaml]. ```yaml spring: cloud: @@ -50,7 +50,7 @@ Event Hub. You can choose anyone of them. 1. Create Azure Service Bus namespace and queue. Please see [how to create][create-service-bus]. -1. Update [application-sp.yaml](src/main/resources/application-sp.yaml). +1. Update [application-sp.yaml][application-sp.yaml]. ```yaml spring: cloud: @@ -87,7 +87,7 @@ Please follow [create managed identity][create-managed-identity] to set up manag ##### Update MSI related properties -1. Update [application-mi.yaml](src/main/resources/application-mi.yaml) +1. Update [application-mi.yaml][application-mi.yaml]. ```yaml spring: cloud: @@ -164,7 +164,7 @@ spring: [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal [create-azure-storage]: https://docs.microsoft.com/azure/storage/ [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md @@ -172,4 +172,6 @@ spring: [deploy-spring-boot-application-to-app-service]: https://docs.microsoft.com/java/azure/spring-framework/deploy-spring-boot-java-app-with-maven-plugin?toc=%2Fazure%2Fapp-service%2Fcontainers%2Ftoc.json&view=azure-java-stable [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [role-assignment]: https://docs.microsoft.com/azure/role-based-access-control/role-assignments-portal - +[application-mi.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-binder/src/main/resources/application-mi.yaml +[application-sp.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-binder/src/main/resources/application-sp.yaml +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-binder/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-multibinders/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-multibinders/README.md index 1001ef8983b9..96426eb29f9c 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-multibinders/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-multibinders/README.md @@ -33,7 +33,7 @@ is completed before the run. ## Examples 1. Update stream binding related properties in - [application.yaml](src/main/resources/application.yaml). If you choose to use + [application.yaml][application.yaml]. If you choose to use service principal or managed identity, update the `application-sp.yaml` or `application-mi.yaml` respectively. @@ -113,7 +113,7 @@ processing. [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md [create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md @@ -122,4 +122,4 @@ processing. [managed-identities]: https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/ [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [role-assignment]: https://docs.microsoft.com/azure/role-based-access-control/role-assignments-portal - +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-multibinders/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-topic-binder/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-topic-binder/README.md index f6452d0cde11..7286a743e009 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-topic-binder/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-topic-binder/README.md @@ -27,7 +27,7 @@ Event Hub. You can choose anyone of them. 1. Create Azure Service Bus namespace and topic. Please see [how to create][create-service-bus]. -1. Update [application.yaml](src/main/resources/application.yaml). +1. Update [application.yaml][application.yaml]. ```yaml spring: cloud: @@ -50,7 +50,7 @@ Event Hub. You can choose anyone of them. 1. Create Azure Service Bus namespace and queue. Please see [how to create][create-service-bus]. -1. Update [application-sp.yaml](src/main/resources/application-sp.yaml). +1. Update [application-sp.yaml][application-sp.yaml]. ```yaml spring: cloud: @@ -87,7 +87,7 @@ Please follow [create managed identity][create-managed-identity] to set up manag ##### Update MSI related properties -1. Update [application-mi.yaml](src/main/resources/application-mi.yaml) +1. Update [application-mi.yaml][application-mi.yaml] ```yaml spring: cloud: @@ -164,7 +164,7 @@ spring: [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal [create-azure-storage]: https://docs.microsoft.com/azure/storage/ [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md @@ -172,4 +172,6 @@ spring: [deploy-spring-boot-application-to-app-service]: https://docs.microsoft.com/java/azure/spring-framework/deploy-spring-boot-java-app-with-maven-plugin?toc=%2Fazure%2Fapp-service%2Fcontainers%2Ftoc.json&view=azure-java-stable [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [role-assignment]: https://docs.microsoft.com/azure/role-based-access-control/role-assignments-portal - +[application-mi.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-topic-binder/src/main/resources/application-mi.yaml +[application-sp.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-topic-binder/src/main/resources/application-sp.yaml +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-topic-binder/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-storage-queue-operation/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-storage-queue-operation/README.md index 948afdabe17b..095678b01b15 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-storage-queue-operation/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-storage-queue-operation/README.md @@ -27,7 +27,7 @@ completed before the run. ## Examples 1. Update stream binding related properties in - [application.yaml](src/main/resources/application.yaml). If you choose to use + [application.yaml][application.yaml]. If you choose to use service principal or managed identity, update the `application-sp.yaml` or `application-mi.yaml` respectively. @@ -70,11 +70,11 @@ completed before the run. [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-azure-storage]: https://docs.microsoft.com/azure/storage/ [create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [storage-queue-operation]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-integration-storage-queue/src/main/java/com/azure/spring/integration/storage/queue/StorageQueueOperation.java [web-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-storage-queue-operation/src/main/java/com/azure/spring/sample/storage/queue/operation/WebController.java#L26 - +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-storage-queue-operation/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/README.md index 530f96bc61c1..ff765b509e1d 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/README.md @@ -32,7 +32,7 @@ completed before the run. ## Examples -1. Update [application.yaml](src/main/resources/application.yaml). If you choose to use +1. Update [application.yaml][application.yaml]. If you choose to use service principal or managed identity, update the `application-sp.yaml` or `application-mi.yaml` respectively. ```yaml @@ -70,7 +70,7 @@ completed before the run. ## Contributing [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-event-hubs]: https://docs.microsoft.com/azure/event-hubs/ [create-azure-storage]: https://docs.microsoft.com/azure/storage/ [create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md @@ -79,6 +79,6 @@ completed before the run. [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [receive-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/src/main/java/com/azure/spring/sample/eventhubs/ReceiveController.java [send-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/src/main/java/com/azure/spring/sample/eventhubs/SendController.java - +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/README.md index 221aaeff613b..a6516d56f95d 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/README.md @@ -29,7 +29,7 @@ completed before the run. ## Examples -1. Update [application.yaml](src/main/resources/application.yaml). If you choose to use +1. Update [application.yaml][application.yaml]. If you choose to use service principal or managed identity, update the `application-sp.yaml` or `application-mi.yaml` respectively. ```yaml @@ -78,7 +78,7 @@ completed before the run. ## Contributing [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal [create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md @@ -87,7 +87,7 @@ completed before the run. [queue-send-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueSendController.java [topic-receive-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/TopicReceiveController.java [topic-send-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/TopicSendController.java - +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/README.md index 818931947e3b..93c2489bfc38 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/README.md @@ -72,11 +72,11 @@ completed before the run. [azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: http://ms.portal.azure.com/ +[azure-portal]: https://ms.portal.azure.com/ [create-azure-storage]: https://docs.microsoft.com/azure/storage/ [create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md [create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [send-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/src/main/java/com/azure/spring/sample/storage/queue/SendController.java [receive-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/src/main/java/com/azure/spring/sample/storage/queue/ReceiveController.java - +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/src/main/resources/application.yaml diff --git a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.java b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.java index 47870e4c16c6..04aa63dfee29 100644 --- a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.java +++ b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.java @@ -4,7 +4,6 @@ package com.azure.spring.cloud.autoconfigure.context; import com.azure.core.credential.TokenCredential; -import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.management.profile.AzureProfile; import com.azure.resourcemanager.AzureResourceManager; import com.azure.spring.cloud.autoconfigure.telemetry.SubscriptionSupplier; diff --git a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/config/AzureProperties.java b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/config/AzureProperties.java index 97ebcd15cc7e..9cf1fc6aaff3 100644 --- a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/config/AzureProperties.java +++ b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/config/AzureProperties.java @@ -3,7 +3,7 @@ package com.azure.spring.cloud.context.core.config; -import com.azure.core.management.AzureEnvironment; + import com.azure.spring.cloud.context.core.api.CredentialSupplier; import com.azure.spring.cloud.context.core.enums.AzureEnvironments; import com.google.common.base.Strings; diff --git a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/enums/package-info.java b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/enums/package-info.java new file mode 100644 index 000000000000..1de728776368 --- /dev/null +++ b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/enums/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * Package com.azure.spring.cloud.context.core.enums; + */ +package com.azure.spring.cloud.context.core.enums; diff --git a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/EventHubManager.java b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/EventHubManager.java index b409c19c5d38..ff3bdfbe3d52 100644 --- a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/EventHubManager.java +++ b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/EventHubManager.java @@ -38,8 +38,7 @@ public EventHub internalGet(Tuple namespaceAndName) { return azureResourceManager.eventHubs() .getByName(resourceGroup, namespaceAndName.getFirst().name(), namespaceAndName.getSecond()); - } catch ( - ManagementException e) { + } catch (ManagementException e) { if (e.getResponse().getStatusCode() == 404) { return null; } else { diff --git a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/RedisCacheManager.java b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/RedisCacheManager.java index 549226e79c76..47fa374c8687 100644 --- a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/RedisCacheManager.java +++ b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/RedisCacheManager.java @@ -3,7 +3,6 @@ package com.azure.spring.cloud.context.core.impl; -import com.azure.core.management.exception.ManagementError; import com.azure.core.management.exception.ManagementException; import com.azure.resourcemanager.AzureResourceManager; import com.azure.resourcemanager.redis.models.RedisCache; diff --git a/sdk/spring/azure-spring-cloud-context/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfigurationTest.java b/sdk/spring/azure-spring-cloud-context/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfigurationTest.java index 56da5b81c8fe..63a69f6d5da3 100644 --- a/sdk/spring/azure-spring-cloud-context/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfigurationTest.java +++ b/sdk/spring/azure-spring-cloud-context/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfigurationTest.java @@ -33,45 +33,47 @@ public void testAzureDisabled() { @Test public void testWithoutAzureClass() { this.contextRunner.withClassLoader(new FilteredClassLoader(AzureResourceManager.class)) - .run(context -> assertThat(context).doesNotHaveBean(AzureProperties.class)); + .run(context -> assertThat(context).doesNotHaveBean(AzureProperties.class)); } @Test(expected = IllegalStateException.class) public void testLocationRequiredWhenAutoCreateResources() { this.contextRunner.withPropertyValues(AZURE_PROPERTY_PREFIX + "resourceGroup=group1") - .withPropertyValues(AZURE_PROPERTY_PREFIX + "auto-create-resources=true") - .run(context -> context.getBean(AzureProperties.class)); + .withPropertyValues(AZURE_PROPERTY_PREFIX + "auto-create-resources=true") + .run(context -> context.getBean(AzureProperties.class)); } @Test public void testAzurePropertiesConfigured() { - this.contextRunner.withPropertyValues( - AZURE_PROPERTY_PREFIX + "client-id=client1", - AZURE_PROPERTY_PREFIX + "client-secret=secret1", - AZURE_PROPERTY_PREFIX + "tenant-id=tenant1", - AZURE_PROPERTY_PREFIX + "resource-group=rg1", - AZURE_PROPERTY_PREFIX + "region=region1", - AZURE_PROPERTY_PREFIX + "subscriptionId=sub1") - .run(context -> { - assertThat(context).hasSingleBean(AzureProperties.class); - assertThat(context.getBean(AzureProperties.class).getClientId()).isEqualTo("client1"); - assertThat(context.getBean(AzureProperties.class).getClientSecret()).isEqualTo("secret1"); - assertThat(context.getBean(AzureProperties.class).getTenantId()).isEqualTo("tenant1"); - assertThat(context.getBean(AzureProperties.class).getResourceGroup()).isEqualTo("rg1"); - assertThat(context.getBean(AzureProperties.class).getRegion()).isEqualTo("region1"); - assertThat(context.getBean(AzureProperties.class).getSubscriptionId()).isEqualTo("sub1"); - assertThat(context.getBean(AzureProperties.class).getEnvironment()).isEqualTo(AzureEnvironment.AZURE); - }); + this.contextRunner + .withPropertyValues( + AZURE_PROPERTY_PREFIX + "client-id=client1", + AZURE_PROPERTY_PREFIX + "client-secret=secret1", + AZURE_PROPERTY_PREFIX + "tenant-id=tenant1", + AZURE_PROPERTY_PREFIX + "resource-group=rg1", + AZURE_PROPERTY_PREFIX + "region=region1", + AZURE_PROPERTY_PREFIX + "subscriptionId=sub1") + .run(context -> { + assertThat(context).hasSingleBean(AzureProperties.class); + assertThat(context.getBean(AzureProperties.class).getClientId()).isEqualTo("client1"); + assertThat(context.getBean(AzureProperties.class).getClientSecret()).isEqualTo("secret1"); + assertThat(context.getBean(AzureProperties.class).getTenantId()).isEqualTo("tenant1"); + assertThat(context.getBean(AzureProperties.class).getResourceGroup()).isEqualTo("rg1"); + assertThat(context.getBean(AzureProperties.class).getRegion()).isEqualTo("region1"); + assertThat(context.getBean(AzureProperties.class).getSubscriptionId()).isEqualTo("sub1"); + assertThat(context.getBean(AzureProperties.class).getEnvironment().getAzureEnvironment()) + .isEqualTo(AzureEnvironment.AZURE); + }); } @Test public void testAutoConfigureEnabled() { this.contextRunner.withPropertyValues(AZURE_PROPERTY_PREFIX + "resource-group=rg1") - .withUserConfiguration(TestConfigurationWithResourceManager.class) - .run(context -> { - assertThat(context).hasSingleBean(AzureProperties.class); - assertThat(context).hasSingleBean(AzureProfile.class); - }); + .withUserConfiguration(TestConfigurationWithResourceManager.class) + .run(context -> { + assertThat(context).hasSingleBean(AzureProperties.class); + assertThat(context).hasSingleBean(AzureProfile.class); + }); } @Configuration diff --git a/sdk/spring/azure-spring-cloud-context/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureEnvironmentConfigurationTest.java b/sdk/spring/azure-spring-cloud-context/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureEnvironmentConfigurationTest.java index 2a8f482b6b0c..374d38b178b8 100644 --- a/sdk/spring/azure-spring-cloud-context/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureEnvironmentConfigurationTest.java +++ b/sdk/spring/azure-spring-cloud-context/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureEnvironmentConfigurationTest.java @@ -3,6 +3,8 @@ package com.azure.spring.cloud.autoconfigure.context; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; import com.azure.core.management.AzureEnvironment; import com.azure.resourcemanager.AzureResourceManager; import com.azure.spring.cloud.context.core.api.CredentialsProvider; @@ -10,13 +12,11 @@ import com.azure.spring.cloud.context.core.config.AzureProperties; import org.junit.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - public class AzureEnvironmentConfigurationTest { private static final String AZURE_PROPERTY_PREFIX = "spring.cloud.azure."; @@ -32,14 +32,23 @@ public void testAutoConfigure() { }); } - // TODO users could autoconfigure environment @Test public void testWithAnotherEnvironment() { - this.contextRunner.withBean(AzureProperties.class) - .run(context -> { - assertThat(context).hasSingleBean(EnvironmentProvider.class); - assertThat(context.getBean(EnvironmentProvider.class).getEnvironment()).isEqualTo(AzureEnvironment.AZURE_CHINA); - }); + this.contextRunner + .withUserConfiguration(TestConfigurationWithProperty.class) + .withPropertyValues(AZURE_PROPERTY_PREFIX + "environment=AzureChina") + .run(context -> { + assertThat(context).hasSingleBean(EnvironmentProvider.class); + assertThat(context.getBean(EnvironmentProvider.class).getEnvironment()) + .isEqualTo(AzureEnvironment.AZURE_CHINA); + }); + } + + + @Configuration + @EnableConfigurationProperties(AzureProperties.class) + static class TestConfigurationWithProperty { + } @Configuration