use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.
the class FindResourcesQueryValidIndexTermsTest method testQueryValidRuleAttributeIndexTerms.
@Test
public void testQueryValidRuleAttributeIndexTerms() throws IOException, InterruptedException {
// Add test files
final Path[] path = { basePath.resolve("drl1.drl"), basePath.resolve("drl2.drl"), basePath.resolve("drl3.drl"), basePath.resolve("functions.drl") };
final String[] content = { loadText("drl1.drl"), loadText("drl2.drl"), loadText("drl3.drl"), loadText("functions.drl") };
for (int i = 0; i < path.length; ++i) {
ioService().write(path[i], content[i]);
}
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
{
final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcesQuery.NAME, new HashSet<ValueIndexTerm>() {
{
add(new ValueResourceIndexTerm("org.kie.workbench.mock.package.myRule", ResourceType.RULE));
}
}, 0, 10);
try {
final PageResponse<RefactoringPageRow> response = service.query(request);
assertNotNull(response);
assertEquals(1, response.getPageRowList().size());
assertResponseContains(response.getPageRowList(), path[0]);
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
{
final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcesQuery.NAME, new HashSet<ValueIndexTerm>() {
{
add(new ValueResourceIndexTerm("org.kie.workbench.mock.package.myRule*", ResourceType.RULE, TermSearchType.WILDCARD));
}
}, 0, 10);
try {
final PageResponse<RefactoringPageRow> response = service.query(request);
assertNotNull(response);
assertEquals(3, response.getPageRowList().size());
assertResponseContains(response.getPageRowList(), path[0]);
assertResponseContains(response.getPageRowList(), path[1]);
assertResponseContains(response.getPageRowList(), path[2]);
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
{
final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcesQuery.NAME, new HashSet<ValueIndexTerm>() {
{
add(new ValueResourceIndexTerm("org.kie.workbench.mock.package.f4", ResourceType.FUNCTION, TermSearchType.WILDCARD));
}
}, 0, 10);
try {
final PageResponse<RefactoringPageRow> response = service.query(request);
assertNotNull(response);
assertEquals(1, response.getPageRowList().size());
assertResponseContains(response.getPageRowList(), path[3]);
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
}
use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.
the class FindResourcesQueryValidIndexTermsTest method testFindResourcesQueryValidIndexTerms.
@Test
public void testFindResourcesQueryValidIndexTerms() throws IOException, InterruptedException {
// Add test files
final Path path1 = basePath.resolve("Pojo1.java");
final String javaFile1 = loadText("../Pojo1.java");
ioService().write(path1, javaFile1);
final Path path2 = basePath.resolve("Interface1.java");
final String javaFile2 = loadText("../Interface1.java");
ioService().write(path2, javaFile2);
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
{
HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
queryTerms.add(new ValueResourceIndexTerm("*", ResourceType.JAVA, TermSearchType.WILDCARD));
final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", queryTerms, 0, 10);
try {
final PageResponse<RefactoringPageRow> response = service.query(request);
assertNotNull("No documents found!", response);
assertEquals(2, response.getPageRowList().size());
assertResponseContains(response.getPageRowList(), path1);
} catch (IllegalArgumentException e) {
e.printStackTrace();
fail("Could not execute query: " + e.getMessage());
}
}
{
HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
queryTerms.add(new ValueResourceIndexTerm("org.kie.workbench.common.screens.datamodeller.backend.server.indexing", ResourceType.JAVA, // Prefix! :)
TermSearchType.PREFIX));
final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", queryTerms, 0, 10);
try {
final PageResponse<RefactoringPageRow> response = service.query(request);
assertNotNull("No documents found!", response);
assertEquals(2, response.getPageRowList().size());
assertResponseContains(response.getPageRowList(), path1);
} catch (IllegalArgumentException e) {
e.printStackTrace();
fail("Could not execute query: " + e.getMessage());
}
}
{
HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
queryTerms.add(new ValueResourceIndexTerm("*Pojo1", ResourceType.JAVA, // Wildcard! :)
TermSearchType.WILDCARD));
final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", queryTerms, 0, 10);
try {
final PageResponse<RefactoringPageRow> response = service.query(request);
assertNotNull(response);
assertEquals(1, response.getPageRowList().size());
assertResponseContains(response.getPageRowList(), path1);
} catch (IllegalArgumentException e) {
e.printStackTrace();
fail("Could not execute query: " + e.getMessage());
}
}
}
use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.
the class FindAllLibraryAssetsQueryTest method filterFilesFromModule.
@Test
public void filterFilesFromModule() throws IOException, InterruptedException {
// Add test files
addTestFile(TEST_MODULE_ROOT, "rule1.rule");
addTestFile(TEST_MODULE_ROOT, "rule2.rule");
addTestFile(SOME_OTHER_MODULE_ROOT, "rule3.rule");
addTestFile(TEST_MODULE_ROOT, "functions.functions");
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
{
final RefactoringPageRequest request = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {
{
add(new LibraryValueModuleRootPathIndexTerm(TEST_MODULE_ROOT, TermSearchType.WILDCARD));
add(new LibraryValueFileNameIndexTerm("*rule*", 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(2, response.getPageRowList().size());
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
}
use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.
the class FindAllLibraryAssetsQueryTest method listAllInModule.
@Test
public void listAllInModule() throws IOException, InterruptedException {
// Add test files
addTestFile(TEST_MODULE_ROOT, "drl1.drl");
addTestFile(TEST_MODULE_ROOT, "drl2.ext2");
addTestFile(SOME_OTHER_MODULE_ROOT, "drl3.ext3");
addTestFile(TEST_MODULE_ROOT, "functions.functions");
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
{
final RefactoringPageRequest request = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {
{
add(new LibraryValueModuleRootPathIndexTerm(TEST_MODULE_ROOT, 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.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.
the class BpmnFileIndexerTest method testBpmnIndexing.
@Test
public void testBpmnIndexing() throws Exception {
List<Path> pathList = new ArrayList<>();
ioService().startBatch(ioService().getFileSystem(basePath.toUri()));
for (int i = 0; i < BPMN_FILES.length; ++i) {
String bpmnFile = BPMN_FILES[i];
if (bpmnFile.endsWith("bpmn")) {
Path path = basePath.resolve(bpmnFile);
pathList.add(path);
String bpmnStr = loadText(bpmnFile);
ioService().write(path, bpmnStr);
}
}
ioService().endBatch();
Path[] paths = pathList.toArray(new Path[pathList.size()]);
{
PageResponse<RefactoringPageRow> response = null;
try {
for (int i = 0; i < MAX_WAIT_TIMES; i++) {
Thread.sleep(WAIT_TIME_MILLIS);
response = queryBPMN2Resources();
if (response != null && response.getPageRowList() != null && response.getPageRowList().size() >= paths.length) {
break;
}
}
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
assertNotNull(response);
assertEquals(paths.length, response.getPageRowList().size());
}
{
QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("*", PartType.RULEFLOW_GROUP, ValueIndexTerm.TermSearchType.WILDCARD).inAllModules().onAllBranches();
try {
final List<RefactoringPageRow> response = service.queryToList(request);
assertNotNull(response);
assertEquals(1, response.size());
assertResponseContains(response, paths[4]);
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
{
QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("MySignal", PartType.SIGNAL).inAllModules().onAllBranches();
try {
final List<RefactoringPageRow> response = service.queryToList(request);
assertNotNull(response);
assertEquals(1, response.size());
assertResponseContains(response, paths[5]);
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
{
QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("BrokenSignal", PartType.SIGNAL).inAllModules().onAllBranches();
try {
final List<RefactoringPageRow> response = service.queryToList(request);
assertNotNull(response);
assertEquals(1, response.size());
assertResponseContains(response, paths[6]);
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
{
QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("name", PartType.GLOBAL).inAllModules().onAllBranches();
try {
final List<RefactoringPageRow> response = service.queryToList(request);
assertNotNull(response);
assertEquals(2, response.size());
assertResponseContains(response, paths[5]);
assertResponseContains(response, paths[6]);
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
{
final Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>() {
{
add(new ValueResourceIndexTerm("*", ResourceType.BPMN2, ValueIndexTerm.TermSearchType.WILDCARD));
}
};
try {
List<RefactoringPageRow> response = service.query(FindBpmnProcessIdsQuery.NAME, queryTerms);
assertNotNull(response);
assertEquals(paths.length, response.size());
for (String expectedId : PROCESS_IDS) {
boolean foundId = false;
for (RefactoringPageRow row : response) {
Map<String, org.uberfire.backend.vfs.Path> mapRow = (Map<String, org.uberfire.backend.vfs.Path>) row.getValue();
for (String rKey : mapRow.keySet()) {
assertTrue(PROCESS_IDS.contains(rKey));
foundId = true;
}
}
if (!foundId) {
fail("Process with ID <" + expectedId + " not found in results for " + FindBpmnProcessIdsQuery.NAME);
}
}
} catch (IllegalArgumentException e) {
fail("Exception thrown: " + e.getMessage());
}
}
}
Aggregations