use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest 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());
}
use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest in project kie-wb-common by kiegroup.
the class ListAssetsTest method listFilesShouldNotHaveDuplicatesFromLibraryIndexer.
@Test
public void listFilesShouldNotHaveDuplicatesFromLibraryIndexer() throws IOException, InterruptedException {
// Add test files
addTestFile(TEST_MODULE_ROOT, "rule1.rule");
addTestFile(TEST_MODULE_ROOT, "rule2.rule");
addTestFile(TEST_MODULE_ROOT, "rule3.rule");
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
{
final RefactoringPageRequest request = new RefactoringPageRequest(TestFindFilesQuery.NAME, new HashSet<ValueIndexTerm>() {
{
add(new ValueFullFileNameIndexTerm("*.rule", ValueIndexTerm.TermSearchType.WILDCARD));
}
}, 0, 10);
try {
final PageResponse<RefactoringPageRow> response = service.query(request);
assertNotNull(response);
for (RefactoringPageRow refactoringPageRow : response.getPageRowList()) {
System.out.println(refactoringPageRow.getValue());
}
assertEquals(3, response.getPageRowList().size());
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
}
use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest in project kie-wb-common by kiegroup.
the class FindResourcePartsQueryValidIndexTermsTest method testIndexJavaFilesAndFindResourcePartsQuery.
@Test
public void testIndexJavaFilesAndFindResourcePartsQuery() throws Exception {
// setup
ioService();
// Add test files
String pojo1FileName = "Pojo1.java";
Path path = basePath.resolve(pojo1FileName);
String javaSourceText = loadText("../" + pojo1FileName);
ioService().write(path, javaSourceText);
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
{
final Query query = new SingleTermQueryBuilder(new ValueResourceIndexTerm("*", ResourceType.JAVA, TermSearchType.WILDCARD)).build();
List<KObject> hits = getConfig().getIndexProvider().findByQuery(index, query, 10);
assertEquals(1, hits.size());
List<Pair<String, String>> expectedValues = initExpectedValues();
KObject doc = null;
for (KObject kObject : hits) {
doc = kObject;
for (KProperty<?> property : doc.getProperties()) {
String fieldVal = property.getValue().toString();
if (fieldVal.startsWith("git://")) {
if (fieldVal.contains(pojo1FileName)) {
break;
}
} else {
continue;
}
}
}
assertContains(expectedValues, doc);
}
{
HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
queryTerms.add(new ValuePartIndexTerm("o_BigDecimal", PartType.FIELD));
final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartsQuery.NAME, queryTerms, 0, 10);
try {
final PageResponse<RefactoringPageRow> response = service.query(request);
assertNotNull("No documents found!", response);
assertEquals(1, response.getPageRowList().size());
} catch (IllegalArgumentException e) {
e.printStackTrace();
fail("Could not execute query: " + e.getMessage());
}
}
;
}
use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest in project kie-wb-common by kiegroup.
the class RefactoringQueryServiceImpl method queryToPageResponse.
/* (non-Javadoc)
* @see org.kie.workbench.common.services.refactoring.service.RefactoringQueryService#queryToPageResponse(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest)
*/
@Override
public PageResponse<RefactoringPageRow> queryToPageResponse(QueryOperationRequest queryOpRequest) {
final RefactoringPageRequest request = convertToRefactoringPageRequest(queryOpRequest);
final PageResponse<RefactoringPageRow> response = query(request);
return response;
}
use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest in project kie-wb-common by kiegroup.
the class RefactoringQueryServiceImpl method convertToRefactoringPageRequest.
private RefactoringPageRequest convertToRefactoringPageRequest(QueryOperationRequest refOpRequest) {
RefactoringPageRequest request = new RefactoringPageRequest(FindAllChangeImpactQuery.NAME, new HashSet<>(), refOpRequest.getStartRowIndex(), refOpRequest.getPageSize());
request.getQueryTerms().addAll(refOpRequest.getQueryTerms());
// add project info
String projectName = refOpRequest.getModuleName();
if (projectName != null && projectName != QueryOperationRequest.ALL) {
ValueModuleNameIndexTerm valueIndexTerm = new ValueModuleNameIndexTerm(projectName);
Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
queryTerms.add(valueIndexTerm);
request.getQueryTerms().addAll(queryTerms);
}
String projectRootPathURI = refOpRequest.getModuleRootPathURI();
if (projectRootPathURI != null && projectRootPathURI != QueryOperationRequest.ALL) {
ValueModuleRootPathIndexTerm valueIndexTerm = new ValueModuleRootPathIndexTerm(projectRootPathURI);
Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
queryTerms.add(valueIndexTerm);
request.getQueryTerms().addAll(queryTerms);
}
String branchName = refOpRequest.getBranchName();
if (branchName != null && branchName != QueryOperationRequest.ALL) {
ValueBranchNameIndexTerm valueIndexTerm = new ValueBranchNameIndexTerm(branchName);
Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
queryTerms.add(valueIndexTerm);
request.getQueryTerms().addAll(queryTerms);
}
return request;
}
Aggregations