use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class EnvironmentBaseNetworkConverterTest method testConvertToLegacyNetworkWithEndpointAccessGatewayNoPublicSubnets.
@Test
public void testConvertToLegacyNetworkWithEndpointAccessGatewayNoPublicSubnets() {
CloudSubnet privateSubnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
EnvironmentNetworkResponse source = setupResponse();
source.setSubnetMetas(Map.of("key", privateSubnet));
source.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
source.setGatewayEndpointSubnetMetas(Map.of("private-key", privateSubnet));
when(subnetSelector.chooseSubnet(any(), anyMap(), anyString(), any())).thenReturn(Optional.of(privateSubnet));
when(subnetSelector.chooseSubnetForEndpointGateway(any(), anyString())).thenReturn(Optional.empty());
Exception exception = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.convertToLegacyNetwork(source, AZ_1)));
assertEquals("Could not find public subnet in availability zone: AZ-1", exception.getMessage());
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class EnvironmentBaseNetworkConverterTest method testConvertToLegacyNetworkWhenSubnetNotFound.
@Test
public void testConvertToLegacyNetworkWhenSubnetNotFound() {
EnvironmentNetworkResponse source = new EnvironmentNetworkResponse();
source.setSubnetMetas(Map.of("key", getCloudSubnet("any")));
when(subnetSelector.chooseSubnet(any(), anyMap(), anyString(), any())).thenReturn(Optional.empty());
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.convertToLegacyNetwork(source, EU_AZ)));
assertEquals(badRequestException.getMessage(), "No subnet for the given availability zone: eu-west-1a");
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class EnvironmentBaseNetworkConverterTest method testEndpointGatewayIsDisabledd.
@Test
public void testEndpointGatewayIsDisabledd() {
CloudSubnet privateSubnet = getCloudSubnet(AZ_1);
CloudSubnet publicSubnet = getPublicCloudSubnet(PUBLIC_ID_1, AZ_1);
EnvironmentNetworkResponse source = setupResponse();
source.setSubnetMetas(Map.of("key", privateSubnet));
source.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.DISABLED);
source.setGatewayEndpointSubnetMetas(Map.of("public-key", publicSubnet));
when(subnetSelector.chooseSubnet(any(), anyMap(), anyString(), any())).thenReturn(Optional.of(privateSubnet));
Network[] network = new Network[1];
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
network[0] = underTest.convertToLegacyNetwork(source, AZ_1);
});
assertNull(network[0].getAttributes().getValue(ENDPOINT_GATEWAY_SUBNET_ID));
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class GcpEnvironmentNetworkConverterTest method getNetworkIdForAttributeLegacyNetwork.
@Test
void getNetworkIdForAttributeLegacyNetwork() {
EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
EnvironmentNetworkGcpParams environmentNetworkGcpParams = mock(EnvironmentNetworkGcpParams.class);
when(environmentNetworkResponse.getGcp()).thenReturn(environmentNetworkGcpParams);
when(environmentNetworkGcpParams.getNetworkId()).thenReturn(GCP_NETWORK_ID);
Map<String, Object> result = converter.getAttributesForLegacyNetwork(environmentNetworkResponse);
assertEquals(GCP_NETWORK_ID, result.get("networkId"));
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class GcpEnvironmentNetworkConverterTest method getNoPublicIpAttributeForLegacyNetwork.
@Test
void getNoPublicIpAttributeForLegacyNetwork() {
EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
EnvironmentNetworkGcpParams environmentNetworkGcpParams = mock(EnvironmentNetworkGcpParams.class);
when(environmentNetworkResponse.getGcp()).thenReturn(environmentNetworkGcpParams);
when(environmentNetworkGcpParams.getNoPublicIp()).thenReturn(true);
Map<String, Object> result = converter.getAttributesForLegacyNetwork(environmentNetworkResponse);
assertEquals(true, result.get("noPublicIp"));
}
Aggregations