use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit in project kie-wb-common by kiegroup.
the class ExamplesServiceImpl method setupExamples.
@Override
public WorkspaceProjectContextChangeEvent setupExamples(final ExampleOrganizationalUnit exampleTargetOU, final List<ExampleProject> exampleProjects) {
PortablePreconditions.checkNotNull("exampleTargetOU", exampleTargetOU);
PortablePreconditions.checkNotNull("exampleProjects", exampleProjects);
PortablePreconditions.checkCondition("Must have at least one ExampleProject", exampleProjects.size() > 0);
// Retrieve or create Organizational Unit
final String targetOUName = exampleTargetOU.getName();
final OrganizationalUnit targetOU = getOrganizationalUnit(targetOUName);
WorkspaceProject firstExampleProject = null;
for (final ExampleProject exampleProject : exampleProjects) {
try {
final Repository targetRepository = repositoryCopier.copy(targetOU, exampleProject.getName(), exampleProject.getRoot());
// Signal creation of new Project (Creation of OU and Repository, if applicable,
// are already handled in the corresponding services).
WorkspaceProject project = projectService.resolveProject(targetRepository);
project = renameIfNecessary(targetOU, project);
newProjectEvent.fire(new NewProjectEvent(project));
// Store first new example project
if (firstExampleProject == null) {
firstExampleProject = project;
}
} catch (IOException ioe) {
logger.error("Unable to create Example(s).", ioe);
}
}
return new WorkspaceProjectContextChangeEvent(firstExampleProject, firstExampleProject.getMainModule());
}
use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit in project kie-wb-common by kiegroup.
the class ExamplesWizardTest method testSetDefaultTargetOrganizationalUnit.
@Test
public void testSetDefaultTargetOrganizationalUnit() {
wizard.setDefaultTargetOrganizationalUnit("testOU");
ExampleOrganizationalUnit targetOrganizationalUnit = wizard.getModel().getTargetOrganizationalUnit();
assertNotNull(targetOrganizationalUnit);
assertEquals("testOU", targetOrganizationalUnit.getName());
}
use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit in project kie-wb-common by kiegroup.
the class LibraryServiceImpl method importProject.
@Override
public WorkspaceProject importProject(final OrganizationalUnit organizationalUnit, final ExampleProject exampleProject) {
final ExampleOrganizationalUnit exampleOrganizationalUnit = new ExampleOrganizationalUnit(organizationalUnit.getName());
final List<ExampleProject> exampleProjects = Collections.singletonList(exampleProject);
final WorkspaceProjectContextChangeEvent projectContextChangeEvent = examplesService.setupExamples(exampleOrganizationalUnit, exampleProjects);
return projectContextChangeEvent.getWorkspaceProject();
}
use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit in project kie-wb-common by kiegroup.
the class LibraryServiceImplTest method importDefaultProjectTest.
@Test
public void importDefaultProjectTest() {
final Repository repository = mock(Repository.class);
when(repository.getAlias()).thenReturn("example");
final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
when(organizationalUnit.getName()).thenReturn("ou");
when(organizationalUnit.getIdentifier()).thenReturn("ou");
when(organizationalUnit.getRepositories()).thenReturn(singletonList(repository));
when(ouService.getOrganizationalUnits()).thenReturn(singletonList(organizationalUnit));
final ExampleProject exampleProject = mock(ExampleProject.class);
doReturn("example").when(exampleProject).getName();
final WorkspaceProject project = mock(WorkspaceProject.class);
final Module module = mock(Module.class);
doReturn(module).when(project).getMainModule();
final WorkspaceProjectContextChangeEvent projectContextChangeEvent = mock(WorkspaceProjectContextChangeEvent.class);
doReturn(project).when(projectContextChangeEvent).getWorkspaceProject();
doReturn(projectContextChangeEvent).when(examplesService).setupExamples(any(ExampleOrganizationalUnit.class), anyList());
final WorkspaceProject importedProject = libraryService.importProject(organizationalUnit, exampleProject);
assertEquals(module, importedProject.getMainModule());
verify(examplesService).setupExamples(new ExampleOrganizationalUnit(organizationalUnit.getName()), singletonList(exampleProject));
}
use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit 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());
}
Aggregations