Search in sources :

Example 36 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method queryWithAFilter.

@Test
public void queryWithAFilter() throws Exception {
    final WorkspaceProject project = spy(WorkspaceProject.class);
    final Branch branch = mock(Branch.class);
    final Path path = mockPath("file://the_project");
    when(branch.getPath()).thenReturn(path);
    when(project.getBranch()).thenReturn(branch);
    doReturn(true).when(ioService).exists(any());
    final ProjectAssetsQuery query = new ProjectAssetsQuery(project, "helloo", 10, 20, Arrays.asList("xml"));
    final PageResponse<RefactoringPageRow> pageRowPageResponse = new PageResponse<>();
    pageRowPageResponse.setPageRowList(new ArrayList<>());
    when(refactoringQueryService.query(any(RefactoringPageRequest.class))).thenReturn(pageRowPageResponse);
    libraryService.getProjectAssets(query);
    verify(refactoringQueryService).query(pageRequestArgumentCaptor.capture());
    final RefactoringPageRequest pageRequest = pageRequestArgumentCaptor.getValue();
    assertEquals(FindAllLibraryAssetsQuery.NAME, pageRequest.getQueryName());
    assertEquals(3, pageRequest.getQueryTerms().size());
    assertQueryTermsContains(pageRequest.getQueryTerms(), "file://the_project");
    assertQueryTermsContains(pageRequest.getQueryTerms(), "*helloo*");
    assertQueryTermsContains(pageRequest.getQueryTerms(), ".*(xml)");
    assertEquals(10, pageRequest.getStartRowIndex());
    assertEquals(20, (int) pageRequest.getPageSize());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Branch(org.guvnor.structure.repositories.Branch) PageResponse(org.uberfire.paging.PageResponse) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Example 37 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method hasAssetsTest.

@Test
public void hasAssetsTest() {
    doReturn(true).when(ioService).exists(any());
    final Package package1 = mock(Package.class);
    final Module project1 = mock(Module.class);
    doReturn(package1).when(moduleService).resolveDefaultPackage(project1);
    doReturn(true).when(explorerServiceHelper).hasAssets(package1);
    final Package package2 = mock(Package.class);
    final Module project2 = mock(Module.class);
    doReturn(package2).when(moduleService).resolveDefaultPackage(project2);
    doReturn(false).when(explorerServiceHelper).hasAssets(package2);
    assertTrue(libraryService.hasAssets(new WorkspaceProject(mock(OrganizationalUnit.class), mock(Repository.class), mock(Branch.class), project1)));
    assertFalse(libraryService.hasAssets(new WorkspaceProject(mock(OrganizationalUnit.class), mock(Repository.class), mock(Branch.class), project2)));
}
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) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Branch(org.guvnor.structure.repositories.Branch) Package(org.guvnor.common.services.project.model.Package) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

Example 38 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method testGetNumberOfAssets.

@Test
public void testGetNumberOfAssets() throws Exception {
    final Path path = mock(Path.class);
    final WorkspaceProject project = mock(WorkspaceProject.class);
    final ProjectAssetsQuery query = mock(ProjectAssetsQuery.class);
    doReturn(project).when(query).getProject();
    doReturn(path).when(project).getRootPath();
    doReturn("some.unique.uri").when(path).toURI();
    libraryService.getNumberOfAssets(query);
    verify(refactoringQueryService).queryHitCount(any(RefactoringPageRequest.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Test(org.junit.Test)

Example 39 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method hasProjectsTest.

@Test
public void hasProjectsTest() {
    final Path path = mockPath("file://the_project");
    final WorkspaceProject project = mock(WorkspaceProject.class);
    when(project.getRootPath()).thenReturn(path);
    doReturn(true).when(ioService).exists(any());
    final Set<WorkspaceProject> projects = new HashSet<>();
    projects.add(project);
    doReturn(projects).when(projectService).getAllWorkspaceProjects(ou1);
    assertTrue(libraryService.hasProjects(ou1));
}
Also used : Path(org.uberfire.backend.vfs.Path) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject 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

WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)67 Test (org.junit.Test)42 Branch (org.guvnor.structure.repositories.Branch)29 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)28 Repository (org.guvnor.structure.repositories.Repository)26 Path (org.uberfire.backend.vfs.Path)26 Module (org.guvnor.common.services.project.model.Module)21 ArrayList (java.util.ArrayList)12 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)12 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)10 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)9 Before (org.junit.Before)8 KieModule (org.kie.workbench.common.services.shared.project.KieModule)7 POM (org.guvnor.common.services.project.model.POM)6 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)5 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)5 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)5 Date (java.util.Date)4 HashSet (java.util.HashSet)4 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)4