-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azure-core, add new
AzureCloud
expandable enum (#43099)
* azure cloud * remove getAzureCloud * licence header * add  in test * changelog for core-management * suppress test warnings * spotless * move AzureProfile to com.azure.core.models * fix changelog * remove deprecation * nit, javadoc
- Loading branch information
1 parent
c9f9b83
commit dbd675b
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...core/azure-core-management/src/test/java/com/azure/core/management/AzureProfileTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.management; | ||
|
||
import com.azure.core.management.profile.AzureProfile; | ||
import com.azure.core.models.AzureCloud; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
|
||
public class AzureProfileTests { | ||
@Test | ||
public void testFromAzureCloud() { | ||
// normal case | ||
AzureProfile azurePublicCloud = new AzureProfile(AzureCloud.AZURE_PUBLIC_CLOUD); | ||
Assertions.assertEquals(AzureEnvironment.AZURE, azurePublicCloud.getEnvironment()); | ||
|
||
AzureProfile azureChinaCloud = new AzureProfile(AzureCloud.AZURE_CHINA_CLOUD); | ||
Assertions.assertEquals(AzureEnvironment.AZURE_CHINA, azureChinaCloud.getEnvironment()); | ||
|
||
AzureProfile azureUSGovernment = new AzureProfile(AzureCloud.AZURE_US_GOVERNMENT); | ||
Assertions.assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT, azureUSGovernment.getEnvironment()); | ||
|
||
// exception case | ||
// exception when initializing using custom AzureCloud | ||
AzureCloud azureCloud = AzureCloud.fromString("Custom"); | ||
Assertions.assertNotNull(azureCloud); | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> new AzureProfile(azureCloud)); | ||
|
||
AzureProfile customEnvironment = new AzureProfile(new AzureEnvironment(new HashMap<>())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
sdk/core/azure-core/src/main/java/com/azure/core/models/AzureCloud.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.models; | ||
|
||
import com.azure.core.util.ExpandableStringEnum; | ||
|
||
/** | ||
* An expandable enum that describes Azure cloud environment. | ||
*/ | ||
public final class AzureCloud extends ExpandableStringEnum<AzureCloud> { | ||
/** | ||
* Azure public cloud. | ||
*/ | ||
public static final AzureCloud AZURE_PUBLIC_CLOUD = fromString("AZURE_PUBLIC_CLOUD"); | ||
/** | ||
* Azure China cloud. | ||
*/ | ||
public static final AzureCloud AZURE_CHINA_CLOUD = fromString("AZURE_CHINA_CLOUD"); | ||
/** | ||
* Azure US government cloud. | ||
*/ | ||
public static final AzureCloud AZURE_US_GOVERNMENT = fromString("AZURE_US_GOVERNMENT"); | ||
|
||
/** | ||
* Creates or finds an AzureCloud from its string representation. | ||
* | ||
* @param cloudName cloud name to look for | ||
* @return the corresponding AzureCloud | ||
*/ | ||
public static AzureCloud fromString(String cloudName) { | ||
return fromString(cloudName, AzureCloud.class); | ||
} | ||
|
||
/** | ||
* Creates a new instance of {@link AzureCloud} without a {@link #toString()} value. | ||
* <p> | ||
* This constructor shouldn't be called as it will produce a {@link AzureCloud} which doesn't have a | ||
* String enum value. | ||
* | ||
* @deprecated Use one of the constants or the {@link #fromString(String)} factory method. | ||
*/ | ||
@Deprecated | ||
public AzureCloud() { | ||
} | ||
} |