Search in sources :

Example 1 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method editByNameNetworkChange.

@Test
void editByNameNetworkChange() {
    NetworkDto network = NetworkDto.builder().build();
    EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withNetwork(network).build();
    Environment value = new Environment();
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(value));
    when(networkService.findByEnvironment(any())).thenReturn(Optional.empty());
    when(networkService.saveNetwork(any(), any(), anyString(), any(), any())).thenReturn(new AwsNetwork());
    environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
    ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
    verify(environmentService).save(environmentArgumentCaptor.capture());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test)

Example 2 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork in project cloudbreak by hortonworks.

the class NetworkTest method createNetwork.

protected AwsNetwork createNetwork() {
    AwsNetwork network = new AwsNetwork();
    network.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
    network.setRegistrationType(RegistrationType.EXISTING);
    return network;
}
Also used : AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork)

Example 3 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork in project cloudbreak by hortonworks.

the class NetworkCreationHandlerTest method testWithEndpointGatewayAndEnvironmentSubnets.

@Test
public void testWithEndpointGatewayAndEnvironmentSubnets() {
    EnvironmentDto environmentDto = createEnvironmentDto();
    Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto);
    AwsNetwork network = createNetwork();
    Environment environment = createEnvironment(network);
    Optional<Environment> environmentOptional = Optional.of(environment);
    Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
    subnets.putAll(createDefaultPublicSubnets());
    when(environmentService.findEnvironmentById(any())).thenReturn(environmentOptional);
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
    when(networkMetadataValidationService.getEndpointGatewaySubnetMetadata(any(), any())).thenReturn(Map.of());
    when(environmentResourceService.createAndSetNetwork(any(), any(), any(), any(), any())).thenReturn(network);
    // Testing that underTest.accept() does not throw a BadRequestException
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.accept(environmentDtoEvent));
    assertEquals(0, environmentDto.getNetwork().getEndpointGatewaySubnetMetas().size());
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) NetworkTest(com.sequenceiq.environment.environment.service.network.NetworkTest) Test(org.junit.jupiter.api.Test)

Example 4 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork in project cloudbreak by hortonworks.

the class NetworkCreationHandlerTest method testHandleValidationFailure.

@Test
public void testHandleValidationFailure() {
    EnvironmentDto environmentDto = createEnvironmentDto();
    Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto);
    AwsNetwork network = createNetwork();
    Environment environment = createEnvironment(network);
    Optional<Environment> environmentOptional = Optional.of(environment);
    Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
    when(environmentService.findEnvironmentById(any())).thenReturn(environmentOptional);
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
    when(networkMetadataValidationService.getEndpointGatewaySubnetMetadata(any(), any())).thenThrow(new BadRequestException("failure"));
    when(environmentResourceService.createAndSetNetwork(any(), any(), any(), any(), any())).thenReturn(network);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.accept(environmentDtoEvent));
    ArgumentCaptor<Event<EnvCreationFailureEvent>> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(any(Object.class), eventCaptor.capture());
    Event<EnvCreationFailureEvent> value = eventCaptor.getValue();
    assertTrue(value.getData().getException() instanceof BadRequestException);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(javax.ws.rs.BadRequestException) Event(reactor.bus.Event) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) NetworkTest(com.sequenceiq.environment.environment.service.network.NetworkTest) Test(org.junit.jupiter.api.Test)

Example 5 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork in project cloudbreak by hortonworks.

the class EnvironmentInitHandlerTest method getEnvironment.

private Environment getEnvironment() {
    Environment environment = new Environment();
    environment.setId(ENV_ID);
    environment.setResourceCrn(CRN);
    environment.setCreator(CREATOR);
    Region region = new Region();
    region.setName(REGION);
    environment.setRegions(Set.of(region));
    environment.setLocationDisplayName(LOCATION_DISPLAY_NAME);
    environment.setLocation(LOCATION);
    environment.setAccountId(ACCOUNT_ID);
    BaseNetwork baseNetwork = new AwsNetwork();
    baseNetwork.setRegistrationType(RegistrationType.EXISTING);
    environment.setNetwork(baseNetwork);
    environment.setCloudPlatform(CloudPlatform.AWS.name());
    environment.setCredential(new Credential());
    return environment;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) Region(com.sequenceiq.environment.environment.domain.Region)

Aggregations

AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)22 Test (org.junit.jupiter.api.Test)15 Environment (com.sequenceiq.environment.environment.domain.Environment)12 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)9 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)8 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)5 Network (com.sequenceiq.cloudbreak.cloud.model.Network)4 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)4 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Credential (com.sequenceiq.environment.credential.domain.Credential)3 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)3 NetworkTest (com.sequenceiq.environment.environment.service.network.NetworkTest)3 CreatedSubnet (com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet)2 Region (com.sequenceiq.environment.environment.domain.Region)2 GcpNetwork (com.sequenceiq.environment.network.dao.domain.GcpNetwork)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)1 NetworkCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest)1