Search in sources :

Example 1 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class WarningsTest method testRedundantRules.

@Test
@Ignore("08-APR-2011 temporally ignoring -Rikkola-")
public void testRedundantRules() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("RedundantRules1.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    VerifierReport result = verifier.getResult();
    Collection<VerifierMessageBase> warnings = result.getBySeverity(Severity.WARNING);
    int counter = 0;
    for (VerifierMessageBase message : warnings) {
        // System.out.println( message );
        if (message.getMessageType().equals(MessageType.REDUNDANCY)) {
            // System.out.println( message );
            counter++;
        }
    }
    assertEquals(1, counter);
    verifier.dispose();
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) Verifier(org.drools.verifier.Verifier) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class CauseTest method testCauseTrace.

@Test
@Ignore("08-APR-2011 temporally ignoring -Rikkola-")
public void testCauseTrace() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(new ClassPathResource("Causes.drl", getClass()), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(0, result.getBySeverity(Severity.ERROR).size());
    Collection<VerifierMessageBase> warnings = result.getBySeverity(Severity.WARNING);
    Collection<VerifierMessageBase> redundancyWarnings = new ArrayList<VerifierMessageBase>();
    for (VerifierMessageBase verifierMessageBase : warnings) {
        if (verifierMessageBase.getMessageType().equals(MessageType.REDUNDANCY)) {
            redundancyWarnings.add(verifierMessageBase);
        }
    }
    assertEquals(1, redundancyWarnings.size());
    VerifierMessage message = (VerifierMessage) redundancyWarnings.toArray()[0];
    // System.out.println( message );
    assertEquals(2, message.getImpactedRules().size());
    assertTrue(message.getImpactedRules().values().contains("Your First Rule"));
    assertTrue(message.getImpactedRules().values().contains("Your Second Rule"));
    Cause[] causes = message.getCauses().toArray(new Cause[message.getCauses().size()]);
    assertEquals(1, causes.length);
    causes = causes[0].getCauses().toArray(new Cause[causes[0].getCauses().size()]);
    assertEquals(2, causes.length);
    causes = causes[0].getCauses().toArray(new Cause[causes[0].getCauses().size()]);
    assertEquals(1, causes.length);
    causes = causes[0].getCauses().toArray(new Cause[causes[0].getCauses().size()]);
    assertEquals(1, causes.length);
    causes = causes[0].getCauses().toArray(new Cause[causes[0].getCauses().size()]);
    assertEquals(2, causes.length);
    assertEquals(0, result.getBySeverity(Severity.NOTE).size());
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) ArrayList(java.util.ArrayList) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class SubsumptantRestrictionsTest method testVerifierLiteralRestrictionRedundancy3.

@Test
public void testVerifierLiteralRestrictionRedundancy3() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantRestriction3.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<? extends Object> subsumptionList = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Subsumption.class));
    assertEquals(6, subsumptionList.size());
    verifier.dispose();
}
Also used : Subsumption(org.drools.verifier.report.components.Subsumption) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Example 4 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class SubsumptantSubRulesTest method testSubruleSubsumption1.

@Test
public void testSubruleSubsumption1() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubRules1.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    assertTrue(noProblems);
    Collection<? extends Object> subsumptionList = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Subsumption.class));
    int count = 0;
    for (Object object : subsumptionList) {
        // System.out.println( " * " + ((Subsumption) object) );
        if (((VerifierComponent) ((Subsumption) object).getLeft()).getVerifierComponentType().equals(VerifierComponentType.SUB_RULE)) {
            // System.out.println( " ** " + ((SubRule) ((Subsumption) object).getLeft()).getItems() + " - " + ((SubRule) ((Subsumption) object).getRight()).getItems() );
            count++;
        }
    }
    assertEquals(2, count);
    verifier.dispose();
}
Also used : Subsumption(org.drools.verifier.report.components.Subsumption) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Example 5 with Verifier

use of org.drools.verifier.Verifier in project drools by kiegroup.

the class VerifierReportBuilderTest method testHtmlReportTest.

@Test
public void testHtmlReportTest() throws IOException {
    // Create report
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
    VerifierReportWriter writer = VerifierReportWriterFactory.newHTMLReportWriter();
    // Write to disk
    FileOutputStream out = new FileOutputStream("testReport.zip");
    writer.writeReport(out, verifier.getResult());
    // Check the files on disk
    File file = new File("testReport.zip");
    assertNotNull(file);
    assertTrue(file.exists());
    // TODO: Check the file content
    // Remove the test file
    file.delete();
    assertFalse(file.exists());
}
Also used : FileOutputStream(java.io.FileOutputStream) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) File(java.io.File) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Aggregations

Verifier (org.drools.verifier.Verifier)20 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)19 Test (org.junit.Test)19 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)12 Subsumption (org.drools.verifier.report.components.Subsumption)11 Ignore (org.junit.Ignore)5 VerifierReport (org.drools.verifier.data.VerifierReport)4 ArrayList (java.util.ArrayList)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 InputStreamResource (org.drools.core.io.impl.InputStreamResource)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 DrlParser (org.drools.drl.parser.DrlParser)1 DefaultVerifierConfiguration (org.drools.verifier.DefaultVerifierConfiguration)1 VerifierError (org.drools.verifier.VerifierError)1