use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.
the class ResourceReference method toIndexElements.
@Override
public List<KProperty<?>> toIndexElements() {
final List<KProperty<?>> indexElements = new ArrayList<>();
// Impact Analysis references
if (resourceFQN != null) {
ValueReferenceIndexTerm refTerm = new ValueReferenceIndexTerm(this.resourceFQN, this.resourceType);
indexElements.add(new KPropertyImpl<>(refTerm.getTerm(), refTerm.getValue()));
}
if (this.fieldNamepartReferenceMap != null) {
fieldNamepartReferenceMap.values().forEach((refPartTerm) -> indexElements.add(new KPropertyImpl<>(refPartTerm.getTerm(), refPartTerm.getValue())));
}
return indexElements;
}
use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.
the class FindResourcesQueryInvalidIndexTermsTest method testFindResourcesQueryInvalidIndexTerms.
@Test
public void testFindResourcesQueryInvalidIndexTerms() throws IOException, InterruptedException {
{
final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", new HashSet<ValueIndexTerm>(), 0, -1);
try {
service.query(request);
fail();
} catch (IllegalArgumentException e) {
String msg = "Expected '" + ValueResourceIndexTerm.class.getSimpleName() + "' term was not found";
assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().startsWith(msg));
// and Swallow. Expected
}
}
{
final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", new HashSet<ValueIndexTerm>() {
{
add(new ValueReferenceIndexTerm("myRule", ResourceType.RULE));
}
}, 0, -1);
try {
service.query(request);
fail();
} catch (IllegalArgumentException e) {
assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().contains("Index term 'ref:rule' can not be used with "));
}
}
{
final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", new HashSet<ValueIndexTerm>() {
{
add(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA));
add(new ValueReferenceIndexTerm("myRule", ResourceType.RULE));
}
}, 0, -1);
try {
service.query(request);
fail();
} catch (IllegalArgumentException e) {
assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().contains(" can not be used with the " + FindResourcesQuery.NAME));
}
}
}
use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.
the class IndexDrlInvalidDrlTest method testIndexDrlInvalidRuleName.
@Test
@SuppressWarnings("unchecked")
public void testIndexDrlInvalidRuleName() throws IOException, InterruptedException, ExecutionException {
// Setup logging
final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender<ILoggingEvent> mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
// Add test files
final Path path1 = basePath.resolve("bz1269366.drl");
final String drl1 = loadText("bz1269366.drl");
ioService().write(path1, drl1);
Thread.sleep(5000);
List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId());
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA)).build();
searchFor(index, query, 0);
verify(mockAppender).doAppend(argThat(argument -> argument.getMessage().startsWith("Unable to parse DRL")));
}
}
use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.
the class IndexDrlLHSTypeExpressionField2Test method testIndexDrlLHSTypeExpressionField2.
@Test
public void testIndexDrlLHSTypeExpressionField2() throws IOException, InterruptedException {
// Add test files
final Path path1 = basePath.resolve("drl4.drl");
final String drl1 = loadText("drl4.drl");
ioService().write(path1, drl1);
// 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).getClusterId());
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA)).build();
searchFor(index, query, 1, path1);
}
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", ResourceType.JAVA)).build();
searchFor(index, query, 1, path1);
}
{
final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", "applicant", PartType.FIELD)).build();
searchFor(index, query, 1, path1);
}
{
final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", "age", PartType.FIELD)).build();
searchFor(index, query, 1, path1);
}
}
use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.
the class IndexDrlLHSTypeExpressionField4Test method testIndexDrlLHSTypeExpressionField4.
@Test
public void testIndexDrlLHSTypeExpressionField4() throws IOException, InterruptedException {
// Add test files
final Path path1 = basePath.resolve("drl6.drl");
final String drl1 = loadText("drl6.drl");
ioService().write(path1, drl1);
// 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).getClusterId());
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Bank", ResourceType.JAVA)).build();
searchFor(index, query, 1, path1);
}
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", ResourceType.JAVA)).build();
searchFor(index, query, 1, path1);
}
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA)).build();
searchFor(index, query, 1, path1);
}
{
final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Bank", "mortgage", PartType.FIELD)).build();
searchFor(index, query, 1, path1);
}
{
final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", "applicant", PartType.FIELD)).build();
searchFor(index, query, 1, path1);
}
{
final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", "age", PartType.FIELD)).build();
searchFor(index, query, 1, path1);
}
}
Aggregations