RepositoryServiceImpl implements RepositoryService { @Override public void updateContributors(final Repository repository, final List<Contributor> contributors) { Optional<org.guvnor.structure.organizationalunit.config.RepositoryInfo> thisRepositoryConfig = findRepositoryConfig(repository.getSpace().getName(), repository.getAlias()); if (!thisRepositoryConfig.isPresent()) { throw new IllegalArgumentException("Repository " + repository.getAlias() + " not found"); } thisRepositoryConfig.ifPresent(config -> { config.getConfiguration().add("contributors", contributors); this.saveRepositoryConfig(repository.getSpace().getName(), config); repositoryContributorsUpdatedEvent.fire(new RepositoryContributorsUpdatedEvent(getRepositoryFromSpace(repository.getSpace(), repository.getAlias()))); }); } RepositoryServiceImpl(); @Inject  RepositoryServiceImpl(@Named("ioStrategy") final IOService ioService,
                                 final GitMetadataStore metadataStore,
                                 final ConfigurationService configurationService,
                                 final OrganizationalUnitService organizationalUnitService,
                                 final ConfigurationFactory configurationFactory,
                                 final RepositoryFactory repositoryFactory,
                                 final Event<NewRepositoryEvent> event,
                                 final Event<RepositoryRemovedEvent> repositoryRemovedEvent,
                                 final BackwardCompatibleUtil backward,
                                 final ConfiguredRepositories configuredRepositories,
                                 final AuthorizationManager authorizationManager,
                                 final User user,
                                 final SpacesAPI spacesAPI,
                                 final SpaceConfigStorageRegistry spaceConfigStorage,
                                 final Event<RepositoryContributorsUpdatedEvent> repositoryContributorsUpdatedEvent,
                                 final PasswordService secureService); @Override RepositoryInfo getRepositoryInfo(final Space space,
                                            final String alias); @Override List<VersionRecord> getRepositoryHistory(final Space space,
                                                    final String alias,
                                                    final int startIndex); @Override List<VersionRecord> getRepositoryHistory(final Space space,
                                                    final String alias,
                                                    int startIndex,
                                                    int endIndex); @Override Repository getRepositoryFromSpace(final Space space,
                                             final String alias); @Override Repository getRepository(final Path root); @Override Repository getRepository(final Space space,
                                    final Path root); @Override String normalizeRepositoryName(String name); @Override boolean validateRepositoryName(String name); @Override Collection<Repository> getAllRepositories(final Space space); @Override Collection<Repository> getAllDeletedRepositories(final Space space); @Override Collection<Repository> getAllRepositories(Space space,
                                                     boolean includeDeleted); @Override Collection<Repository> getAllRepositoriesFromAllUserSpaces(); @Override Collection<Repository> getRepositories(final Space space); @Override Repository createRepository(final OrganizationalUnit organizationalUnit,
                                       final String scheme,
                                       final String alias,
                                       final RepositoryEnvironmentConfigurations repositoryEnvironmentConfigurations); @Override Repository createRepository(final OrganizationalUnit organizationalUnit,
                                       final String scheme,
                                       final String alias,
                                       final RepositoryEnvironmentConfigurations repositoryEnvironmentConfigurations,
                                       final Collection<Contributor> contributors); @Override void removeRepository(final Space space,
                                 final String alias); @Override void removeRepositories(final Space space,
                                   final Set<String> aliases); @SuppressWarnings({"unchecked", "rawtypes"}) @Override void addGroup(final Repository repository,
                         final String group); @SuppressWarnings({"unchecked", "rawtypes"}) @Override void removeGroup(Repository repository,
                            String group); @Override void updateContributors(final Repository repository,
                                   final List<Contributor> contributors); @Override List<VersionRecord> getRepositoryHistoryAll(final Space space,
                                                       final String alias);  }
@Test public void updateContributorsTest() { final Space space = new Space("space"); doReturn(space).when(repository).getSpace(); doReturn("alias").when(repository).getAlias(); doReturn(repository).when(configuredRepositories).getRepositoryByRepositoryAlias(any(), any()); final SpaceConfigStorage spaceConfigStorage = mock(SpaceConfigStorage.class); doReturn(new SpaceInfo("space", "Test space", "defaultGroupId", Collections.emptyList(), new ArrayList<>(Arrays.asList(new RepositoryInfo("alias", false, new RepositoryConfiguration()))), Collections.emptyList())).when(spaceConfigStorage).loadSpaceInfo(); doReturn(true) .when(spaceConfigStorage).isInitialized(); when(registry.get(anyString())).thenReturn(spaceConfigStorage); when(registry.getBatch(anyString())).thenReturn(new SpaceConfigStorageRegistryImpl.SpaceStorageBatchImpl(spaceConfigStorage)); String username = "admin1"; repositoryService.updateContributors(repository, Collections.singletonList(new Contributor(username, ContributorType.OWNER))); verify(updatedEvent).fire(captor.capture()); assertEquals("alias", captor.getValue().getRepository().getAlias()); assertEquals("space", captor.getValue().getRepository().getSpace().getName()); verify(repositoryService).saveRepositoryConfig(eq("space"), configCaptor.capture()); assertEquals(username, configCaptor.getValue().getContributors().get(0).getUsername()); assertEquals(ContributorType.OWNER, configCaptor.getValue().getContributors().get(0).getType()); verify(spaceConfigStorage).startBatch(); verify(spaceConfigStorage).saveSpaceInfo(any()); verify(spaceConfigStorage).endBatch(); }