|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +// Code generated by Microsoft (R) TypeSpec Code Generator. |
| 4 | + |
| 5 | +package com.azure.resourcemanager.devopsinfrastructure.generated; |
| 6 | + |
| 7 | +import com.azure.core.credential.AccessToken; |
| 8 | +import com.azure.core.http.HttpClient; |
| 9 | +import com.azure.core.management.AzureEnvironment; |
| 10 | +import com.azure.core.management.profile.AzureProfile; |
| 11 | +import com.azure.core.test.http.MockHttpResponse; |
| 12 | +import com.azure.resourcemanager.devopsinfrastructure.DevOpsInfrastructureManager; |
| 13 | +import com.azure.resourcemanager.devopsinfrastructure.models.AgentProfile; |
| 14 | +import com.azure.resourcemanager.devopsinfrastructure.models.FabricProfile; |
| 15 | +import com.azure.resourcemanager.devopsinfrastructure.models.ManagedServiceIdentity; |
| 16 | +import com.azure.resourcemanager.devopsinfrastructure.models.ManagedServiceIdentityType; |
| 17 | +import com.azure.resourcemanager.devopsinfrastructure.models.OrganizationProfile; |
| 18 | +import com.azure.resourcemanager.devopsinfrastructure.models.Pool; |
| 19 | +import com.azure.resourcemanager.devopsinfrastructure.models.PoolProperties; |
| 20 | +import com.azure.resourcemanager.devopsinfrastructure.models.ProvisioningState; |
| 21 | +import com.azure.resourcemanager.devopsinfrastructure.models.ResourcePredictions; |
| 22 | +import com.azure.resourcemanager.devopsinfrastructure.models.ResourcePredictionsProfile; |
| 23 | +import com.azure.resourcemanager.devopsinfrastructure.models.UserAssignedIdentity; |
| 24 | +import java.nio.charset.StandardCharsets; |
| 25 | +import java.time.OffsetDateTime; |
| 26 | +import java.util.HashMap; |
| 27 | +import java.util.Map; |
| 28 | +import org.junit.jupiter.api.Assertions; |
| 29 | +import org.junit.jupiter.api.Test; |
| 30 | +import reactor.core.publisher.Mono; |
| 31 | + |
| 32 | +public final class PoolsCreateOrUpdateMockTests { |
| 33 | + @Test |
| 34 | + public void testCreateOrUpdate() throws Exception { |
| 35 | + String responseStr |
| 36 | + = "{\"properties\":{\"provisioningState\":\"Succeeded\",\"maximumConcurrency\":1068546777,\"organizationProfile\":{\"kind\":\"OrganizationProfile\"},\"agentProfile\":{\"kind\":\"AgentProfile\",\"resourcePredictions\":{},\"resourcePredictionsProfile\":{\"kind\":\"ResourcePredictionsProfile\"}},\"fabricProfile\":{\"kind\":\"FabricProfile\"},\"devCenterProjectResourceId\":\"eddgssofw\"},\"identity\":{\"principalId\":\"qal\",\"tenantId\":\"mnjijpxacqqudf\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"evfdnwnwm\":{\"principalId\":\"aaabjyvayff\",\"clientId\":\"rzrtuzqogsex\"},\"thzvaytdwkqbrqu\":{\"principalId\":\"zsyyceuzso\",\"clientId\":\"judpfrxt\"},\"oaxoruzfgsqu\":{\"principalId\":\"axhexiilivp\",\"clientId\":\"iirqtd\"}}},\"location\":\"xrxxlep\",\"tags\":{\"wxuqlcvydypatdoo\":\"mxjezwlw\",\"kooebwnu\":\"ojknio\",\"vdkcrodtj\":\"hemms\"},\"id\":\"nfwjlfltkacjvefk\",\"name\":\"lfoakg\",\"type\":\"kfpagao\"}"; |
| 37 | + |
| 38 | + HttpClient httpClient |
| 39 | + = response -> Mono.just(new MockHttpResponse(response, 200, responseStr.getBytes(StandardCharsets.UTF_8))); |
| 40 | + DevOpsInfrastructureManager manager = DevOpsInfrastructureManager.configure() |
| 41 | + .withHttpClient(httpClient) |
| 42 | + .authenticate(tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)), |
| 43 | + new AzureProfile("", "", AzureEnvironment.AZURE)); |
| 44 | + |
| 45 | + Pool response |
| 46 | + = manager.pools() |
| 47 | + .define("dxbjhwuaanozj") |
| 48 | + .withRegion("varmywdmj") |
| 49 | + .withExistingResourceGroup("abfatkl") |
| 50 | + .withTags(mapOf("rw", "bjhhyx")) |
| 51 | + .withProperties(new PoolProperties().withProvisioningState(ProvisioningState.DELETING) |
| 52 | + .withMaximumConcurrency(1082355314) |
| 53 | + .withOrganizationProfile(new OrganizationProfile()) |
| 54 | + .withAgentProfile(new AgentProfile().withResourcePredictions(new ResourcePredictions()) |
| 55 | + .withResourcePredictionsProfile(new ResourcePredictionsProfile())) |
| 56 | + .withFabricProfile(new FabricProfile()) |
| 57 | + .withDevCenterProjectResourceId("l")) |
| 58 | + .withIdentity( |
| 59 | + new ManagedServiceIdentity().withType(ManagedServiceIdentityType.SYSTEM_AND_USER_ASSIGNED) |
| 60 | + .withUserAssignedIdentities(mapOf("jhdgqggebdunyga", new UserAssignedIdentity(), "rxcyjmoad", |
| 61 | + new UserAssignedIdentity()))) |
| 62 | + .create(); |
| 63 | + |
| 64 | + Assertions.assertEquals("xrxxlep", response.location()); |
| 65 | + Assertions.assertEquals("mxjezwlw", response.tags().get("wxuqlcvydypatdoo")); |
| 66 | + Assertions.assertEquals(ProvisioningState.SUCCEEDED, response.properties().provisioningState()); |
| 67 | + Assertions.assertEquals(1068546777, response.properties().maximumConcurrency()); |
| 68 | + Assertions.assertEquals("eddgssofw", response.properties().devCenterProjectResourceId()); |
| 69 | + Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, response.identity().type()); |
| 70 | + } |
| 71 | + |
| 72 | + // Use "Map.of" if available |
| 73 | + @SuppressWarnings("unchecked") |
| 74 | + private static <T> Map<String, T> mapOf(Object... inputs) { |
| 75 | + Map<String, T> map = new HashMap<>(); |
| 76 | + for (int i = 0; i < inputs.length; i += 2) { |
| 77 | + String key = (String) inputs[i]; |
| 78 | + T value = (T) inputs[i + 1]; |
| 79 | + map.put(key, value); |
| 80 | + } |
| 81 | + return map; |
| 82 | + } |
| 83 | +} |
0 commit comments