OrganizationalUnitFactoryImpl implements OrganizationalUnitFactory { @Override public OrganizationalUnit newOrganizationalUnit(final SpaceInfo spaceInfo) { OrganizationalUnitImpl organizationalUnit = new OrganizationalUnitImpl(spaceInfo.getName(), spaceInfo.getDefaultGroupId()); organizationalUnit.setDescription(spaceInfo.getDescription()); final List<RepositoryInfo> repositories = spaceInfo.getRepositories(); if (repositories != null) { for (RepositoryInfo alias : repositories) { Space space = spacesAPI.getSpace(organizationalUnit.getName()); final Repository repo = repositoryService.getRepositoryFromSpace(space, alias.getName()); if (repo != null) { organizationalUnit.getRepositories().add(repo); } } } final List<String> securityGroups = spaceInfo.getSecurityGroups(); if (securityGroups != null) { organizationalUnit.getGroups().addAll(securityGroups); } final Collection<Contributor> contributors = spaceInfo.getContributors(); if (contributors != null) { organizationalUnit.getContributors().addAll(contributors); } return organizationalUnit; } @Inject  OrganizationalUnitFactoryImpl(final RepositoryService repositoryService,
                                         final SpacesAPI spacesAPI); @Override OrganizationalUnit newOrganizationalUnit(final SpaceInfo spaceInfo);  }
@Test public void newOrganizationalUnitTest() { final List<Contributor> contributors = Arrays.asList(new Contributor("c1", ContributorType.OWNER), new Contributor("c2", ContributorType.ADMIN)); final SpaceInfo spaceInfo = new SpaceInfo("ou", "test space", "groupId", contributors, Collections.singletonList(new RepositoryInfo("repo1",false,new RepositoryConfiguration())), Collections.singletonList("group1")); final OrganizationalUnit organizationalUnit = factory.newOrganizationalUnit(spaceInfo); assertEquals("ou", organizationalUnit.getName()); assertEquals("groupId", organizationalUnit.getDefaultGroupId()); assertEquals("test space", organizationalUnit.getDescription()); assertEquals(1, organizationalUnit.getRepositories().size()); assertEquals("repo1", ((List<Repository>) organizationalUnit.getRepositories()).get(0).getAlias()); assertEquals(1, organizationalUnit.getGroups().size()); assertEquals("group1", ((List<String>) organizationalUnit.getGroups()).get(0)); assertEquals(2, organizationalUnit.getContributors().size()); assertEquals("c1", ((List<Contributor>) organizationalUnit.getContributors()).get(0).getUsername()); assertEquals(ContributorType.OWNER, ((List<Contributor>) organizationalUnit.getContributors()).get(0).getType()); assertEquals("c2", ((List<Contributor>) organizationalUnit.getContributors()).get(1).getUsername()); assertEquals(ContributorType.ADMIN, ((List<Contributor>) organizationalUnit.getContributors()).get(1).getType()); }