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