use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class DefExplorerQueryServiceImpl method resolveModules.
/**
* Resolves all the modules accessible by current user in the given branch name.
*/
private Map<String, Module> resolveModules(final Map<String, Repository> repositories, final String branchName) {
final Map<String, Module> authorizedModules = new HashMap<>();
for (final Repository repository : repositories.values()) {
if (containsBranch(repository.getBranches(), branchName)) {
final Module module = projectService.resolveProject(repository).getMainModule();
authorizedModules.put(module.getModuleName(), module);
}
}
return authorizedModules;
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class SocialEventModuleConstraintTest method setUp.
@Before
public void setUp() throws Exception {
Collection<OrganizationalUnit> ous = new ArrayList<OrganizationalUnit>();
final OrganizationalUnitImpl ou = new OrganizationalUnitImpl("ouname", "owner", "groupid");
final OrganizationalUnitImpl ouSpy = spy(ou);
Collection<Repository> repositories = new ArrayList<Repository>();
repository = new GitRepository("repo", new Space("space"));
repositories.add(repository);
ous.add(ouSpy);
when(ouSpy.getRepositories()).thenReturn(repositories);
when(organizationalUnitService.getOrganizationalUnits()).thenReturn(ous);
when(authorizationManager.authorize(ou, user)).thenReturn(true);
when(authorizationManager.authorize(repository, user)).thenReturn(true);
when(userCDIContextHelper.getUser()).thenReturn(user);
when(userCDIContextHelper.thereIsALoggedUserInScope()).thenReturn(true);
socialEventModuleConstraint = createSocialEventModuleConstraint();
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class SocialEventModuleConstraintTest method hasNoRestrictionsTest.
@Test
public void hasNoRestrictionsTest() throws Exception {
final WorkspaceProject project = mock(WorkspaceProject.class);
Repository repository = mock(Repository.class);
doReturn(repository).when(project).getRepository();
when(authorizationManager.authorize(repository, user)).thenReturn(true);
eventProject = project;
final SocialActivitiesEvent vfsEvent = new SocialActivitiesEvent(socialUser, "type", new Date());
final SocialActivitiesEvent moduleEvent = new SocialActivitiesEvent(socialUser, OrganizationalUnitEventType.NEW_ORGANIZATIONAL_UNIT, new Date()).withLink("otherName", "otherName", SocialActivitiesEvent.LINK_TYPE.CUSTOM);
socialEventModuleConstraint.init();
assertFalse(socialEventModuleConstraint.hasRestrictions(vfsEvent));
assertFalse(socialEventModuleConstraint.hasRestrictions(moduleEvent));
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class ModuleSaverTest method runProjecCreationTest.
protected void runProjecCreationTest(final POM pom) throws IOException {
final Repository repository = mock(Repository.class);
final String baseURL = "/";
final File test = File.createTempFile("test", Long.toString(System.nanoTime()));
final Path repositoryRootPath = paths.convert(fs.getPath(test.toURI()));
when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("master", repositoryRootPath)));
when(pomService.load(any(Path.class))).thenReturn(pom);
final ArrayList<String> directories = new ArrayList<String>();
when(resourceResolver.simpleModuleInstance(any(org.uberfire.java.nio.file.Path.class))).thenReturn(mock(KieModule.class));
final KieModule kieModule = new KieModule();
kieModule.setPom(pom);
when(resourceResolver.resolveModule(any(Path.class))).thenReturn(kieModule);
stub(ioService.createDirectory(any(org.uberfire.java.nio.file.Path.class))).toAnswer(new Answer<org.uberfire.java.nio.file.Path>() {
@Override
public org.uberfire.java.nio.file.Path answer(final InvocationOnMock invocationOnMock) throws Throwable {
org.uberfire.java.nio.file.Path path = (org.uberfire.java.nio.file.Path) invocationOnMock.getArguments()[0];
directories.add(path.toString());
return null;
}
});
Module module = saver.save(repositoryRootPath, pom, baseURL);
assertEquals(4, directories.size());
assertTrue(directories.add("src/main/java"));
assertTrue(directories.add("src/main/resources"));
assertTrue(directories.add("src/test/resources"));
assertTrue(directories.add("src/main/java"));
assertEquals(pom, module.getPom());
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class ModuleServiceImplNewModuleTest method testNewModuleCreationClashingGAVForced.
@Test()
public void testNewModuleCreationClashingGAVForced() throws URISyntaxException {
final Repository repository = mock(Repository.class);
final Path masterBranchRoot = mock(Path.class);
doReturn(Optional.of(new Branch("master", masterBranchRoot))).when(repository).getDefaultBranch();
final POM pom = new POM();
final String baseURL = "/";
final KieModule expected = new KieModule();
when(moduleRepositoryResolver.getRepositoriesResolvingArtifact(eq(pom.getGav()))).thenReturn(new HashSet<MavenRepositoryMetadata>() {
{
add(new MavenRepositoryMetadata("id", "url", MavenRepositorySource.SETTINGS));
}
});
when(saver.save(masterBranchRoot, pom, baseURL)).thenReturn(expected);
try {
moduleService.newModule(masterBranchRoot, pom, baseURL, DeploymentMode.FORCED);
} catch (GAVAlreadyExistsException e) {
fail("Unexpected exception thrown: " + e.getMessage());
}
}
Aggregations