Search in sources :

Example 6 with Credentials

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

Example 7 with Credentials

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);
        }
    });
}
Also used : Credentials(org.kie.workbench.common.screens.examples.model.Credentials)

Aggregations

Credentials (org.kie.workbench.common.screens.examples.model.Credentials)7 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)4 Test (org.junit.Test)3 ImportProject (org.kie.workbench.common.screens.examples.model.ImportProject)3 Repository (org.guvnor.structure.repositories.Repository)2 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)2 Mockito.anyString (org.mockito.Mockito.anyString)2 Path (org.uberfire.backend.vfs.Path)2 FileSystem (org.uberfire.java.nio.file.FileSystem)2 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)2 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 RepositoryInfo (org.guvnor.structure.organizationalunit.config.RepositoryInfo)1 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)1 Message (org.jboss.errai.bus.client.api.messaging.Message)1 EmptyRemoteRepositoryException (org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException)1