Search in sources :

Example 26 with ImportProject

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

the class ProjectImportServiceImplTest 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"));
    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", "Example 'module1' module", 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 27 with ImportProject

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

the class ProjectImportServiceImplTest method testGetProjects_EmptyRepositoryUrl.

@Test
public void testGetProjects_EmptyRepositoryUrl() {
    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 28 with ImportProject

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

the class ProjectImportServiceImplTest method importProjectWithoutCredentialsTest.

@Test
public void importProjectWithoutCredentialsTest() {
    final Repository repo = mock(Repository.class);
    final WorkspaceProject project = mock(WorkspaceProject.class);
    final String repositoryURL = "file:///some/path/to/fake-repo.git";
    final String username = null;
    final String password = null;
    final List<String> branches = Arrays.asList("main");
    final ArgumentCaptor<RepositoryEnvironmentConfigurations> configCaptor = ArgumentCaptor.forClass(RepositoryEnvironmentConfigurations.class);
    ImportProject importProject = mock(ImportProject.class, Answers.RETURNS_DEEP_STUBS.get());
    when(importProject.getCredentials().getUsername()).thenReturn(username);
    when(importProject.getCredentials().getPassword()).thenReturn(password);
    when(importProject.getOrigin()).thenReturn(repositoryURL);
    when(importProject.getSelectedBranches()).thenReturn(branches);
    org.uberfire.java.nio.file.Path p = mock(org.uberfire.java.nio.file.Path.class);
    when(p.getFileSystem()).thenReturn(mock(FileSystem.class));
    doReturn(p).when(pathUtil).convert(Mockito.<org.uberfire.backend.vfs.Path>any());
    when(service.getProjectRoot(Mockito.<ImportProject>any())).thenReturn(p);
    when(repoService.createRepository(any(), any(), any(), configCaptor.capture())).thenReturn(repo);
    when(projectService.resolveProject(any(Repository.class))).thenReturn(project);
    final WorkspaceProject observedProject = service.importProject(organizationalUnit, importProject);
    verify(repoService).createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), eq("fake-repo"), any());
    RepositoryEnvironmentConfigurations observedConfig = configCaptor.getValue();
    assertEquals(username, observedConfig.getUserName());
    assertEquals(password, observedConfig.getPassword());
    assertEquals(repositoryURL, observedConfig.getOrigin());
    assertEquals(branches, observedConfig.getBranches());
    verify(projectService).resolveProject(same(repo));
    assertSame(project, observedProject);
}
Also used : ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Mockito.anyString(org.mockito.Mockito.anyString) 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) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) FileSystem(org.uberfire.java.nio.file.FileSystem) Test(org.junit.Test)

Example 29 with ImportProject

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

the class ProjectImportServiceImplTest method importProjectWithCredentialsTest.

@Test
public void importProjectWithCredentialsTest() {
    final Repository repo = mock(Repository.class);
    final WorkspaceProject project = mock(WorkspaceProject.class);
    final String repositoryURL = "file:///some/path/to/fake-repo.git";
    final String username = "fakeUser";
    final String password = "fakePassword";
    final List<String> branches = Arrays.asList("main");
    ImportProject importProject = mock(ImportProject.class, Answers.RETURNS_DEEP_STUBS.get());
    when(importProject.getCredentials().getUsername()).thenReturn(username);
    when(importProject.getCredentials().getPassword()).thenReturn(password);
    when(importProject.getOrigin()).thenReturn(repositoryURL);
    when(importProject.getSelectedBranches()).thenReturn(branches);
    org.uberfire.java.nio.file.Path p = mock(org.uberfire.java.nio.file.Path.class);
    when(p.getFileSystem()).thenReturn(mock(FileSystem.class));
    doReturn(p).when(pathUtil).convert(Mockito.<org.uberfire.backend.vfs.Path>any());
    when(service.getProjectRoot(Mockito.<ImportProject>any())).thenReturn(p);
    final ArgumentCaptor<RepositoryEnvironmentConfigurations> configCaptor = ArgumentCaptor.forClass(RepositoryEnvironmentConfigurations.class);
    when(repoService.createRepository(any(), any(), any(), configCaptor.capture())).thenReturn(repo);
    when(projectService.resolveProject(any(Repository.class))).thenReturn(project);
    final WorkspaceProject observedProject = service.importProject(organizationalUnit, importProject);
    verify(repoService).createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), eq("fake-repo"), any());
    RepositoryEnvironmentConfigurations observedConfig = configCaptor.getValue();
    assertEquals(username, observedConfig.getUserName());
    assertEquals(password, observedConfig.getPassword());
    assertEquals(repositoryURL, observedConfig.getOrigin());
    assertEquals(branches, observedConfig.getBranches());
    verify(projectService).resolveProject(same(repo));
    assertSame(project, observedProject);
}
Also used : ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Mockito.anyString(org.mockito.Mockito.anyString) 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) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) FileSystem(org.uberfire.java.nio.file.FileSystem) Test(org.junit.Test)

Example 30 with ImportProject

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

the class ProjectImportServiceImplTest method testProjectImportWithCredentialsTest.

@Test
public void testProjectImportWithCredentialsTest() {
    final String origin = "file:///some/path/to/fake-repo.git";
    final String username = "fakeUser";
    final String password = "fakePassword";
    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(eq(organizationalUnit), any(), any(), configurations.capture());
    assertEquals(username, configurations.getValue().getUserName());
}
Also used : Path(org.uberfire.backend.vfs.Path) 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)

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