From 6461b150c21ee4204ed7ab4a095cc5d4cea3a7b8 Mon Sep 17 00:00:00 2001 From: Tristan Becker Date: Wed, 11 Oct 2023 14:14:31 +1300 Subject: [PATCH 1/2] Added Sample for resource manager compute and added dependencies to gradle file --- sdk/android/azure-samples/build.gradle.kts | 6 ++++- .../ReadmeSamplesResourceManagerCompute.java | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 sdk/android/azure-samples/src/main/java/com/azure/android/resourcemanager/compute/ReadmeSamplesResourceManagerCompute.java diff --git a/sdk/android/azure-samples/build.gradle.kts b/sdk/android/azure-samples/build.gradle.kts index 522a96dcb646a..99575d65ceca2 100644 --- a/sdk/android/azure-samples/build.gradle.kts +++ b/sdk/android/azure-samples/build.gradle.kts @@ -73,6 +73,10 @@ dependencies { // azure_messaging_eventhubs implementation("com.azure:azure-messaging-eventhubs") + //azure_resourcemanager + implementation("com.azure:azure-core-management") + implementation("com.azure.resourcemanager:azure-resourcemanager-compute:2.31.0") + // android implementation("androidx.appcompat:appcompat:1.6.1") implementation("com.google.android.material:material:1.9.0") @@ -135,4 +139,4 @@ dependencies { because("earlier versions declared as transitive dependencies for azure are not android compatible") } } -} \ No newline at end of file +} diff --git a/sdk/android/azure-samples/src/main/java/com/azure/android/resourcemanager/compute/ReadmeSamplesResourceManagerCompute.java b/sdk/android/azure-samples/src/main/java/com/azure/android/resourcemanager/compute/ReadmeSamplesResourceManagerCompute.java new file mode 100644 index 0000000000000..2bc5702fca56c --- /dev/null +++ b/sdk/android/azure-samples/src/main/java/com/azure/android/resourcemanager/compute/ReadmeSamplesResourceManagerCompute.java @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.android.resourcemanager.compute; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.resourcemanager.compute.ComputeManager; + +/** + * Code samples for the README.md + */ +public class ReadmeSamplesResourceManagerCompute { + + public static void authenticate() { + // BEGIN: readme-sample-authenticate + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + ComputeManager manager = ComputeManager + .authenticate(credential, profile); + // END: readme-sample-authenticate + } +} From 03218dd3b0d790351af2380a07a06effc605566a Mon Sep 17 00:00:00 2001 From: Tristan Becker Date: Mon, 16 Oct 2023 19:53:20 +1300 Subject: [PATCH 2/2] Added Test for Authenticate function --- .../ResourceManagerComputeSampleTests.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 sdk/android/azure-samples/src/androidTest/java/com/azure/android/ResourceManagerComputeSampleTests.java diff --git a/sdk/android/azure-samples/src/androidTest/java/com/azure/android/ResourceManagerComputeSampleTests.java b/sdk/android/azure-samples/src/androidTest/java/com/azure/android/ResourceManagerComputeSampleTests.java new file mode 100644 index 0000000000000..0b3c62e1488cf --- /dev/null +++ b/sdk/android/azure-samples/src/androidTest/java/com/azure/android/ResourceManagerComputeSampleTests.java @@ -0,0 +1,24 @@ +package com.azure.android; + +import static org.junit.Assert.fail; + +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.azure.android.resourcemanager.compute.ReadmeSamplesResourceManagerCompute; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class ResourceManagerComputeSampleTests { + + + @Test + public void testAuthenticate() { + try { + ReadmeSamplesResourceManagerCompute.authenticate(); + } catch (RuntimeException e) { + fail(); + } + } + +}