Search in sources :

Example 1 with ExampleProject

use of org.kie.workbench.common.screens.examples.model.ExampleProject in project kie-wb-common by kiegroup.

the class ExampleImportPresenterTest method filterProjectsTest.

@Test
public void filterProjectsTest() {
    Set<ExampleProject> projects = new HashSet<>();
    projects.add(new ExampleProject(mock(Path.class), "p1a", "p1a description", null));
    projects.add(new ExampleProject(mock(Path.class), "p3b", "p3b description", null));
    projects.add(new ExampleProject(mock(Path.class), "p2a", "p2a description", null));
    doReturn(projects).when(libraryService).getExampleProjects();
    Map<String, String> params = new HashMap<>();
    params.put("repositoryUrl", "repoUrl");
    importPresenter.onStartup(new DefaultPlaceRequest(LibraryPlaces.PROJECT_SCREEN, params));
    final List<TileWidget> filteredProjects = importPresenter.filterProjects("a");
    assertEquals(2, filteredProjects.size());
}
Also used : HashMap(java.util.HashMap) TileWidget(org.kie.workbench.common.screens.library.client.widgets.common.TileWidget) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with ExampleProject

use of org.kie.workbench.common.screens.examples.model.ExampleProject 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());
}
Also used : NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) IOException(org.uberfire.java.nio.IOException) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject)

Example 3 with ExampleProject

use of org.kie.workbench.common.screens.examples.model.ExampleProject 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(any(Path.class))).thenReturn(Arrays.asList("tag1", "tag2"));
    final GitRepository repository = makeGitRepository();
    when(repositoryFactory.newRepository(any(ConfigGroup.class))).thenReturn(repository);
    when(moduleService.getAllModules(any(Branch.class))).thenReturn(new HashSet<Module>() {

        {
            add(module);
        }
    });
    final Set<ExampleProject> modules = service.getProjects(new ExampleRepository("https://github.com/guvnorngtestuser1/guvnorng-playground.git"));
    assertNotNull(modules);
    assertEquals(1, modules.size());
    assertTrue(modules.contains(new ExampleProject(moduleRoot, "module1", "pom description", Arrays.asList("tag1", "tag2"))));
}
Also used : Path(org.uberfire.backend.vfs.Path) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) Branch(org.guvnor.structure.repositories.Branch) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 4 with ExampleProject

use of org.kie.workbench.common.screens.examples.model.ExampleProject 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 ExampleProject exModule = mock(ExampleProject.class);
    doReturn("module").when(exModule).getName();
    final List<ExampleProject> exModules = new ArrayList<ExampleProject>() {

        {
            add(exModule);
        }
    };
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    doReturn("ou").when(ou).getName();
    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("master", 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(""), eq(""))).thenReturn(ou);
    when(repositoryCopier.copy(eq(ou), anyString(), eq(moduleRoot))).thenReturn(repository);
    final WorkspaceProject project = spy(new WorkspaceProject());
    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(""), eq(""));
    verify(repositoryCopier, times(1)).copy(eq(ou), anyString(), eq(moduleRoot));
    verify(newProjectEvent, times(1)).fire(any(NewProjectEvent.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) Test(org.junit.Test)

Example 5 with ExampleProject

use of org.kie.workbench.common.screens.examples.model.ExampleProject 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 ExampleProject exProject1 = mock(ExampleProject.class);
    doReturn("project 1").when(exProject1).getName();
    final ExampleProject exProject2 = mock(ExampleProject.class);
    doReturn("project 2").when(exProject1).getName();
    final List<ExampleProject> exProjects = new ArrayList<ExampleProject>() {

        {
            add(exProject1);
            add(exProject2);
        }
    };
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    doReturn("ou").when(ou).getName();
    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> master = Optional.of(new Branch("master", PathFactory.newPath("testFile", "file:///")));
    when(repository1.getDefaultBranch()).thenReturn(master);
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(module1Root.toURI()).thenReturn("default:///module1");
    when(module2Root.toURI()).thenReturn("default:///module2");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
    doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module1Root));
    doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module2Root));
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn("project").when(project).getName();
    doReturn(project).when(projectService).resolveProject(repository1);
    final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exProjects);
    assertNull(event.getOrganizationalUnit());
    assertEquals(project, event.getWorkspaceProject());
    verify(ouService, never()).createOrganizationalUnit(eq("ou"), eq(""), eq(""));
    verify(repositoryCopier, times(2)).copy(eq(ou), anyString(), any(Path.class));
    verify(newProjectEvent, times(2)).fire(any(NewProjectEvent.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) Test(org.junit.Test)

Aggregations

ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)27 Test (org.junit.Test)18 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)14 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)8 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)7 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)6 Module (org.guvnor.common.services.project.model.Module)6 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)6 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)6 Branch (org.guvnor.structure.repositories.Branch)6 Path (org.uberfire.backend.vfs.Path)6 HashSet (java.util.HashSet)5 ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)4 ArrayList (java.util.ArrayList)3 NewProjectEvent (org.guvnor.common.services.project.events.NewProjectEvent)3 KieModule (org.kie.workbench.common.services.shared.project.KieModule)3 WizardPageSelectedEvent (org.uberfire.ext.widgets.core.client.wizards.WizardPageSelectedEvent)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 POM (org.guvnor.common.services.project.model.POM)2