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());
}
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;
}
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());
}
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);
}
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;
}
Aggregations