Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Automation] Generate Fluent Lite from deviceprovisioningservices# #21149

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<version>2.4.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-test</artifactId>
<version>2.0.0-beta.1</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-test;current} -->
Copy link
Member

@weidongxu-microsoft weidongxu-microsoft May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better not to include this.

If you really really need this, you need to put it in a profile, as this azure-resourcemanager-test is not released to maven.

    <profile>
      <id>azure-mgmt-sdk-test-jar</id>
      <activation>
        <property>
          <name>!maven.test.skip</name>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.azure.resourcemanager</groupId>
          <artifactId>azure-resourcemanager-test</artifactId>
          <version>2.0.0-beta.1</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-test;current} -->
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>

<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
Expand All @@ -75,6 +81,18 @@
<version>1.7.30</version> <!-- {x-version-update;org.slf4j:slf4j-simple;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.1</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.1</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -90,8 +108,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class Constants
{
public static final String ACCESS_KEY_NAME = "provisioningserviceowner";


public static final String DEFAULT_LOCATION = "WestUS2";

public static class DefaultSku
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.deviceprovisioningservices;

import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.resources.ResourceManager;
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
import com.azure.resourcemanager.test.ResourceManagerTestBase;
import com.azure.resourcemanager.test.utils.TestDelayProvider;

import java.time.temporal.ChronoUnit;
import java.util.List;

public class DeviceProvisioningResourceManagementTestBase extends ResourceManagerTestBase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't think you need this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I had been modeling my test code on the Key Vault Resource Management SDK, but is there a more recent control plane SDK that I should model my test code on?

{
ResourceManager resourceManager;
IotDpsManager iotDpsManager;
String resourceGroupName = "";
String provisioningServiceName = "";

@Override
protected HttpPipeline buildHttpPipeline(
TokenCredential credential,
AzureProfile profile,
HttpLogOptions httpLogOptions,
List<HttpPipelinePolicy> policies,
HttpClient httpClient) {
return HttpPipelineProvider.buildHttpPipeline(
credential,
profile,
null,
httpLogOptions,
null,
new RetryPolicy("Retry-After", ChronoUnit.SECONDS),
policies,
httpClient);
}

@Override
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) {
resourceGroupName = generateRandomResourceName("javacsmrg", 15);
provisioningServiceName = generateRandomResourceName("java-deviceprovisioning-", 20);

ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));

//IotDpsManager iotDpsManager = buildManager(IotDpsManager.class, httpPipeline, profile);
iotDpsManager =
IotDpsManager
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE));

resourceManager =
ResourceManager
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE))
.withDefaultSubscription();
}

@Override
protected void cleanUpResources() {
resourceManager.resourceGroups().beginDeleteByName(resourceGroupName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,24 @@

package com.azure.resourcemanager.deviceprovisioningservices;

import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.Region;
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.deviceprovisioningservices.fluent.models.ProvisioningServiceDescriptionInner;
import com.azure.resourcemanager.deviceprovisioningservices.models.NameAvailabilityInfo;
import com.azure.resourcemanager.deviceprovisioningservices.models.OperationInputs;
import com.azure.resourcemanager.deviceprovisioningservices.models.ProvisioningServiceDescription;
import com.azure.resourcemanager.resources.ResourceManager;
import com.azure.resourcemanager.resources.models.ResourceGroup;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class DeviceProvisioningResourceManagementTests extends TestBase {
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class DeviceProvisioningResourceManagementTests extends DeviceProvisioningResourceManagementTestBase
{
private static final Region DEFAULT_REGION = Region.US_WEST_CENTRAL;

@Test
@DoNotRecord(skipInPlayback = true)
public void CreateAndDelete() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow Java convention, else build will fail.

String testName = "testingDPSCreateUpdate";
String resourceGroupName = testName;
String provisioningServiceName = testName;

ResourceManager resourceManager = ResourceManager
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE))
.withDefaultSubscription();

IotDpsManager iotDpsManager = IotDpsManager
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE));

ResourceGroup group = resourceManager.resourceGroups()
.define(resourceGroupName)
.withRegion(DEFAULT_REGION)
.create();

Assertions.assertNotNull(group);

NameAvailabilityInfo nameAvailabilityInfo =
iotDpsManager
.iotDpsResources()
.checkProvisioningServiceNameAvailability(new OperationInputs().withName(testName));

if (nameAvailabilityInfo.nameAvailable() != null && !nameAvailabilityInfo.nameAvailable())
{
// it exists, so test deleting it
iotDpsManager.iotDpsResources().delete(testName, resourceGroupName, null);

// check the name is now available
nameAvailabilityInfo = iotDpsManager
.iotDpsResources()
.checkProvisioningServiceNameAvailability(new OperationInputs().withName(testName));

assertTrue(nameAvailabilityInfo.nameAvailable());
if (skipInPlayback()) {
return;
}

// try to create a DPS service
Expand All @@ -75,6 +35,6 @@ public void CreateAndDelete() {

assertNotNull(updatedProvisioningServiceDescriptionInner);
assertEquals(Constants.DefaultSku.NAME, updatedProvisioningServiceDescriptionInner.sku().name().toString());
assertEquals(testName, updatedProvisioningServiceDescriptionInner.name());
assertEquals(provisioningServiceName, updatedProvisioningServiceDescriptionInner.name());
}
}