Search in sources :

Example 1 with CreateNetworkRequestData

use of bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData in project terra-workspace-manager by DataBiosphere.

the class CreateAzureNetworkStepTest method createNetwork.

@Test
void createNetwork() throws InterruptedException {
    final ApiAzureNetworkCreationParameters creationParameters = ControlledResourceFixtures.getAzureNetworkCreationParameters();
    var createAzureNetworkStep = new CreateAzureNetworkStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureNetwork(creationParameters));
    final StepResult stepResult = createAzureNetworkStep.doStep(mockFlightContext);
    // Verify step returns success
    assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
    // Verify Azure create call was made correctly
    verify(mockNetworkStage13).create(contextCaptor.capture());
    Context context = contextCaptor.getValue();
    Optional<CreateNetworkRequestData> requestDataOpt = context.getValues().values().stream().filter(CreateNetworkRequestData.class::isInstance).map(CreateNetworkRequestData.class::cast).findFirst();
    CreateNetworkRequestData expected = CreateNetworkRequestData.builder().setName(creationParameters.getName()).setRegion(Region.fromName(creationParameters.getRegion())).setSubnetName(creationParameters.getSubnetName()).setAddressSpaceCidr(creationParameters.getAddressSpaceCidr()).setNetworkSecurityGroup(mockNsg).setAddressPrefix(creationParameters.getSubnetAddressCidr()).setTenantId(mockAzureCloudContext.getAzureTenantId()).setSubscriptionId(mockAzureCloudContext.getAzureSubscriptionId()).setResourceGroupName(mockAzureCloudContext.getAzureResourceGroupId()).build();
    assertThat(requestDataOpt, equalTo(Optional.of(expected)));
}
Also used : Context(com.azure.core.util.Context) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) CreateNetworkRequestData(bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData) ApiAzureNetworkCreationParameters(bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters) StepResult(bio.terra.stairway.StepResult) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 2 with CreateNetworkRequestData

use of bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData in project terra-cloud-resource-lib by DataBiosphere.

the class ComputeRequestDataTest method serializeCreateNetwork.

@Test
public void serializeCreateNetwork() {
    CreateNetworkRequestData createNetwork = CreateNetworkRequestData.builder().setName("my-network").setTenantId("my-tenant").setSubscriptionId("my-sub").setResourceGroupName("my-rg").setRegion(Region.US_EAST).setAddressSpaceCidr("192.168.0.0/16").setSubnetName("my-subnet").setAddressPrefix("192.168.1.0/24").setNetworkSecurityGroup(mockNetworkSecurityGroup()).build();
    assertEquals(ComputeManagerOperation.AZURE_CREATE_NETWORK, createNetwork.cloudOperation());
    assertEquals("{\"tenantId\":\"my-tenant\",\"subscriptionId\":\"my-sub\",\"resourceGroupName\":\"my-rg\"," + "\"name\":\"my-network\",\"region\":\"eastus\"," + "\"addressSpaceCidr\":\"192.168.0.0/16\",\"subnetName\":\"my-subnet\"," + "\"addressPrefix\":\"192.168.1.0/24\",\"networkSecurityGroupName\":\"my-nsg\"}", createNetwork.serialize().toString());
    assertEquals(Optional.of(new CloudResourceUid().azureNetwork(new AzureNetwork().resourceGroup(azureResourceGroup(createNetwork)).networkName("my-network"))), createNetwork.resourceUidCreation());
}
Also used : CloudResourceUid(bio.terra.janitor.model.CloudResourceUid) CreateNetworkRequestData(bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData) AzureNetwork(bio.terra.janitor.model.AzureNetwork) Test(org.junit.jupiter.api.Test)

Aggregations

CreateNetworkRequestData (bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData)2 Test (org.junit.jupiter.api.Test)2 AzureNetwork (bio.terra.janitor.model.AzureNetwork)1 CloudResourceUid (bio.terra.janitor.model.CloudResourceUid)1 FlightContext (bio.terra.stairway.FlightContext)1 StepResult (bio.terra.stairway.StepResult)1 BaseAzureTest (bio.terra.workspace.common.BaseAzureTest)1 ApiAzureNetworkCreationParameters (bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters)1 AzureCloudContext (bio.terra.workspace.service.workspace.model.AzureCloudContext)1 Context (com.azure.core.util.Context)1