Search in sources :

Example 21 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder in project drools by kiegroup.

the class VerifierTest method testCustomRule.

@Test
public void testCustomRule() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("FindPatterns.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    if (!works) {
        for (VerifierError error : verifier.getErrors()) {
            System.out.println(error.getMessage());
        }
        fail("Could not run verifier");
    }
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(6, result.getBySeverity(Severity.NOTE).size());
    for (VerifierMessageBase m : result.getBySeverity(Severity.NOTE)) {
        assertEquals("This pattern was found.", m.getMessage());
    }
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 22 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder in project drools by kiegroup.

the class VerifyingScopeTest method testSingleRule.

@Test
public void testSingleRule() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("VerifyingScope.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(true, ScopesAgendaFilter.VERIFYING_SCOPE_SINGLE_RULE));
    if (!works) {
        for (VerifierError error : verifier.getErrors()) {
            System.out.println(error.getMessage());
        }
        fail("Error when building in verifier");
    }
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(6, result.getBySeverity(Severity.NOTE).size());
}
Also used : ScopesAgendaFilter(org.drools.verifier.builder.ScopesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 23 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder in project drools by kiegroup.

the class VerifyingScopeTest method testNothing.

@Test
public void testNothing() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("VerifyingScope.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(true, Collections.EMPTY_LIST));
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(2, result.getBySeverity(Severity.NOTE).size());
}
Also used : ScopesAgendaFilter(org.drools.verifier.builder.ScopesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 24 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder in project drools by kiegroup.

the class VerifyingScopeTest method testDecisionTable.

@Test
public void testDecisionTable() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    vConfiguration.getVerifyingResources().put(new ClassPathResource("VerifyingScope.drl", Verifier.class), ResourceType.DRL);
    Verifier verifier = vBuilder.newVerifier(vConfiguration);
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(false, ScopesAgendaFilter.VERIFYING_SCOPE_DECISION_TABLE));
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    assertEquals(0, result.getBySeverity(Severity.WARNING).size());
    assertEquals(2, result.getBySeverity(Severity.NOTE).size());
}
Also used : ScopesAgendaFilter(org.drools.verifier.builder.ScopesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 25 with VerifierBuilder

use of org.drools.verifier.builder.VerifierBuilder in project drools by kiegroup.

the class AlwaysFalseTest method testAlwaysFalse.

@Test
public void testAlwaysFalse() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("AlwaysFalseTest.drl", getClass()), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<VerifierMessageBase> notes = verifier.getResult().getBySeverity(Severity.ERROR);
    assertEquals(1, containsMessageType(notes, MessageType.ALWAYS_FALSE));
    verifier.dispose();
}
Also used : VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Aggregations

VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)27 Test (org.junit.Test)27 Verifier (org.drools.verifier.Verifier)18 VerifierReport (org.drools.verifier.data.VerifierReport)13 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)12 ClassPathResource (org.drools.core.io.impl.ClassPathResource)11 Subsumption (org.drools.verifier.report.components.Subsumption)11 Ignore (org.junit.Ignore)5 ScopesAgendaFilter (org.drools.verifier.builder.ScopesAgendaFilter)4 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)4 IOException (java.io.IOException)2 JarInputStream (java.util.jar.JarInputStream)2 Field (org.drools.verifier.components.Field)2 ObjectType (org.drools.verifier.components.ObjectType)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 DefaultVerifierConfiguration (org.drools.verifier.DefaultVerifierConfiguration)1 VerifierError (org.drools.verifier.VerifierError)1