Search in sources :

Example 21 with RefactoringPageRequest

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest 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 22 with RefactoringPageRequest

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest 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

RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)22 Test (org.junit.Test)17 HashSet (java.util.HashSet)16 PageResponse (org.uberfire.paging.PageResponse)12 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)10 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)10 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)8 LibraryValueModuleRootPathIndexTerm (org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm)5 Path (org.uberfire.backend.vfs.Path)5 Path (org.uberfire.java.nio.file.Path)5 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)3 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 Branch (org.guvnor.structure.repositories.Branch)2 ValueModuleRootPathIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm)2 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)2 Collection (java.util.Collection)1