Search in sources :

Example 21 with ImportProject

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)));
}
Also used : Path(org.uberfire.backend.vfs.Path) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 22 with ImportProject

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)));
}
Also used : Path(org.uberfire.backend.vfs.Path) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 23 with ImportProject

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);
        }
    });
}
Also used : RepositoryInfo(org.guvnor.structure.organizationalunit.config.RepositoryInfo) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Paths(org.uberfire.backend.server.util.Paths) POM(org.guvnor.common.services.project.model.POM) FileSystemProvider(org.uberfire.java.nio.file.spi.FileSystemProvider) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) ImportService(org.kie.workbench.common.screens.examples.service.ImportService) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes) Module(org.guvnor.common.services.project.model.Module) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ProjectScreenService(org.kie.workbench.common.screens.projecteditor.service.ProjectScreenService) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) Repository(org.guvnor.structure.repositories.Repository) MetadataService(org.guvnor.common.services.shared.metadata.MetadataService) SpaceConfigStorageRegistry(org.guvnor.structure.organizationalunit.config.SpaceConfigStorageRegistry) Collection(java.util.Collection) Set(java.util.Set) SCHEME(org.guvnor.structure.repositories.EnvironmentParameters.SCHEME) EmptyRemoteRepositoryException(org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException) ExampleProjectError(org.kie.workbench.common.screens.examples.model.ExampleProjectError) Collectors(java.util.stream.Collectors) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) List(java.util.List) Stream(java.util.stream.Stream) RepositoryConfiguration(org.guvnor.structure.organizationalunit.config.RepositoryConfiguration) ImportProjectValidators(org.kie.workbench.common.screens.examples.validation.ImportProjectValidators) PathUtil(org.guvnor.common.services.project.backend.server.utils.PathUtil) Optional(java.util.Optional) HashMap(java.util.HashMap) EnvironmentParameters(org.guvnor.structure.repositories.EnvironmentParameters) MessageFormat(java.text.MessageFormat) ProjectAlreadyExistException(org.kie.workbench.common.screens.examples.exception.ProjectAlreadyExistException) StreamSupport(java.util.stream.StreamSupport) PortablePreconditions(org.kie.soup.commons.validation.PortablePreconditions) Credentials(org.kie.workbench.common.screens.examples.model.Credentials) Path(org.uberfire.backend.vfs.Path) Event(javax.enterprise.event.Event) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) RepositoryService(org.guvnor.structure.repositories.RepositoryService) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) MIRROR(org.guvnor.structure.repositories.EnvironmentParameters.MIRROR) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) Collectors.toList(java.util.stream.Collectors.toList) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) IOService(org.uberfire.io.IOService) ImportProjectValidator(org.kie.workbench.common.screens.examples.validation.ImportProjectValidator) Collections(java.util.Collections) FileSystem(org.uberfire.java.nio.file.FileSystem) Branch(org.guvnor.structure.repositories.Branch) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)

Example 24 with ImportProject

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();
}
Also used : Path(org.uberfire.backend.vfs.Path) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) Test(org.junit.Test)

Example 25 with ImportProject

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)));
}
Also used : Path(org.uberfire.backend.vfs.Path) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Mockito.anyString(org.mockito.Mockito.anyString) POM(org.guvnor.common.services.project.model.POM) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Aggregations

ImportProject (org.kie.workbench.common.screens.examples.model.ImportProject)37 Test (org.junit.Test)30 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)22 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)17 Path (org.uberfire.backend.vfs.Path)17 ImportUtils.makeGitRepository (org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository)14 Module (org.guvnor.common.services.project.model.Module)11 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)11 KieModule (org.kie.workbench.common.services.shared.project.KieModule)10 Mockito.anyString (org.mockito.Mockito.anyString)10 Branch (org.guvnor.structure.repositories.Branch)8 Repository (org.guvnor.structure.repositories.Repository)7 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)7 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)7 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)5 FileSystem (org.uberfire.java.nio.file.FileSystem)5 ArrayList (java.util.ArrayList)4 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)4 POM (org.guvnor.common.services.project.model.POM)4 Credentials (org.kie.workbench.common.screens.examples.model.Credentials)4