/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.appservice;
import com.microsoft.azure.management.appservice.implementation.AppServiceManager;
import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager;
import com.microsoft.azure.management.resources.core.TestBase;
import com.microsoft.azure.management.resources.fluentcore.arm.CountryIsoCode;
import com.microsoft.azure.management.resources.fluentcore.arm.CountryPhoneCode;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.implementation.ResourceManager;
import com.microsoft.rest.RestClient;
/**
* The base for app service tests.
*/
public class AppServiceTest extends TestBase {
protected static ResourceManager resourceManager;
protected static KeyVaultManager keyVaultManager;
protected static AppServiceManager appServiceManager;
protected static AppServiceDomain domain;
protected static AppServiceCertificateOrder certificateOrder;
protected static String RG_NAME = "";
@Override
protected void initializeClients(RestClient restClient, String defaultSubscription, String domain) {
RG_NAME = generateRandomResourceName("javacsmrg", 20);
resourceManager = ResourceManager
.authenticate(restClient)
.withSubscription(defaultSubscription);
keyVaultManager = KeyVaultManager
.authenticate(restClient, domain, defaultSubscription);
appServiceManager = AppServiceManager
.authenticate(restClient, domain, defaultSubscription);
useExistingDomainAndCertificate();
//createNewDomainAndCertificate();
}
@Override
protected void cleanUpResources() {
resourceManager.resourceGroups().beginDeleteByName(RG_NAME);
}
private void useExistingDomainAndCertificate() {
String rgName = "rgnemv24d683784f51d";
String certOrder = "wild2crt8b42374211";
String domainName = "jsdk79877.com";
if (System.getenv("appservice-group") != null) {
rgName = System.getenv("appservice-group");
}
if (System.getenv("appservice-domain") != null) {
domainName = System.getenv("appservice-domain");
}
if (System.getenv("appservice-certificateorder") != null) {
certOrder = System.getenv("appservice-certificateorder");
}
domain = appServiceManager.domains().getByResourceGroup(rgName, domainName);
certificateOrder = appServiceManager.certificateOrders().getByResourceGroup(rgName, certOrder);
}
private static void createNewDomainAndCertificate() {
domain = appServiceManager.domains().define(System.getenv("appservice-domain"))
.withExistingResourceGroup(System.getenv("appservice-group"))
.defineRegistrantContact()
.withFirstName("Jon")
.withLastName("Doe")
.withEmail("jondoe@contoso.com")
.withAddressLine1("123 4th Ave")
.withCity("Redmond")
.withStateOrProvince("WA")
.withCountry(CountryIsoCode.UNITED_STATES)
.withPostalCode("98052")
.withPhoneCountryCode(CountryPhoneCode.UNITED_STATES)
.withPhoneNumber("4258828080")
.attach()
.withDomainPrivacyEnabled(true)
.withAutoRenewEnabled(true)
.create();
certificateOrder = appServiceManager.certificateOrders()
.define(System.getenv("appservice-certificateorder"))
.withExistingResourceGroup(System.getenv("appservice-group"))
.withHostName("*." + domain.name())
.withWildcardSku()
.withDomainVerification(domain)
.withNewKeyVault("graphvault", Region.US_WEST)
.withValidYears(1)
.create();
}
}