use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.
the class ProjectImportServiceImplTest method importProjectInSubdirectory.
@Test
public void importProjectInSubdirectory() {
final OrganizationalUnit organizationalUnit = new OrganizationalUnitImpl("myteam", "org.whatever");
organizationalUnit.getRepositories();
final String exampleURI = "default://main@system/repo/example";
final Path exampleRoot = PathFactory.newPath("example", exampleURI);
final JGitFileSystem fs = mock(JGitFileSystem.class);
final FileSystemProvider provider = mock(FileSystemProvider.class);
when(fs.provider()).thenReturn(provider);
final org.uberfire.java.nio.file.Path exampleRootNioPath = JGitPathImpl.create(fs, "/example", "main@system/repo", true);
final org.uberfire.java.nio.file.Path repoRoot = exampleRootNioPath.getParent();
when(fs.getRootDirectories()).thenReturn(() -> Stream.of(repoRoot).iterator());
when(pathUtil.stripProtocolAndBranch(any())).then(inv -> realPathUtil.stripProtocolAndBranch(inv.getArgument(0, String.class)));
when(pathUtil.stripRepoNameAndSpace(any())).then(inv -> realPathUtil.stripRepoNameAndSpace(inv.getArgument(0, String.class)));
when(pathUtil.convert(Mockito.<org.uberfire.java.nio.file.Path>any())).then(inv -> realPathUtil.convert(inv.getArgument(0, org.uberfire.java.nio.file.Path.class)));
when(pathUtil.extractBranch(any())).then(inv -> realPathUtil.extractBranch(inv.getArgument(0, String.class)));
String repoURL = "file:///some/repo/url";
final ImportProject importProject = new ImportProject(exampleRoot, "example", "description", repoURL, emptyList());
when(service.getProjectRoot(importProject)).thenReturn(exampleRootNioPath);
when(pathUtil.getNiogitRepoPath(any())).thenReturn(repoURL);
final Repository repository = new GitRepository("example", new Space("myteam"));
final WorkspaceProject project = new WorkspaceProject(organizationalUnit, repository, new Branch("main", mock(Path.class)), new Module());
when(projectService.resolveProject(repository)).thenReturn(project);
doReturn(repository).when(repoService).createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), any(), any());
final WorkspaceProject importedProject = service.importProject(organizationalUnit, importProject);
assertSame(project, importedProject);
final ArgumentCaptor<RepositoryEnvironmentConfigurations> configsCaptor = ArgumentCaptor.forClass(RepositoryEnvironmentConfigurations.class);
verify(repoService).createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), any(), configsCaptor.capture());
final RepositoryEnvironmentConfigurations configs = configsCaptor.getValue();
assertEquals(repoURL, configs.getOrigin());
assertEquals("example", configs.getSubdirectory());
verify(projectService).resolveProject(repository);
}
use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.
the class ExamplesServiceImplTest method testGetProjects_PomDescription.
@Test
public void testGetProjects_PomDescription() {
final Path moduleRoot = mock(Path.class);
final POM pom = mock(POM.class);
final KieModule module = mock(KieModule.class);
when(pom.getDescription()).thenReturn("pom description");
when(module.getRootPath()).thenReturn(moduleRoot);
when(module.getModuleName()).thenReturn("module1");
when(module.getPom()).thenReturn(pom);
when(moduleRoot.toURI()).thenReturn("default:///module1");
when(metadataService.getTags(Mockito.<Path>any())).thenReturn(Arrays.asList("tag1", "tag2"));
final GitRepository repository = makeGitRepository();
when(repositoryFactory.newRepository(Mockito.<RepositoryInfo>any())).thenReturn(repository);
when(moduleService.getAllModules(Mockito.<Branch>any())).thenReturn(new HashSet<Module>() {
{
add(module);
}
});
String origin = "https://github.com/guvnorngtestuser1/guvnorng-playground.git";
final Set<ImportProject> modules = service.getProjects(ou, new ExampleRepository(origin));
assertNotNull(modules);
assertEquals(1, modules.size());
assertTrue(modules.contains(new ImportProject(moduleRoot, "module1", "pom description", origin, Arrays.asList("tag1", "tag2"), null, Collections.emptyList(), false)));
}
use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.
the class ExamplesServiceImplTest method testSetupExamples_ProjectCopy.
@Test
public void testSetupExamples_ProjectCopy() {
final ExampleOrganizationalUnit exOU = mock(ExampleOrganizationalUnit.class);
final ImportProject exProject1 = mock(ImportProject.class);
doReturn("project 1").when(exProject1).getName();
final ImportProject exProject2 = mock(ImportProject.class);
doReturn("project 2").when(exProject1).getName();
final List<ImportProject> exProjects = Arrays.asList(exProject1, exProject2);
final GitRepository repository1 = mock(GitRepository.class);
final Path repositoryRoot = mock(Path.class);
final Path module1Root = mock(Path.class);
final Path module2Root = mock(Path.class);
when(exOU.getName()).thenReturn("ou");
when(exProject1.getName()).thenReturn("module1");
when(exProject1.getRoot()).thenReturn(module1Root);
when(exProject2.getName()).thenReturn("module2");
when(exProject2.getRoot()).thenReturn(module2Root);
when(repository1.getBranch("dev_branch")).thenReturn(Optional.of(new Branch("dev_branch", repositoryRoot)));
final Optional<Branch> main = Optional.of(new Branch("main", PathFactory.newPath("testFile", "file:///")));
when(repository1.getDefaultBranch()).thenReturn(main);
when(repositoryRoot.toURI()).thenReturn("default:///");
when(module1Root.toURI()).thenReturn("default:///module1");
when(module2Root.toURI()).thenReturn("default:///module2");
when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
final WorkspaceProject project = spy(new WorkspaceProject());
doReturn(project).when(service).importProject(eq(ou), eq(exProject1));
doReturn(project).when(service).importProject(eq(ou), eq(exProject2));
doReturn("project").when(project).getName();
doReturn(project).when(projectService).resolveProject(repository1);
final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exProjects);
assertNull(event.getWorkspaceProject());
assertEquals(ou, event.getOrganizationalUnit());
verify(ouService, never()).createOrganizationalUnit(eq("ou"), eq(""));
verify(service, times(2)).importProject(eq(ou), Mockito.<ImportProject>any());
verify(newProjectEvent, times(2)).fire(Mockito.<NewProjectEvent>any());
}
use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.
the class ExamplesServiceImplTest method testSetupExamples_NewOrganizationalUnitNewRepository.
@Test
public void testSetupExamples_NewOrganizationalUnitNewRepository() {
final ExampleOrganizationalUnit exOU = mock(ExampleOrganizationalUnit.class);
final ImportProject exModule = mock(ImportProject.class);
doReturn("module").when(exModule).getName();
final List<ImportProject> exModules = Collections.singletonList(exModule);
final GitRepository repository = mock(GitRepository.class);
final Path repositoryRoot = mock(Path.class);
final Path moduleRoot = mock(Path.class);
when(exOU.getName()).thenReturn("ou");
when(exModule.getName()).thenReturn("module");
when(exModule.getRoot()).thenReturn(moduleRoot);
when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("main", repositoryRoot)));
when(repositoryRoot.toURI()).thenReturn("default:///");
when(moduleRoot.toURI()).thenReturn("default:///module");
when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(null);
when(ouService.createOrganizationalUnit(eq("ou"), eq(""))).thenReturn(ou);
final WorkspaceProject project = spy(new WorkspaceProject());
doReturn(project).when(service).importProject(eq(ou), eq(exModule));
doReturn("project").when(project).getName();
doReturn(project).when(projectService).resolveProject(repository);
final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exModules);
assertNull(event.getOrganizationalUnit());
assertEquals(project, event.getWorkspaceProject());
verify(ouService, times(1)).createOrganizationalUnit(eq("ou"), eq(""));
verify(service, times(1)).importProject(eq(ou), eq(exModule));
verify(newProjectEvent, times(1)).fire(Mockito.<NewProjectEvent>any());
}
use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.
the class BaseProjectImportService method getProjects.
@Override
public Set<ImportProject> getProjects(final OrganizationalUnit target, final ExampleRepository repository) {
if (repository == null) {
return Collections.emptySet();
}
final String repositoryURL = repository.getUrl();
if (repositoryURL == null || repositoryURL.trim().isEmpty()) {
return Collections.emptySet();
}
Repository gitRepository = resolveGitRepository(repository);
if (gitRepository == null) {
return Collections.emptySet();
}
if (gitRepository.getBranches().isEmpty()) {
throw new EmptyRemoteRepositoryException(getRepositoryAlias(repositoryURL));
}
Set<ImportProject> importProjects = convert(gitRepository.getBranch("master").get(), repository);
return validateProjects(target, importProjects);
}
Aggregations