Search in sources :

Example 76 with Credential

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

the class CredentialValidatorTest method testValidateCredentialUpdate.

@Test
void testValidateCredentialUpdate() {
    Credential original = new Credential();
    original.setCloudPlatform(CloudPlatform.AWS.name());
    Credential newCred = new Credential();
    newCred.setCloudPlatform(CloudPlatform.AWS.name());
    ValidationResult result = underTest.validateCredentialUpdate(original, newCred, ENVIRONMENT);
    assertFalse(result.hasError());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 77 with Credential

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

the class CredentialDeleteServiceTest method testMultipleIfAllTheCredentialsAreExistsAndAbleToArchiveThenExpectedCredentialsAreComingBack.

@Test
void testMultipleIfAllTheCredentialsAreExistsAndAbleToArchiveThenExpectedCredentialsAreComingBack() {
    String firstCredentialName = "first";
    String secondCredentialName = "second";
    Credential firstCred = createCredentialWithName(firstCredentialName);
    Credential secondCred = createCredentialWithName(secondCredentialName);
    Set<String> names = Set.of(firstCredentialName, secondCredentialName);
    when(credentialService.findByNameAndAccountId(eq(firstCredentialName), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(firstCred));
    when(credentialService.findByNameAndAccountId(eq(secondCredentialName), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(secondCred));
    when(credentialService.save(firstCred)).thenReturn(firstCred);
    when(credentialService.save(secondCred)).thenReturn(secondCred);
    doNothing().when(ownerAssignmentService).notifyResourceDeleted(any(), any());
    Set<Credential> result = underTest.deleteMultiple(names, ACCOUNT_ID, ENVIRONMENT);
    assertNotNull(result);
    assertEquals(2L, result.size());
    assertTrue(result.stream().anyMatch(credential -> credential.getName().startsWith(firstCredentialName)));
    assertTrue(result.stream().anyMatch(credential -> credential.getName().startsWith(secondCredentialName)));
    assertTrue(result.stream().allMatch(Credential::isArchived));
    verify(credentialService, times(2)).findByNameAndAccountId(anyString(), anyString(), anyCollection(), any());
    verify(environmentViewService, times(2)).findAllByCredentialId(any());
    verify(credentialService, times(2)).save(any());
    verify(credentialService, times(1)).save(firstCred);
    verify(credentialService, times(1)).save(secondCred);
    verify(ownerAssignmentService, times(2)).notifyResourceDeleted(any(), any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NotificationSender(com.sequenceiq.notification.NotificationSender) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) Client(javax.ws.rs.client.Client) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) MockitoAnnotations(org.mockito.MockitoAnnotations) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ENVIRONMENT(com.sequenceiq.common.model.CredentialType.ENVIRONMENT) BadRequestException(javax.ws.rs.BadRequestException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Notification(com.sequenceiq.notification.Notification) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) List(java.util.List) EnvironmentViewService(com.sequenceiq.environment.environment.service.EnvironmentViewService) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Credential(com.sequenceiq.environment.credential.domain.Credential) Set(java.util.Set) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 78 with Credential

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

the class CredentialDeleteServiceTest method testWhenCredentialDeleteIsSuccessfulThenNotificationShouldBeSent.

@Test
void testWhenCredentialDeleteIsSuccessfulThenNotificationShouldBeSent() {
    Credential cred = createCredentialWithName("first");
    when(credentialService.findByNameAndAccountId(eq(cred.getName()), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(cred));
    when(credentialService.save(cred)).thenReturn(cred);
    doNothing().when(ownerAssignmentService).notifyResourceDeleted(any(), any());
    underTest.deleteMultiple(Set.of(cred.getName()), ACCOUNT_ID, ENVIRONMENT);
    notificationSender.send(any(Notification.class), any(List.class), any(Client.class));
    verify(ownerAssignmentService, times(1)).notifyResourceDeleted(any(), any());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Set(java.util.Set) List(java.util.List) Client(javax.ws.rs.client.Client) Notification(com.sequenceiq.notification.Notification) Test(org.junit.jupiter.api.Test)

Example 79 with Credential

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

the class CredentialServiceTest method testUpdateByAccountIdModifyPlatformIsForbiddenAndEnvironmentCredential.

@Test
void testUpdateByAccountIdModifyPlatformIsForbiddenAndEnvironmentCredential() {
    Credential result = new Credential();
    result.setCloudPlatform("anotherplatform");
    when(repository.findByNameAndAccountId(eq(CREDENTIAL_NAME), eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Optional.of(result));
    when(credentialValidator.validateCredentialUpdate(any(), any(), any())).thenThrow(BadRequestException.class);
    assertThrows(BadRequestException.class, () -> credentialServiceUnderTest.updateByAccountId(CREDENTIAL, ACCOUNT_ID, ENVIRONMENT));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 80 with Credential

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

the class CredentialServiceTest method testUpdateByAccountIdAndAuditCredential.

@Test
void testUpdateByAccountIdAndAuditCredential() {
    Credential result = new Credential();
    result.setId(2L);
    result.setResourceCrn("this");
    result.setCloudPlatform(PLATFORM);
    CREDENTIAL.setId(1L);
    CREDENTIAL.setResourceCrn("that");
    CREDENTIAL.setCloudPlatform(PLATFORM);
    when(repository.findByNameAndAccountId(eq(CREDENTIAL_NAME), eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Optional.of(result));
    when(credentialAdapter.verify(any(), anyString())).thenAnswer(i -> new CredentialVerification(i.getArgument(0), true));
    when(repository.save(any())).thenAnswer(i -> i.getArgument(0));
    when(credentialValidator.validateCredentialUpdate(any(Credential.class), any(Credential.class), any(CredentialType.class))).thenReturn(ValidationResult.builder().build());
    Credential testResult = credentialServiceUnderTest.updateByAccountId(CREDENTIAL, ACCOUNT_ID, AUDIT);
    verify(repository).save(CREDENTIAL);
    assertEquals(2L, testResult.getId());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CredentialType(com.sequenceiq.common.model.CredentialType) CredentialVerification(com.sequenceiq.environment.credential.verification.CredentialVerification) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Credential (com.sequenceiq.environment.credential.domain.Credential)102 Test (org.junit.jupiter.api.Test)49 Environment (com.sequenceiq.environment.environment.domain.Environment)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)13 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)10 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)9 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)9 BadRequestException (javax.ws.rs.BadRequestException)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)8 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)8 Set (java.util.Set)8 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)7 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)7 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)7 Map (java.util.Map)7 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)6 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6