@Test void testMultipleWhenEnvironmentStillUsesTheCredential2ThenBadRequestShouldComeOnSecondButTheFirstDeletionSuccess() { doNothing().when(grpcUmsClient).notifyResourceDeleted(any(), any()); String name1 = "something1"; Credential cred1 = createCredentialWithName(name1); cred1.setId(1L); when(credentialService.findByNameAndAccountId(eq(name1), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(cred1)); when(credentialService.save(any())).thenReturn(cred1); String name2 = "something2"; Credential cred2 = createCredentialWithName(name2); cred2.setId(2L); when(credentialService.findByNameAndAccountId(eq(name2), eq(ACCOUNT_ID), any(Set.class), any())) .thenThrow(new BadRequestException("anything can happen")); when(environmentViewService.findAllByCredentialId(cred1.getId())).thenReturn(Set.of()); Set<Credential> result = underTest.deleteMultiple(Set.of(name1, name2), ACCOUNT_ID, ENVIRONMENT); verify(credentialService, times(2)).findByNameAndAccountId(anyString(), anyString(), anyCollection(), any()); verify(environmentViewService, times(1)).findAllByCredentialId(anyLong()); verify(environmentViewService, times(1)).findAllByCredentialId(cred1.getId()); verify(credentialService, times(1)).save(any()); verify(grpcUmsClient, times(1)).notifyResourceDeleted(any(), any()); assertTrue(result.size() == 1); assertTrue(result.iterator().next().getName().startsWith(name1)); }
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);  }