use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.
the class ExamplesServiceImplTest method testGetProjects_CustomDescription.
@Test
public void testGetProjects_CustomDescription() {
final Path moduleRoot = mock(Path.class);
final KieModule module = mock(KieModule.class);
when(module.getRootPath()).thenReturn(moduleRoot);
when(module.getModuleName()).thenReturn("module1");
when(moduleRoot.toURI()).thenReturn("default:///module1");
when(ioService.exists(Mockito.<org.uberfire.java.nio.file.Path>any())).thenReturn(true);
when(ioService.readAllString(Mockito.<org.uberfire.java.nio.file.Path>any())).thenReturn("This is custom description.\n\n This is a new line.");
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", "This is custom description. This is a new line.", 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 testGetProjects_DefaultDescription.
@Test
public void testGetProjects_DefaultDescription() {
final Path moduleRoot = mock(Path.class);
final KieModule module = mock(KieModule.class);
when(module.getRootPath()).thenReturn(moduleRoot);
when(module.getModuleName()).thenReturn("module1");
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);
}
});
service.setPlaygroundRepository(mock(ExampleRepository.class));
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", "Example 'module1' module", 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 BaseProjectImportService method importProjects.
@Override
public WorkspaceProjectContextChangeEvent importProjects(OrganizationalUnit activeOU, List<ImportProject> projects) {
PortablePreconditions.checkNotNull("activeOU", activeOU);
PortablePreconditions.checkNotNull("projects", projects);
PortablePreconditions.checkCondition("Must have at least one Project", projects.size() > 0);
return spaceConfigStorageRegistry.getBatch(activeOU.getSpace().getName()).run(context -> {
List<WorkspaceProject> importedProjects = projects.stream().map(exampleProject -> {
WorkspaceProject project = this.importProject(activeOU, exampleProject);
newProjectEvent.fire(new NewProjectEvent(project));
return project;
}).collect(Collectors.toList());
if (importedProjects.size() == 1) {
final WorkspaceProject importedProject = importedProjects.get(0);
return new WorkspaceProjectContextChangeEvent(importedProject, importedProject.getMainModule());
} else {
return new WorkspaceProjectContextChangeEvent(activeOU);
}
});
}
use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.
the class ProjectImportServiceImplTest method testImportProjects_ProjectImport.
@Test
public void testImportProjects_ProjectImport() {
final ImportProject exProject1 = mock(ImportProject.class);
final ImportProject exProject2 = mock(ImportProject.class);
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(exProject1.getName()).thenReturn("project1");
when(exProject1.getRoot()).thenReturn(module1Root);
when(exProject2.getName()).thenReturn("project2");
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(organizationalUnit);
WorkspaceProject project1 = mock(WorkspaceProject.class);
when(project1.getName()).thenReturn("project1");
when(project1.getBranch()).thenReturn(main.get());
WorkspaceProject project2 = mock(WorkspaceProject.class);
when(project2.getName()).thenReturn("project2");
when(project2.getBranch()).thenReturn(main.get());
doReturn(project1).when(service).importProject(eq(organizationalUnit), eq(exProject1));
doReturn(project2).when(service).importProject(eq(organizationalUnit), eq(exProject2));
final WorkspaceProject project = spy(new WorkspaceProject());
doReturn("project").when(project).getName();
doReturn(project).when(projectService).resolveProject(repository1);
final WorkspaceProjectContextChangeEvent event = service.importProjects(organizationalUnit, exProjects);
assertEquals(organizationalUnit, event.getOrganizationalUnit());
assertEquals(null, event.getWorkspaceProject());
verify(ouService, never()).createOrganizationalUnit(eq("ou"), eq(""));
verify(service, times(2)).importProject(eq(organizationalUnit), any());
verify(spaceConfigStorage).startBatch();
verify(spaceConfigStorage).endBatch();
}
use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.
the class ProjectImportServiceImplTest 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"));
when(pathUtil.convert(Mockito.<Path>any())).thenCallRealMethod();
final GitRepository repository = makeGitRepository();
when(repositoryFactory.newRepository(Mockito.<RepositoryInfo>any())).thenReturn(repository);
when(moduleService.getAllModules(Mockito.<Branch>any())).thenReturn(new HashSet<Module>() {
{
add(module);
}
});
doReturn(Collections.singletonList("main")).when(service).getBranches(Mockito.<org.uberfire.java.nio.file.Path>any(), Mockito.<Path>any());
String origin = "https://github.com/guvnorngtestuser1/guvnorng-playground.git";
final Set<ImportProject> modules = service.getProjects(organizationalUnit, 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.singletonList("main"), true)));
}
Aggregations