@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(grpcUmsClient).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(grpcUmsClient, times(2)).notifyResourceDeleted(any(), any()); }
public Set<Credential> deleteMultiple(Set<String> names, String accountId, CredentialType type) { Set<Credential> deletedOnes = new LinkedHashSet<>(); names.forEach(credentialName -> { try { deletedOnes.add(deleteByName(credentialName, accountId, type)); } catch (Exception ex) { LOGGER.debug("Could not delete Credential with name {} because: {}", credentialName, ex.getMessage()); } }); return deletedOnes; }
CredentialDeleteService extends AbstractCredentialService { public Set<Credential> deleteMultiple(Set<String> names, String accountId, CredentialType type) { Set<Credential> deletedOnes = new LinkedHashSet<>(); names.forEach(credentialName -> { try { deletedOnes.add(deleteByName(credentialName, accountId, type)); } catch (Exception ex) { LOGGER.debug("Could not delete Credential with name {} because: {}", credentialName, ex.getMessage()); } }); return deletedOnes; } }
CredentialDeleteService extends AbstractCredentialService { public Set<Credential> deleteMultiple(Set<String> names, String accountId, CredentialType type) { Set<Credential> deletedOnes = new LinkedHashSet<>(); names.forEach(credentialName -> { try { deletedOnes.add(deleteByName(credentialName, accountId, type)); } catch (Exception ex) { LOGGER.debug("Could not delete Credential with name {} because: {}", credentialName, ex.getMessage()); } }); return deletedOnes; } CredentialDeleteService(CredentialService credentialService,
            NotificationSender notificationSender,
            CloudbreakMessagesService messagesService,
            EnvironmentViewService environmentViewService,
            GrpcUmsClient grpcUmsClient,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); }
CredentialDeleteService extends AbstractCredentialService { public Set<Credential> deleteMultiple(Set<String> names, String accountId, CredentialType type) { Set<Credential> deletedOnes = new LinkedHashSet<>(); names.forEach(credentialName -> { try { deletedOnes.add(deleteByName(credentialName, accountId, type)); } catch (Exception ex) { LOGGER.debug("Could not delete Credential with name {} because: {}", credentialName, ex.getMessage()); } }); return deletedOnes; } CredentialDeleteService(CredentialService credentialService,
            NotificationSender notificationSender,
            CloudbreakMessagesService messagesService,
            EnvironmentViewService environmentViewService,
            GrpcUmsClient grpcUmsClient,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); Set<Credential> deleteMultiple(Set<String> names, String accountId, CredentialType type); Credential deleteByName(String name, String accountId, CredentialType type); Credential deleteByCrn(String crn, String accountId, CredentialType type); }
CredentialDeleteService extends AbstractCredentialService { public Set<Credential> deleteMultiple(Set<String> names, String accountId, CredentialType type) { Set<Credential> deletedOnes = new LinkedHashSet<>(); names.forEach(credentialName -> { try { deletedOnes.add(deleteByName(credentialName, accountId, type)); } catch (Exception ex) { LOGGER.debug("Could not delete Credential with name {} because: {}", credentialName, ex.getMessage()); } }); return deletedOnes; } CredentialDeleteService(CredentialService credentialService,
            NotificationSender notificationSender,
            CloudbreakMessagesService messagesService,
            EnvironmentViewService environmentViewService,
            GrpcUmsClient grpcUmsClient,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); Set<Credential> deleteMultiple(Set<String> names, String accountId, CredentialType type); Credential deleteByName(String name, String accountId, CredentialType type); Credential deleteByCrn(String crn, String accountId, CredentialType type);  }