Search in sources :

Example 1 with EnvironmentChangeCredentialDto

use of com.sequenceiq.environment.environment.dto.EnvironmentChangeCredentialDto in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method changeCredentialByEnvironmentCrn.

@Test
void changeCredentialByEnvironmentCrn() {
    String credentialName = "credentialName";
    final Credential value = new Credential();
    EnvironmentChangeCredentialDto environmentChangeDto = EnvironmentChangeCredentialDto.EnvironmentChangeCredentialDtoBuilder.anEnvironmentChangeCredentialDto().withCredentialName(credentialName).build();
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(Optional.of(new Environment()));
    when(credentialService.getByNameForAccountId(eq(credentialName), eq(ACCOUNT_ID), eq(ENVIRONMENT))).thenReturn(value);
    environmentModificationServiceUnderTest.changeCredentialByEnvironmentCrn(ACCOUNT_ID, CRN, environmentChangeDto);
    ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
    verify(environmentService).save(environmentArgumentCaptor.capture());
    assertEquals(value, environmentArgumentCaptor.getValue().getCredential());
}
Also used : EnvironmentChangeCredentialDto(com.sequenceiq.environment.environment.dto.EnvironmentChangeCredentialDto) Credential(com.sequenceiq.environment.credential.domain.Credential) Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with EnvironmentChangeCredentialDto

use of com.sequenceiq.environment.environment.dto.EnvironmentChangeCredentialDto in project cloudbreak by hortonworks.

the class EnvironmentController method changeCredentialByEnvironmentName.

@Override
@CheckPermissionByRequestProperty(path = "credentialName", type = NAME, action = DESCRIBE_CREDENTIAL)
@CheckPermissionByResourceName(action = AuthorizationResourceAction.CHANGE_CREDENTIAL)
public DetailedEnvironmentResponse changeCredentialByEnvironmentName(@ResourceName String environmentName, @RequestObject @Valid EnvironmentChangeCredentialRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    EnvironmentChangeCredentialDto dto = environmentApiConverter.convertEnvironmentChangeCredentialDto(request);
    EnvironmentDto result = environmentModificationService.changeCredentialByEnvironmentName(accountId, environmentName, dto);
    return environmentResponseConverter.dtoToDetailedResponse(result);
}
Also used : EnvironmentChangeCredentialDto(com.sequenceiq.environment.environment.dto.EnvironmentChangeCredentialDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CheckPermissionByRequestProperty(com.sequenceiq.authorization.annotation.CheckPermissionByRequestProperty) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Example 3 with EnvironmentChangeCredentialDto

use of com.sequenceiq.environment.environment.dto.EnvironmentChangeCredentialDto in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method changeCredentialByEnvironmentName.

@Test
void changeCredentialByEnvironmentName() {
    String credentialName = "credentialName";
    final Credential value = new Credential();
    EnvironmentChangeCredentialDto environmentChangeDto = EnvironmentChangeCredentialDto.EnvironmentChangeCredentialDtoBuilder.anEnvironmentChangeCredentialDto().withCredentialName(credentialName).build();
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(new Environment()));
    when(credentialService.getByNameForAccountId(eq(credentialName), eq(ACCOUNT_ID), eq(ENVIRONMENT))).thenReturn(value);
    environmentModificationServiceUnderTest.changeCredentialByEnvironmentName(ACCOUNT_ID, ENVIRONMENT_NAME, environmentChangeDto);
    ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
    verify(environmentService).save(environmentArgumentCaptor.capture());
    assertEquals(value, environmentArgumentCaptor.getValue().getCredential());
}
Also used : EnvironmentChangeCredentialDto(com.sequenceiq.environment.environment.dto.EnvironmentChangeCredentialDto) Credential(com.sequenceiq.environment.credential.domain.Credential) Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

EnvironmentChangeCredentialDto (com.sequenceiq.environment.environment.dto.EnvironmentChangeCredentialDto)3 Credential (com.sequenceiq.environment.credential.domain.Credential)2 Environment (com.sequenceiq.environment.environment.domain.Environment)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 CheckPermissionByRequestProperty (com.sequenceiq.authorization.annotation.CheckPermissionByRequestProperty)1 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1