RepositoryServiceImpl implements RepositoryService { protected String createFreshRepositoryAlias(final String alias, final Space space) { int index = 0; String suffix = ""; while (configuredRepositories.getRepositoryByRepositoryAlias(space, alias + suffix, true) != null) { suffix = "-" + ++index; } return alias + suffix; } 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 testNotCreateNewAliasIfNecessary() { when(configuredRepositories.getRepositoryByRepositoryAlias(any(), eq("other-name"))).thenReturn(repository); doReturn(Optional.of(mock(Branch.class))).when(repository).getDefaultBranch(); doReturn("alias").when(repository).getAlias(); String newAlias = repositoryService.createFreshRepositoryAlias("alias", new Space("alias")); assertEquals("alias", newAlias); }
@Test public void testCreateNewAliasIfNecessary() { when(configuredRepositories.getRepositoryByRepositoryAlias(any(), eq("alias"), eq(true))).thenReturn(repository); doReturn(Optional.of(mock(Branch.class))).when(repository).getDefaultBranch(); doReturn("alias").when(repository).getAlias(); String newAlias = repositoryService.createFreshRepositoryAlias("alias", new Space("alias")); assertEquals("alias-1", newAlias); }
@Test public void testCreateSecondNewAliasIfNecessary() { when(configuredRepositories.getRepositoryByRepositoryAlias(any(), eq("alias"), eq(true))).thenReturn(repository); when(configuredRepositories.getRepositoryByRepositoryAlias(any(), eq("alias-1"), eq(true))).thenReturn(repository); doReturn(Optional.of(mock(Branch.class))).when(repository).getDefaultBranch(); doReturn("alias").when(repository).getAlias(); String newAlias = repositoryService.createFreshRepositoryAlias("alias", new Space("alias")); assertEquals("alias-2", newAlias); }