Search in sources :

Example 6 with ImportProject

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

the class ProjectImportServiceImplTest method testProjectImportWithNullCredentialsTest.

@Test
public void testProjectImportWithNullCredentialsTest() {
    final ArgumentCaptor<RepositoryEnvironmentConfigurations> captor = ArgumentCaptor.forClass(RepositoryEnvironmentConfigurations.class);
    final String origin = "file:///some/path/to/fake-repo.git";
    final String username = "fakeUser";
    final String password = null;
    final List<String> branches = Arrays.asList("main");
    final ImportProject importProject = mock(ImportProject.class);
    final Path rootPath = mock(Path.class);
    final org.uberfire.java.nio.file.Path convertedRootPath = mock(org.uberfire.java.nio.file.Path.class);
    when(pathUtil.convert(Mockito.<Path>any())).thenReturn(convertedRootPath);
    when(convertedRootPath.getFileSystem()).thenReturn(mock(FileSystem.class));
    when(service.getProjectRoot(rootPath)).thenReturn(convertedRootPath);
    when(importProject.getCredentials()).thenReturn(new Credentials(username, password));
    when(importProject.getRoot()).thenReturn(rootPath);
    when(importProject.getOrigin()).thenReturn(origin);
    when(importProject.getSelectedBranches()).thenReturn(branches);
    when(service.getProjectRoot(importProject)).thenReturn(convertedRootPath);
    service.importProject(organizationalUnit, importProject);
    verify(repoService).createRepository(any(), any(), any(), captor.capture());
    assertFalse(captor.getValue().containsConfiguration(EnvironmentParameters.USER_NAME));
    assertFalse(captor.getValue().containsConfiguration(EnvironmentParameters.PASSWORD));
}
Also used : Path(org.uberfire.backend.vfs.Path) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) FileSystem(org.uberfire.java.nio.file.FileSystem) Mockito.anyString(org.mockito.Mockito.anyString) Credentials(org.kie.workbench.common.screens.examples.model.Credentials) Test(org.junit.Test)

Example 7 with ImportProject

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

the class ProjectImportServiceImplTest method testGetProjects_WhiteSpaceRepositoryUrl.

@Test
public void testGetProjects_WhiteSpaceRepositoryUrl() {
    final Set<ImportProject> modules = service.getProjects(organizationalUnit, new ExampleRepository("   "));
    assertNotNull(modules);
    assertEquals(0, modules.size());
}
Also used : ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Test(org.junit.Test)

Example 8 with ImportProject

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

the class ProjectImportServiceImplTest 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"));
    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", "This is custom description. This is a new line.", origin, Arrays.asList("tag1", "tag2"), null, Collections.singletonList("main"), true)));
}
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) Mockito.anyString(org.mockito.Mockito.anyString) 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 9 with ImportProject

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

the class ProjectImportServiceImplTest method importDefaultProjectTest.

@Test
public void importDefaultProjectTest() {
    final OrganizationalUnit organizationalUnit = new OrganizationalUnitImpl("myteam", "org.whatever");
    organizationalUnit.getRepositories();
    final Path exampleRoot = mock(Path.class);
    org.uberfire.java.nio.file.Path fspath = mock(org.uberfire.java.nio.file.Path.class);
    final JGitFileSystem fileSystem = mock(JGitFileSystem.class);
    doReturn(fileSystem).when(fspath).getFileSystem();
    final org.uberfire.java.nio.file.Path exampleRootNioPath = fspath;
    String repoURL = "file:///some/repo/url";
    final ImportProject importProject = new ImportProject(exampleRoot, "example", "description", repoURL, emptyList());
    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);
    when(repoService.createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), any(), any())).thenReturn(repository);
    when(service.getProjectRoot(importProject)).thenReturn(exampleRootNioPath);
    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());
    assertNull(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) 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 10 with ImportProject

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

the class ProjectImportServiceImplTest method importDefaultProjectInWindowsTest.

@Test
public void importDefaultProjectInWindowsTest() {
    final OrganizationalUnit organizationalUnit = new OrganizationalUnitImpl("myteam", "org.whatever");
    organizationalUnit.getRepositories();
    final Path exampleRoot = mock(Path.class);
    org.uberfire.java.nio.file.Path fspath = mock(org.uberfire.java.nio.file.Path.class);
    final JGitFileSystem fileSystem = mock(JGitFileSystem.class);
    doReturn(fileSystem).when(fspath).getFileSystem();
    final org.uberfire.java.nio.file.Path exampleRootNioPath = fspath;
    String repoURL = "file:///C:/some/repo/url";
    final ImportProject importProject = new ImportProject(exampleRoot, "example", "description", repoURL, emptyList());
    doReturn(emptyList()).when(service).getBranches(Mockito.<org.uberfire.java.nio.file.Path>any(), any());
    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);
    when(repoService.createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), any(), any())).thenReturn(repository);
    when(service.getProjectRoot(importProject)).thenReturn(exampleRootNioPath);
    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());
    assertNull(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) 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)

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