@Test public void updateProjectAndUserDataTest() { ProviderProjectEntity storedProviderProjectEntity = new ProviderProjectEntity("stored-name", "stored-description", "stored-href", "stored-Email", 2L); ProviderProject providerProject = new ProviderProject(name, description, href, projectOwnerEmail); ProviderProjectEntity providerProjectEntity = new ProviderProjectEntity(name, description, href, projectOwnerEmail, 1L); providerProjectEntity.setId(3L); ProviderUserEntity providerUserEntity = new ProviderUserEntity("test-email", true, 1L); providerUserEntity.setId(4L); Map<ProviderProject, Set<String>> projectToUserData = new HashMap<>(); projectToUserData.put(providerProject, Set.of("test-user-email")); final String additionalRelevantUsers = "additional-test-user-email"; ProviderProjectRepository providerProjectRepository = Mockito.mock(ProviderProjectRepository.class); ProviderUserRepository providerUserRepository = Mockito.mock(ProviderUserRepository.class); ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); ProviderUserProjectRelationRepository providerUserProjectRelationRepository = Mockito.mock(ProviderUserProjectRelationRepository.class); Mockito.when(providerProjectRepository.findByProviderConfigId(Mockito.any())).thenReturn(List.of(storedProviderProjectEntity)); Mockito.when(providerProjectRepository.saveAll(Mockito.any())).thenReturn(List.of(providerProjectEntity)); Mockito.when(providerUserRepository.findByProviderConfigId(Mockito.any())).thenReturn(List.of(providerUserEntity)); Mockito.when(providerUserRepository.save(Mockito.any())).thenReturn(providerUserEntity); Mockito.when(providerProjectRepository.findFirstByHref(Mockito.any())).thenReturn(Optional.of(providerProjectEntity)); Mockito.when(providerUserRepository.findByEmailAddressAndProviderConfigId(Mockito.any(), Mockito.any())).thenReturn(List.of(providerUserEntity)); DefaultProviderDataAccessor providerDataAccessor = new DefaultProviderDataAccessor(providerProjectRepository, providerUserProjectRelationRepository, providerUserRepository, configurationAccessor); providerDataAccessor.updateProjectAndUserData(1L, projectToUserData, Set.of(additionalRelevantUsers)); Mockito.verify(providerProjectRepository).deleteByHref(Mockito.any()); Mockito.verify(providerUserRepository).deleteByProviderConfigIdAndEmailAddress(Mockito.any(), Mockito.any()); Mockito.verify(providerUserProjectRelationRepository).saveAll(Mockito.any()); }
@Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); }
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); } }
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); } @Autowired  DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
        ConfigurationAccessor configurationAccessor); }
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); } @Autowired  DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
        ConfigurationAccessor configurationAccessor); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigId(Long providerConfigId); @Override void deleteProjects(Collection<ProviderProject> providerProjects); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Set<String> getEmailAddressesForProjectHref(String projectHref); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderUserModel> getUsersByProviderConfigId(Long providerConfigId); @Override List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName); @Override void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers); }
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); } @Autowired  DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
        ConfigurationAccessor configurationAccessor); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigId(Long providerConfigId); @Override void deleteProjects(Collection<ProviderProject> providerProjects); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Set<String> getEmailAddressesForProjectHref(String projectHref); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderUserModel> getUsersByProviderConfigId(Long providerConfigId); @Override List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName); @Override void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers); static final int MAX_DESCRIPTION_LENGTH; static final int MAX_PROJECT_NAME_LENGTH; }