Search in sources :

Example 11 with PageResponse

use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.

the class FormDefinitionIndexerTest method testFormsIndexing.

@Test
public void testFormsIndexing() throws Exception {
    List<Path> pathList = new ArrayList<>();
    ioService().startBatch(ioService().getFileSystem(basePath.toUri()));
    for (String formFile : FORMS) {
        Path path = basePath.resolve(formFile);
        pathList.add(path);
        String formContent = loadText(formFile);
        ioService().write(path, formContent);
    }
    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 = getFormResources();
                if (response != null && response.getPageRowList() != null && response.getPageRowList().size() >= paths.length) {
                    break;
                }
            }
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
        assertNotNull(response);
        Set<RefactoringPageRow> result = new HashSet(response.getPageRowList());
        assertEquals(paths.length, result.size());
    }
    {
        final Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>() {

            {
                add(new ValueResourceIndexTerm("*", ResourceType.FORM, ValueIndexTerm.TermSearchType.WILDCARD));
            }
        };
        try {
            Set<RefactoringPageRow> response = new HashSet(service.query(FindFormDefinitionIdsQuery.NAME, queryTerms));
            assertNotNull(response);
            assertEquals(paths.length, response.size());
            for (String expectedId : FORMS) {
                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(Arrays.asList(FORMS).contains(rKey));
                        foundId = true;
                    }
                }
                if (!foundId) {
                    fail("FormDefinition with ID <" + expectedId + " not found in results for " + FindFormDefinitionIdsQuery.NAME);
                }
            }
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) HashSet(java.util.HashSet) Set(java.util.Set) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) ArrayList(java.util.ArrayList) PageResponse(org.uberfire.paging.PageResponse) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Map(java.util.Map) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 12 with PageResponse

use of org.uberfire.paging.PageResponse 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());
        }
    }
    ;
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) Query(org.apache.lucene.search.Query) FindResourcePartsQuery(org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindResourcePartsQuery) NamedQuery(org.kie.workbench.common.services.refactoring.backend.server.query.NamedQuery) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) KObject(org.uberfire.ext.metadata.model.KObject) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) KProperty(org.uberfire.ext.metadata.model.KProperty) PageResponse(org.uberfire.paging.PageResponse) ArrayList(java.util.ArrayList) List(java.util.List) ValuePartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 13 with PageResponse

use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.

the class FindResourcePartReferencesQueryValidIndexTermsTest method testFindResourcePartReferencesQueryValidIndexTerms.

@Test
public void testFindResourcePartReferencesQueryValidIndexTerms() throws IOException, InterruptedException {
    // Add test files
    Path[] path = { basePath.resolve("drl1.drl"), basePath.resolve("drl2.drl"), basePath.resolve("drl3.drl") };
    String[] content = { loadText("../findresourceparts/drl1.drl"), loadText("../findresourceparts/drl2.drl"), loadText("../findresourceparts/drl3.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(FindResourcePartReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", "age", PartType.FIELD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(2, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path[0]);
            assertResponseContains(response.getPageRowList(), path[1]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueSharedPartIndexTerm("myRuleFlowGroup", PartType.RULEFLOW_GROUP));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(2, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path[0]);
            assertResponseContains(response.getPageRowList(), path[2]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValuePartReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm) PageResponse(org.uberfire.paging.PageResponse) HashSet(java.util.HashSet) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 14 with PageResponse

use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.

the class FindResourceReferencesQueryValidIndexTermsTest method testFindResourceReferencesQueryValidIndexTerms.

@Test
public void testFindResourceReferencesQueryValidIndexTerms() throws IOException, InterruptedException {
    // Add test files
    final Path[] paths = { basePath.resolve("drl1.drl"), basePath.resolve("drl2.drl"), basePath.resolve("drl3.drl"), basePath.resolve("functions.drl") };
    final String[] content = { loadText("../findresources/drl1.drl"), loadText("../findresources/drl2.drl"), loadText("../findresources/drl3.drl"), loadText("../findresources/functions.drl") };
    for (int i = 0; i < paths.length; ++i) {
        ioService().write(paths[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(FindResourceReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(2, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), paths[0]);
            assertResponseContains(response.getPageRowList(), paths[1]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourceReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes", ResourceType.JAVA, TermSearchType.PREFIX));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(3, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), paths[0]);
            assertResponseContains(response.getPageRowList(), paths[1]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourceReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("org.kie.workbench.mock.package.f1", ResourceType.FUNCTION));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(2, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), paths[0]);
            assertResponseContains(response.getPageRowList(), paths[1]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    // only locally referenced, not referenced in other resources
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourceReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("org.kie.workbench.mock.package.f4", ResourceType.FUNCTION));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(0, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourceReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("org.kie.workbench.mock.package.f4", ResourceType.FUNCTION));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(0, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) PageResponse(org.uberfire.paging.PageResponse) HashSet(java.util.HashSet) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 15 with PageResponse

use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.

the class FindRulesByModuleQueryValidIndexTermsTest method testQueryValidIndexTerms.

@Test
public void testQueryValidIndexTerms() throws IOException, InterruptedException {
    // Add test files
    addTestFile(BaseIndexingTest.TEST_MODULE_ROOT, "drl1.drl");
    addTestFile(BaseIndexingTest.TEST_MODULE_ROOT, "drl2.drl");
    addTestFile(SOME_OTHER_PROJECT_ROOT, "drl3.drl");
    addTestFile(BaseIndexingTest.TEST_MODULE_ROOT, "drl4.drl");
    addTestFile(BaseIndexingTest.TEST_MODULE_ROOT, "drl5.drl");
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm(BaseIndexingTest.TEST_MODULE_ROOT, TermSearchType.WILDCARD));
                add(new ValuePackageNameIndexTerm("", TermSearchType.WILDCARD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(1, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), "noPackage", "");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm("*", TermSearchType.WILDCARD));
                add(new ValuePackageNameIndexTerm("*", TermSearchType.WILDCARD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(5, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), "myRule", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "myRule2", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "myRule3", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "my.Rule4", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "noPackage", "");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm(BaseIndexingTest.TEST_MODULE_ROOT));
                add(new ValuePackageNameIndexTerm(BaseIndexingTest.TEST_PACKAGE_NAME));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(3, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), "myRule", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "myRule2", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "my.Rule4", "org.kie.workbench.mock.package");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm(SOME_OTHER_PROJECT_ROOT));
                add(new ValuePackageNameIndexTerm(BaseIndexingTest.TEST_PACKAGE_NAME));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(1, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), "myRule3", "org.kie.workbench.mock.package");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm(BaseIndexingTest.TEST_MODULE_ROOT));
                add(new ValuePackageNameIndexTerm("non-existent-package-name"));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(0, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm("non-existent-module-root"));
                add(new ValuePackageNameIndexTerm(BaseIndexingTest.TEST_PACKAGE_NAME));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(0, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) PageResponse(org.uberfire.paging.PageResponse) ValueModuleRootPathIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm) ValuePackageNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePackageNameIndexTerm) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Aggregations

PageResponse (org.uberfire.paging.PageResponse)15 Test (org.junit.Test)14 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)13 HashSet (java.util.HashSet)12 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)9 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)8 Path (org.uberfire.java.nio.file.Path)7 ArrayList (java.util.ArrayList)5 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)5 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)5 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)4 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)4 Path (org.uberfire.backend.vfs.Path)4 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Branch (org.guvnor.structure.repositories.Branch)3 AssetInfo (org.kie.workbench.common.screens.library.api.AssetInfo)2 AssetQueryResult (org.kie.workbench.common.screens.library.api.AssetQueryResult)2 LibraryValueModuleRootPathIndexTerm (org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm)2