use of org.kie.workbench.common.screens.examples.model.Credentials 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());
}
use of org.kie.workbench.common.screens.examples.model.Credentials in project kie-wb-common by kiegroup.
the class ExamplesServiceImpl method resolveGitRepository.
@Override
protected Repository resolveGitRepository(final ExampleRepository exampleRepository) {
return spaceConfigStorageRegistry.getBatch(this.playgroundSpaceName).run(spaceConfigStorageBatchContext -> {
if (exampleRepository.equals(playgroundRepository)) {
return this.ouService.getOrganizationalUnit(this.playgroundSpaceName).getRepositories().stream().findFirst().get();
} else {
Credentials credentials = exampleRepository.getCredentials();
String username = null;
String password = null;
if (credentials != null) {
username = credentials.getUsername();
password = credentials.getPassword();
}
return cloneRepository(exampleRepository.getUrl(), username, password);
}
});
}
Aggregations