Skip to content

Commit

Permalink
mgmt, frontdoor tests (Azure#23714)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Aug 23, 2021
1 parent 00ca25d commit 4e4e3f9
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.datafactory;

Expand Down
18 changes: 18 additions & 0 deletions sdk/frontdoor/azure-resourcemanager-frontdoor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@
<artifactId>azure-core-management</artifactId>
<version>1.4.0</version> <!-- {x-version-update;com.azure:azure-core-management;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.3.5</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.7.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-storage</artifactId>
<version>2.7.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-storage;dependency} -->
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.frontdoor;

import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.Region;
import com.azure.core.management.SubResource;
import com.azure.core.management.profile.AzureProfile;
import com.azure.core.test.TestBase;
import com.azure.core.test.annotation.DoNotRecord;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.frontdoor.fluent.models.FrontendEndpointInner;
import com.azure.resourcemanager.frontdoor.models.Backend;
import com.azure.resourcemanager.frontdoor.models.BackendEnabledState;
import com.azure.resourcemanager.frontdoor.models.BackendPool;
import com.azure.resourcemanager.frontdoor.models.ForwardingConfiguration;
import com.azure.resourcemanager.frontdoor.models.FrontDoor;
import com.azure.resourcemanager.frontdoor.models.FrontDoorForwardingProtocol;
import com.azure.resourcemanager.frontdoor.models.FrontDoorHealthProbeMethod;
import com.azure.resourcemanager.frontdoor.models.FrontDoorProtocol;
import com.azure.resourcemanager.frontdoor.models.HealthProbeEnabled;
import com.azure.resourcemanager.frontdoor.models.HealthProbeSettingsModel;
import com.azure.resourcemanager.frontdoor.models.LoadBalancingSettingsModel;
import com.azure.resourcemanager.frontdoor.models.RoutingRule;
import com.azure.resourcemanager.frontdoor.models.RoutingRuleEnabledState;
import com.azure.resourcemanager.frontdoor.models.SessionAffinityEnabledState;
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceId;
import com.azure.resourcemanager.storage.StorageManager;
import com.azure.resourcemanager.storage.models.StorageAccount;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.Random;

public class FrontDoorTests extends TestBase {

private static final Region REGION = Region.US_EAST2;

private String subscriptionId;
private String resourceGroupName;
private String fdName;

@Test
@DoNotRecord(skipInPlayback = true)
public void frontDoorTest() {
StorageManager storageManager = StorageManager
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE));

FrontDoorManager manager = FrontDoorManager
.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE));

resourceGroupName = "rg" + randomPadding();
String saName = "sa" + randomPadding();
fdName = "fd" + randomPadding();

storageManager.resourceManager().resourceGroups().define(resourceGroupName)
.withRegion(REGION)
.create();

try {
// @embedmeStart
StorageAccount storageAccount = storageManager.storageAccounts()
.define(saName)
.withRegion(REGION)
.withExistingResourceGroup(resourceGroupName)
.create();

String backendAddress = fdName + ".blob.core.windows.net";
String frontendName = "frontend1";
String loadBalancingName = "loadbalancing1";
String healthProbeName = "healthprobe1";
String routingRuleName = "rule1";
String backendPoolName = "backend1";
subscriptionId = ResourceId.fromString(storageAccount.id()).subscriptionId();
String frontendEndpointsId = getResourceId("frontendEndpoints", frontendName);
String loadBalancingSettingsId = getResourceId("loadBalancingSettings", loadBalancingName);
String healthProbeSettingsId = getResourceId("healthProbeSettings", healthProbeName);
String backendPoolsId = getResourceId("backendPools", backendPoolName);

FrontDoor frontDoor = manager.frontDoors().define(fdName)
.withRegion("global")
.withExistingResourceGroup(resourceGroupName)
.withFrontendEndpoints(Collections.singletonList(
new FrontendEndpointInner()
.withName(frontendName)
.withHostname(fdName + ".azurefd.net")
.withSessionAffinityEnabledState(SessionAffinityEnabledState.DISABLED)
))
.withBackendPools(Collections.singletonList(
new BackendPool().withName(backendPoolName).withBackends(Collections.singletonList(
new Backend()
.withAddress(backendAddress)
.withEnabledState(BackendEnabledState.ENABLED)
.withBackendHostHeader(backendAddress)
.withHttpPort(80)
.withHttpsPort(443)
.withPriority(1)
.withWeight(50)
))
.withLoadBalancingSettings(new SubResource().withId(loadBalancingSettingsId))
.withHealthProbeSettings(new SubResource().withId(healthProbeSettingsId))
))
.withLoadBalancingSettings(Collections.singletonList(
new LoadBalancingSettingsModel()
.withName(loadBalancingName)
.withSampleSize(4)
.withSuccessfulSamplesRequired(2)
.withAdditionalLatencyMilliseconds(0)
))
.withHealthProbeSettings(Collections.singletonList(
new HealthProbeSettingsModel()
.withName(healthProbeName)
.withEnabledState(HealthProbeEnabled.ENABLED)
.withPath("/")
.withProtocol(FrontDoorProtocol.HTTPS)
.withHealthProbeMethod(FrontDoorHealthProbeMethod.HEAD)
.withIntervalInSeconds(30)
))
.withRoutingRules(Collections.singletonList(
new RoutingRule()
.withName(routingRuleName)
.withEnabledState(RoutingRuleEnabledState.ENABLED)
.withFrontendEndpoints(Collections.singletonList(new SubResource().withId(frontendEndpointsId)))
.withAcceptedProtocols(Arrays.asList(FrontDoorProtocol.HTTP, FrontDoorProtocol.HTTPS))
.withPatternsToMatch(Collections.singletonList("/*"))
.withRouteConfiguration(new ForwardingConfiguration()
.withForwardingProtocol(FrontDoorForwardingProtocol.HTTPS_ONLY)
.withBackendPool(new SubResource().withId(backendPoolsId)))
))
.create();
// @embedmeEnd
} finally {
storageManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroupName);
}
}

private static final Random RANDOM = new Random();

private static String randomPadding() {
return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000));
}

private String getResourceId(String type, String name) {
return String.format("/subscriptions/%1$s/resourceGroups/%2$s/providers/Microsoft.Network/frontdoors/%3$s/%4$s/%5$s",
subscriptionId, resourceGroupName, fdName, type, name);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.hdinsight;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.resourcegraph;

Expand Down

0 comments on commit 4e4e3f9

Please sign in to comment.