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