Skip to content

Commit

Permalink
mgmt, add live tests for arg (#20079)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Mar 24, 2021
1 parent 9c5d7bf commit 6e2f14d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.6.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
18 changes: 18 additions & 0 deletions sdk/resourcegraph/azure-resourcemanager-resourcegraph/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.2.0</version> <!-- {x-version-update;com.azure:azure-core-management;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.2.4</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.6.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version> <!-- {x-version-update;org.slf4j:slf4j-simple;external_dependency} -->
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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;

import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.core.test.TestBase;
import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.resourcegraph.models.QueryRequest;
import com.azure.resourcemanager.resourcegraph.models.QueryRequestOptions;
import com.azure.resourcemanager.resourcegraph.models.QueryResponse;
import com.azure.resourcemanager.resourcegraph.models.ResultFormat;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ResourceGraphTests extends TestBase {

@Test
@DoNotRecord(skipInPlayback = true)
public void queryTest() {
// requires a Azure Subscription
String subscriptionId = Configuration.getGlobalConfiguration().get(Configuration.PROPERTY_AZURE_SUBSCRIPTION_ID);

ResourceGraphManager manager = ResourceGraphManager
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE));

QueryRequest queryRequest = new QueryRequest()
.withSubscriptions(Collections.singletonList(subscriptionId))
.withQuery("Resources | project name, type | limit 5 | order by name asc");
// table format
queryRequest.withOptions(new QueryRequestOptions().withResultFormat(ResultFormat.TABLE));
QueryResponse response = manager.resourceProviders().resources(queryRequest);

Assertions.assertNotNull(response.data());
Assertions.assertTrue(response.data() instanceof Map);

// object array format
queryRequest.withOptions(new QueryRequestOptions().withResultFormat(ResultFormat.OBJECT_ARRAY));
response = manager.resourceProviders().resources(queryRequest);

Assertions.assertNotNull(response.data());
Assertions.assertTrue(response.data() instanceof List);
}
}

0 comments on commit 6e2f14d

Please sign in to comment.