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));
}
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());
}
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)));
}
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);
}
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);
}
Aggregations