use of com.sequenceiq.common.model.CredentialType.ENVIRONMENT 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());
}
use of com.sequenceiq.common.model.CredentialType.ENVIRONMENT in project cloudbreak by hortonworks.
the class EnvironmentServiceIntegrationTest method setup.
@BeforeEach
public void setup() {
client = new EnvironmentServiceClientBuilder(String.format(SERVICE_ADDRESS, port)).withCertificateValidation(false).withDebug(true).withIgnorePreValidation(true).build().withCrn(TEST_USER_CRN);
credential = new Credential();
credential.setName("credential_test");
credential.setResourceCrn(TEST_RESOURCE_CRN);
credential.setAccountId(TEST_ACCOUNT_ID);
credential.setCloudPlatform("AWS");
credential.setCreator(TEST_USER_CRN);
credential.setDescription("description");
credential.setGovCloud(false);
credential.setArchived(false);
credential.setType(ENVIRONMENT);
credentialRequest = new CredentialRequest();
when(entitlementService.azureEnabled(any())).thenReturn(true);
doNothing().when(grpcUmsClient).assignResourceRole(anyString(), anyString(), anyString(), any(), any());
lenient().when(grpcUmsClient.hasRights(anyString(), anyList(), any(), any())).then(i -> {
List<RightCheck> rightChecks = i.getArgument(1);
return rightChecks.stream().map(r -> Boolean.TRUE).collect(toList());
});
lenient().when(grpcUmsClient.checkAccountRight(anyString(), anyString(), any(), any())).thenReturn(true);
Map<String, Boolean> rightCheckMap = Maps.newHashMap();
rightCheckMap.put(credential.getResourceCrn(), true);
when(umsResourceAuthorizationService.getRightOfUserOnResources(anyString(), any(), anyList())).thenReturn(rightCheckMap);
when(grpcUmsClient.getResourceRoles(any(), any())).thenReturn(Set.of("crn:altus:iam:us-west-1:altus:resourceRole:Owner", "crn:altus:iam:us-west-1:altus:resourceRole:EnvironmentAdmin"));
}
Aggregations