Search in sources :

Example 1 with NetworkV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response in project cloudbreak by hortonworks.

the class NetworkToNetworkV4ResponseConverterTest method testConvertShouldRCallTheParserWhenTheStackStackDoesNotContainNetworkRelatedResources.

@Test
public void testConvertShouldRCallTheParserWhenTheStackStackDoesNotContainNetworkRelatedResources() throws JsonProcessingException {
    Resource gcpDisk = new Resource();
    gcpDisk.setResourceType(ResourceType.GCP_DISK);
    gcpDisk.setResourceName("myproject-attachedworkerdisk");
    when(stack.getResources()).thenReturn(Set.of(gcpDisk));
    when(stack.getNetwork()).thenReturn(network);
    Map<String, Object> attributes = Map.of("cloudPlatform", "GCP");
    when(network.getAttributes()).thenReturn(new Json(attributes));
    when(network.getSubnetCIDR()).thenReturn(DEFAULT_CIDR);
    NetworkV4Response result = underTest.convert(stack);
    verify(providerParameterCalculator).parse(eq(attributes), any());
    assertNotNull(result);
    assertEquals(DEFAULT_CIDR, result.getSubnetCIDR());
}
Also used : NetworkV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response) Resource(com.sequenceiq.cloudbreak.domain.Resource) Json(com.sequenceiq.cloudbreak.common.json.Json) Test(org.junit.jupiter.api.Test)

Example 2 with NetworkV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response in project cloudbreak by hortonworks.

the class NetworkToNetworkV4ResponseConverterTest method testConvertShouldRCallTheParserWhenTheStackStackContainsNetworkRelatedResources.

@Test
public void testConvertShouldRCallTheParserWhenTheStackStackContainsNetworkRelatedResources() throws JsonProcessingException {
    Resource vpc = new Resource();
    vpc.setResourceType(ResourceType.AWS_VPC);
    vpc.setResourceName("idOfTheCreatedVPC");
    Resource subnet = new Resource();
    subnet.setResourceType(ResourceType.AWS_SUBNET);
    subnet.setResourceName("idOfTheCreatedSubnet");
    Resource azureNetwork = new Resource();
    azureNetwork.setResourceType(ResourceType.AZURE_NETWORK);
    azureNetwork.setResourceName("idOfTheCreatedAzureNetwork");
    when(stack.getResources()).thenReturn(Set.of(vpc, subnet, azureNetwork));
    when(stack.getNetwork()).thenReturn(network);
    Map<String, Object> attributes = Map.of("cloudPlatform", "MOCK");
    when(network.getAttributes()).thenReturn(new Json(attributes));
    when(network.getSubnetCIDR()).thenReturn(DEFAULT_CIDR);
    NetworkV4Response result = underTest.convert(stack);
    Map<String, Object> expectedParameters = new HashMap<>(attributes);
    expectedParameters.put("vpcId", vpc.getResourceName());
    expectedParameters.put("subnetId", subnet.getResourceName());
    expectedParameters.put("networkId", azureNetwork.getResourceName());
    verify(providerParameterCalculator).parse(eq(expectedParameters), any());
    assertNotNull(result);
    assertEquals(DEFAULT_CIDR, result.getSubnetCIDR());
}
Also used : NetworkV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response) HashMap(java.util.HashMap) Resource(com.sequenceiq.cloudbreak.domain.Resource) Json(com.sequenceiq.cloudbreak.common.json.Json) Test(org.junit.jupiter.api.Test)

Example 3 with NetworkV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response in project cloudbreak by hortonworks.

the class NetworkToNetworkV4ResponseConverterTest method testConvertShouldReturnNullWhenTheStackDoesNotHaveAssignedNetwork.

@Test
public void testConvertShouldReturnNullWhenTheStackDoesNotHaveAssignedNetwork() {
    when(stack.getNetwork()).thenReturn(null);
    NetworkV4Response result = underTest.convert(stack);
    assertNull(result);
}
Also used : NetworkV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response) Test(org.junit.jupiter.api.Test)

Example 4 with NetworkV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response in project cloudbreak by hortonworks.

the class StackToStackV4ResponseConverterTest method testConvert.

@Test
public void testConvert() throws CloudbreakImageNotFoundException {
    Stack source = getSource();
    // GIVEN
    given(imageService.getImage(source.getId())).willReturn(mock(Image.class));
    given(imageToStackImageV4ResponseConverter.convert(any(Image.class))).willReturn(new StackImageV4Response());
    given(stackAuthenticationToStackAuthenticationV4ResponseConverter.convert(any(StackAuthentication.class))).willReturn(new StackAuthenticationV4Response());
    given(stackToCustomDomainsSettingsV4Response.convert(any())).willReturn(new CustomDomainSettingsV4Response());
    given(clusterToClusterV4ResponseConverter.convert(any())).willReturn(new ClusterV4Response());
    given(networkToNetworkV4ResponseConverter.convert(any())).willReturn(new NetworkV4Response());
    given(workspaceToWorkspaceResourceV4ResponseConverter.convert(any())).willReturn(new WorkspaceResourceV4Response());
    given(cloudbreakDetailsToCloudbreakDetailsV4ResponseConverter.convert(any())).willReturn(new CloudbreakDetailsV4Response());
    given(stackToPlacementSettingsV4ResponseConverter.convert(any())).willReturn(new PlacementSettingsV4Response());
    given(telemetryConverter.convert(any())).willReturn(new TelemetryResponse());
    given(instanceGroupToInstanceGroupV4ResponseConverter.convert(any())).willReturn(new InstanceGroupV4Response());
    given(databaseAvailabilityTypeToDatabaseResponseConverter.convert(any(), any())).willReturn(new DatabaseResponse());
    // WHEN
    StackV4Response result = underTest.convert(source);
    // THEN
    assertAllFieldsNotNull(result, Arrays.asList("gcp", "mock", "openstack", "aws", "yarn", "azure", "environmentName", "credentialName", "credentialCrn", "telemetry", "flowIdentifier", "loadBalancers"));
    verify(restRequestThreadLocalService).setWorkspace(source.getWorkspace());
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) ClusterV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) DatabaseResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseResponse) CustomDomainSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.customdomain.CustomDomainSettingsV4Response) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) WorkspaceResourceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.workspace.responses.WorkspaceResourceV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackAuthenticationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.authentication.StackAuthenticationV4Response) NetworkV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response) CloudbreakDetailsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CloudbreakDetailsV4Response) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) PlacementSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.PlacementSettingsV4Response) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 5 with NetworkV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response in project cloudbreak by hortonworks.

the class StackToStackV4ResponseConverterTest method testConvertWithoutCluster.

@Test
public void testConvertWithoutCluster() throws CloudbreakImageNotFoundException {
    Stack source = getSource();
    // GIVEN
    getSource().setCluster(null);
    given(imageService.getImage(source.getId())).willReturn(mock(Image.class));
    given(imageToStackImageV4ResponseConverter.convert(any())).willReturn(new StackImageV4Response());
    given(stackToCustomDomainsSettingsV4Response.convert(any())).willReturn(new CustomDomainSettingsV4Response());
    given(stackAuthenticationToStackAuthenticationV4ResponseConverter.convert(any())).willReturn(new StackAuthenticationV4Response());
    given(networkToNetworkV4ResponseConverter.convert(any())).willReturn(new NetworkV4Response());
    given(workspaceToWorkspaceResourceV4ResponseConverter.convert(any())).willReturn(new WorkspaceResourceV4Response());
    given(cloudbreakDetailsToCloudbreakDetailsV4ResponseConverter.convert(any())).willReturn(new CloudbreakDetailsV4Response());
    given(stackToPlacementSettingsV4ResponseConverter.convert(any())).willReturn(new PlacementSettingsV4Response());
    given(telemetryConverter.convert(any())).willReturn(new TelemetryResponse());
    given(instanceGroupToInstanceGroupV4ResponseConverter.convert(any())).willReturn(new InstanceGroupV4Response());
    given(databaseAvailabilityTypeToDatabaseResponseConverter.convert(any(), any())).willReturn(new DatabaseResponse());
    // WHEN
    StackV4Response result = underTest.convert(source);
    // THEN
    assertAllFieldsNotNull(result, Arrays.asList("cluster", "gcp", "mock", "openstack", "aws", "yarn", "azure", "telemetry", "environmentName", "credentialName", "credentialCrn", "telemetry", "flowIdentifier", "loadBalancers"));
    assertNull(result.getCluster());
    verify(restRequestThreadLocalService).setWorkspace(source.getWorkspace());
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) DatabaseResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseResponse) CustomDomainSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.customdomain.CustomDomainSettingsV4Response) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) WorkspaceResourceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.workspace.responses.WorkspaceResourceV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackAuthenticationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.authentication.StackAuthenticationV4Response) NetworkV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response) CloudbreakDetailsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CloudbreakDetailsV4Response) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) PlacementSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.PlacementSettingsV4Response) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Aggregations

NetworkV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response)8 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 Test (org.junit.jupiter.api.Test)4 CloudbreakDetailsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CloudbreakDetailsV4Response)3 PlacementSettingsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.PlacementSettingsV4Response)3 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)3 StackAuthenticationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.authentication.StackAuthenticationV4Response)3 CustomDomainSettingsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.customdomain.CustomDomainSettingsV4Response)3 DatabaseResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseResponse)3 StackImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response)3 InstanceGroupV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response)3 WorkspaceResourceV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.workspace.responses.WorkspaceResourceV4Response)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 AbstractEntityConverterTest (com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest)3 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)3 Test (org.junit.Test)3 Json (com.sequenceiq.cloudbreak.common.json.Json)2 Resource (com.sequenceiq.cloudbreak.domain.Resource)2 ClusterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response)1 Network (com.sequenceiq.cloudbreak.domain.Network)1