Search in sources :

Example 6 with ProjectAssetsQuery

use of org.kie.workbench.common.screens.library.api.ProjectAssetsQuery 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 7 with ProjectAssetsQuery

use of org.kie.workbench.common.screens.library.api.ProjectAssetsQuery 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 8 with ProjectAssetsQuery

use of org.kie.workbench.common.screens.library.api.ProjectAssetsQuery in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method queryAnItemThatIsInLuceneIndexButAlreadyDeletedFromGitRepository.

@Test
public void queryAnItemThatIsInLuceneIndexButAlreadyDeletedFromGitRepository() throws Exception {
    final Path path = mockPath("file://the_project");
    final WorkspaceProject project = spy(WorkspaceProject.class);
    final Branch branch = mock(Branch.class);
    when(project.getBranch()).thenReturn(branch);
    when(branch.getPath()).thenReturn(path);
    doReturn(true).when(ioService).exists(any());
    final ProjectAssetsQuery query = new ProjectAssetsQuery(project, "", 10, 20, Collections.emptyList());
    final PageResponse<RefactoringPageRow> pageRowPageResponse = new PageResponse<>();
    final ArrayList<RefactoringPageRow> assetPageRowList = new ArrayList<>();
    final RefactoringPageRow pageRow = mock(RefactoringPageRow.class);
    final Path filePath = mockPath("file://the_project/delete.me");
    when(filePath.getFileName()).thenReturn("delete.me");
    when(pageRow.getValue()).thenReturn(filePath);
    assetPageRowList.add(pageRow);
    pageRowPageResponse.setPageRowList(assetPageRowList);
    when(refactoringQueryService.query(any(RefactoringPageRequest.class))).thenReturn(pageRowPageResponse);
    when(ioService.readAttributes(any())).thenThrow(new NoSuchFileException());
    final AssetQueryResult result = libraryService.getProjectAssets(query);
    assertEquals(ResultType.Normal, result.getResultType());
    assertTrue(result.getAssetInfos().isPresent());
    List<AssetInfo> projectAssets = result.getAssetInfos().get();
    assertTrue(projectAssets.isEmpty());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo) ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) Branch(org.guvnor.structure.repositories.Branch) AssetQueryResult(org.kie.workbench.common.screens.library.api.AssetQueryResult) PageResponse(org.uberfire.paging.PageResponse) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Example 9 with ProjectAssetsQuery

use of org.kie.workbench.common.screens.library.api.ProjectAssetsQuery in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method emptyFirstPage.

@Test
public void emptyFirstPage() throws Exception {
    final WorkspaceProject project = spy(WorkspaceProject.class);
    final Branch branch = mock(Branch.class);
    final Path path = mock(Path.class);
    when(project.getBranch()).thenReturn(branch);
    when(branch.getPath()).thenReturn(path);
    when(path.toURI()).thenReturn("file://a/b/c");
    doReturn(true).when(ioService).exists(any());
    final ProjectAssetsQuery query = new ProjectAssetsQuery(project, "", 0, 10, Collections.emptyList());
    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(1, pageRequest.getQueryTerms().size());
    assertEquals("file://a/b/c", pageRequest.getQueryTerms().iterator().next().getValue());
    assertEquals(0, pageRequest.getStartRowIndex());
    assertEquals(10, (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 10 with ProjectAssetsQuery

use of org.kie.workbench.common.screens.library.api.ProjectAssetsQuery in project kie-wb-common by kiegroup.

the class PopulatedAssetsScreen method getAssets.

private void getAssets(String filter, String filterType, int startIndex, int amount, RemoteCallback<AssetQueryResult> callback) {
    if (!isProjectNull()) {
        ProjectAssetsQuery query = this.createProjectQuery(filter, filterType, startIndex, amount);
        assetQueryService.getAssets(query).call(callback, new DefaultErrorCallback());
    }
}
Also used : ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) DefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.DefaultErrorCallback)

Aggregations

ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)11 Test (org.junit.Test)7 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)6 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)5 Path (org.uberfire.backend.vfs.Path)5 Branch (org.guvnor.structure.repositories.Branch)4 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)4 PageResponse (org.uberfire.paging.PageResponse)4 AssetQueryResult (org.kie.workbench.common.screens.library.api.AssetQueryResult)3 ArrayList (java.util.ArrayList)2 AssetInfo (org.kie.workbench.common.screens.library.api.AssetInfo)2 NoSuchFileException (org.uberfire.java.nio.file.NoSuchFileException)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1