Search in sources :

Example 1 with RepositoryEnvironmentConfigurations

use of org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations in project kie-wb-common by kiegroup.

the class LibraryServiceImpl method importProject.

@Override
public WorkspaceProject importProject(final OrganizationalUnit targetOU, final String repositoryURL, final String username, final String password) {
    final RepositoryEnvironmentConfigurations config = new RepositoryEnvironmentConfigurations();
    config.setOrigin(repositoryURL);
    if (username != null && password != null) {
        config.setUserName(username);
        config.setPassword(password);
    }
    final String targetProjectName = inferProjectName(repositoryURL);
    final Repository repo = repoService.createRepository(targetOU, GitRepository.SCHEME.toString(), targetProjectName, config);
    return projectService.resolveProject(repo);
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)

Example 2 with RepositoryEnvironmentConfigurations

use of org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method importProjectWithoutCredentialsTest.

@Test
public void importProjectWithoutCredentialsTest() {
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    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 ArgumentCaptor<RepositoryEnvironmentConfigurations> configCaptor = ArgumentCaptor.forClass(RepositoryEnvironmentConfigurations.class);
    when(repositoryService.createRepository(any(), any(), any(), configCaptor.capture())).thenReturn(repo);
    when(projectService.resolveProject(any(Repository.class))).thenReturn(project);
    final WorkspaceProject observedProject = libraryService.importProject(organizationalUnit, repositoryURL, username, password);
    verify(repositoryService).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());
    verify(projectService).resolveProject(same(repo));
    assertSame(project, observedProject);
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Test(org.junit.Test)

Example 3 with RepositoryEnvironmentConfigurations

use of org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method importProjectWithCredentialsTest.

@Test
public void importProjectWithCredentialsTest() {
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    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 ArgumentCaptor<RepositoryEnvironmentConfigurations> configCaptor = ArgumentCaptor.forClass(RepositoryEnvironmentConfigurations.class);
    when(repositoryService.createRepository(any(), any(), any(), configCaptor.capture())).thenReturn(repo);
    when(projectService.resolveProject(any(Repository.class))).thenReturn(project);
    final WorkspaceProject observedProject = libraryService.importProject(organizationalUnit, repositoryURL, username, password);
    verify(repositoryService).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());
    verify(projectService).resolveProject(same(repo));
    assertSame(project, observedProject);
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Test(org.junit.Test)

Aggregations

Repository (org.guvnor.structure.repositories.Repository)3 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)3 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)3 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)3 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)2 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)2 Test (org.junit.Test)2 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)2