Search in sources :

Example 36 with Environment

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

the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenHasPublicKeyAndPublicKeyIdAsWell.

@Test
void testValidateAuthenticationModificationWhenHasPublicKeyAndPublicKeyIdAsWell() {
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().withPublicKeyId("pub-key-id").withPublicKey("ssh-key").build()).build();
    PublicKeyConnector connector = mock(PublicKeyConnector.class);
    when(environmentResourceService.isPublicKeyIdExists(environment, "pub-key-id")).thenReturn(true);
    when(environmentResourceService.getPublicKeyConnector(environment.getCloudPlatform())).thenReturn(Optional.of(connector));
    when(publicKeyValidator.validatePublicKey(anyString())).thenReturn(ValidationResult.empty());
    ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
    assertEquals("You should define either publicKey or publicKeyId only, but not both.", validationResult.getFormattedErrors());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with Environment

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

the class EnvironmentValidatorServiceTest method testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyAndKnoxAndDefaultSecGroupAdded.

@Test
void testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyAndKnoxAndDefaultSecGroupAdded() {
    Environment environment = new Environment();
    environment.setCidr("cidr");
    SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withDefaultSecurityGroupId("sec-group").withSecurityGroupIdForKnox("knox-sec-group").build();
    ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment);
    assertFalse(validationResult.hasError());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with Environment

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

the class EnvironmentTestData method newTestEnvironment.

public static Environment newTestEnvironment() {
    Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(TestConstants.ACCOUNT_ID);
    environment.setResourceCrn(TestConstants.CRN);
    environment.setArchived(false);
    environment.setAuthentication(AUTHENTICATION);
    environment.setCidr(CIDR);
    environment.setCloudPlatform(CLOUD_PLATFORM);
    environment.setCreated(1L);
    environment.setCreateFreeIpa(true);
    environment.setCreator(TEST);
    environment.setCredential(CREDENTIAL);
    environment.setDefaultSecurityGroupId(DEFAULT_SG);
    environment.setDescription(DESCRIPTION);
    environment.setLatitude(LATITUDE);
    environment.setLongitude(LONGITUDE);
    environment.setLocation(LOCATION);
    environment.setLocationDisplayName(LOCATION_DISPLAY_NAME);
    environment.setStatus(EnvironmentStatus.AVAILABLE);
    environment.setStatusReason(OK);
    environment.getExperimentalFeaturesJson().setTunnel(Tunnel.DIRECT);
    environment.setSecurityGroupIdForKnox(KNOX_SG);
    environment.setParameters(PARAMETERS);
    environment.setRegions(REGIONS);
    environment.setNetwork(NETWORK);
    return environment;
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment)

Example 39 with Environment

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

the class PemBasedEnvironmentDomainProviderTest method testGenerateShouldThrowServiceExceptionWhenPemReturnsWithThrowExceptionDuringGenerationOfManagedDomainName.

@Test
void testGenerateShouldThrowServiceExceptionWhenPemReturnsWithThrowExceptionDuringGenerationOfManagedDomainName() {
    Environment environment = new Environment();
    String anEnvName = "anEnvName";
    environment.setName(anEnvName);
    when(dnsManagementService.generateManagedDomain(anyString(), eq(anEnvName))).thenThrow(new RuntimeException("ooo something went wrong, no domain generation from our side."));
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> Assertions.assertThrows(EnvironmentServiceException.class, () -> underTest.generate(environment)));
    verify(dnsManagementService, times(1)).generateManagedDomain(anyString(), eq(anEnvName));
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 40 with Environment

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

the class PemBasedEnvironmentDomainProviderTest method testGenerateReturnManagedDomainWhenPemReturnsTheGeneratedManagedDomainName.

@Test
void testGenerateReturnManagedDomainWhenPemReturnsTheGeneratedManagedDomainName() {
    Environment environment = new Environment();
    String anEnvName = "anEnvName";
    environment.setName(anEnvName);
    String expectedDomain = anEnvName + ".mydomain.cldr";
    when(dnsManagementService.generateManagedDomain(anyString(), eq(anEnvName))).thenReturn(expectedDomain);
    String result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.generate(environment));
    Assertions.assertEquals(expectedDomain, result);
    verify(dnsManagementService, times(1)).generateManagedDomain(anyString(), eq(anEnvName));
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

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