Search in sources :

Example 61 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentCreationServiceTest method testEncryptionKeyUrlValidationError.

@Test
void testEncryptionKeyUrlValidationError() {
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("AZURE").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).withParameters(ParametersDto.builder().withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummy-key-url").build()).build()).build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("AZURE");
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    validationResultBuilder.error("error");
    when(validatorService.validateEncryptionKeyUrl(any(), any())).thenReturn(validationResultBuilder.build());
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(credential);
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(entitlementService.azureEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    when(environmentService.save(any())).thenReturn(environment);
    assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentCreationServiceTest method testEncryptionKeyArnValidationError.

@Test
void testEncryptionKeyArnValidationError() {
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("AWS").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummy-key-arn").build()).build()).build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("AWS");
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    validationResultBuilder.error("error");
    when(validatorService.validateEncryptionKeyArn(any(), any())).thenReturn(validationResultBuilder.build());
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(credential);
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(environmentService.save(any())).thenReturn(environment);
    assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentCreationServiceTest method testCreateForCcmV2TunnelInitialization.

// CHECKSTYLE:ON
// @formatter:on
@ParameterizedTest(name = "Tunnel = {0}, Override = {1}, CCMv2Entitled = {2}, CMv2JumpgateEntitled = {3}, Valid = {4}")
@MethodSource("tunnelingScenarios")
void testCreateForCcmV2TunnelInitialization(Tunnel tunnel, boolean override, boolean ccmV2Entitled, boolean ccmv2JumpgateEntitled, boolean valid, Tunnel expectedTunnel, Class<? extends Throwable> expectedThrowable, String errorMessage) {
    EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).build();
    Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    environment.setExperimentalFeaturesJson(ExperimentalFeatures.builder().withTunnel(tunnel).withOverrideTunnel(override).build());
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(new Credential());
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(environmentService.getRegionsByEnvironment(any())).thenReturn(getCloudRegions());
    when(environmentService.save(any(Environment.class))).thenReturn(environment);
    when(entitlementService.ccmV2Enabled(ACCOUNT_ID)).thenReturn(ccmV2Entitled);
    when(entitlementService.ccmV2JumpgateEnabled(ACCOUNT_ID)).thenReturn(ccmv2JumpgateEntitled);
    if (valid) {
        environmentCreationServiceUnderTest.create(environmentCreationDto);
        ArgumentCaptor<Environment> captor = ArgumentCaptor.forClass(Environment.class);
        verify(environmentService).save(captor.capture());
        Environment capturedEnvironment = captor.getValue();
        assertEquals(expectedTunnel, capturedEnvironment.getExperimentalFeaturesJson().getTunnel(), "Tunnel should be " + expectedTunnel);
    } else {
        assertThatThrownBy(() -> environmentCreationServiceUnderTest.create(environmentCreationDto)).isInstanceOf(expectedThrowable).hasMessage(errorMessage);
        verify(environmentService, never()).save(any());
        verify(environmentResourceService, never()).createAndSetNetwork(any(), any(), any(), any(), any());
        verify(reactorFlowManager, never()).triggerCreationFlow(anyLong(), eq(ENVIRONMENT_NAME), eq(USER), anyString());
    }
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 64 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentCreationServiceTest method testCreationVerificationError.

@Test
void testCreationVerificationError() {
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("dynamo").build()).build();
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).withCreator(CRN).withAccountId(ACCOUNT_ID).withParameters(parametersDto).withLocation(LocationDto.builder().withName("test").withDisplayName("test").withLatitude(0.1).withLongitude(0.1).build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("platform");
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    validationResultBuilder.error("error");
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(validationResultBuilder);
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), eq(ACCOUNT_ID))).thenReturn(credential);
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(environmentService.getRegionsByEnvironment(eq(environment))).thenReturn(getCloudRegions());
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(validationResult.merge(any())).thenReturn(ValidationResult.builder().error("nogood"));
    when(environmentService.save(any())).thenReturn(environment);
    assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
    verify(validatorService, Mockito.times(1)).validatePublicKey(any());
    verify(environmentService, never()).save(any());
    verify(environmentResourceService, never()).createAndSetNetwork(any(), any(), any(), any(), any());
    verify(reactorFlowManager, never()).triggerCreationFlow(anyLong(), eq(ENVIRONMENT_NAME), eq(USER), anyString());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentCreationServiceTest method testCreateWithParentEnvironment.

@Test
void testCreateWithParentEnvironment() {
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("dynamo").build()).build();
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).withParameters(parametersDto).withCrn("aCrn").withLocation(LocationDto.builder().withName("test").withDisplayName("test").withLatitude(0.1).withLongitude(0.1).build()).withParentEnvironmentName("parentCrn").build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    final Environment parentEnvironment = new Environment();
    parentEnvironment.setName(ENVIRONMENT_NAME);
    parentEnvironment.setId(2L);
    parentEnvironment.setAccountId(ACCOUNT_ID);
    String parentEnvironmentResourceCrn = "ParentEnvironmentResourceCrn";
    parentEnvironment.setResourceCrn(parentEnvironmentResourceCrn);
    Credential credential = new Credential();
    credential.setCloudPlatform("platform");
    ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(any(), eq(ACCOUNT_ID))).thenReturn(Optional.of(parentEnvironment));
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), eq(ACCOUNT_ID))).thenReturn(credential);
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(environmentService.getRegionsByEnvironment(eq(environment))).thenReturn(getCloudRegions());
    when(environmentService.save(environmentArgumentCaptor.capture())).thenReturn(environment);
    environmentCreationServiceUnderTest.create(environmentCreationDto);
    verify(validatorService, Mockito.times(1)).validatePublicKey(any());
    verify(environmentService).save(any());
    verify(parametersService).saveParameters(eq(environment), eq(parametersDto));
    verify(environmentResourceService).createAndSetNetwork(any(), any(), any(), any(), any());
    verify(reactorFlowManager).triggerCreationFlow(anyLong(), eq(ENVIRONMENT_NAME), eq(CRN), anyString());
    assertEquals(environmentArgumentCaptor.getValue().getParentEnvironment(), parentEnvironment);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Environment (com.sequenceiq.environment.environment.domain.Environment)187 Test (org.junit.jupiter.api.Test)145 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)48 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)42 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)29 Credential (com.sequenceiq.environment.credential.domain.Credential)26 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)21 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)16 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)15 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)14 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)13 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)12 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)11 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)11 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)11 Headers (reactor.bus.Event.Headers)11 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)10 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)10