Search in sources :

Example 11 with ImportProject

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);
}
Also used : Path(org.uberfire.backend.vfs.Path) Space(org.uberfire.spaces.Space) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Mockito.anyString(org.mockito.Mockito.anyString) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) FileSystemProvider(org.uberfire.java.nio.file.spi.FileSystemProvider) Branch(org.guvnor.structure.repositories.Branch) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) Test(org.junit.Test)

Example 12 with ImportProject

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)));
}
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) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 13 with ImportProject

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());
}
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) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) Test(org.junit.Test)

Example 14 with ImportProject

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());
}
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) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) Test(org.junit.Test)

Example 15 with ImportProject

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);
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) EmptyRemoteRepositoryException(org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException)

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