Search in sources :

Example 1 with ScopesAgendaFilter

use of org.drools.verifier.builder.ScopesAgendaFilter 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 2 with ScopesAgendaFilter

use of org.drools.verifier.builder.ScopesAgendaFilter 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 3 with ScopesAgendaFilter

use of org.drools.verifier.builder.ScopesAgendaFilter 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 4 with ScopesAgendaFilter

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

the class IncoherentRestrictionsTest method testApprovedTrueAndNotTrue.

@Test
public void testApprovedTrueAndNotTrue() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    String str = "";
    str += "package mortgages\n";
    str += "rule \"Bankruptcy history\"\n";
    str += "salience 10\n";
    str += "dialect \"mvel\"\n";
    str += "when\n";
    str += "Applicant( approved == \"true\" , approved != \"true\" )\n";
    str += "then\n";
    str += "end";
    DefaultVerifierConfiguration conf = new DefaultVerifierConfiguration();
    Verifier verifier = VerifierBuilderFactory.newVerifierBuilder().newVerifier(conf);
    verifier.addResourcesToVerify(ResourceFactory.newReaderResource(new StringReader(str)), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis(new ScopesAgendaFilter(true, ScopesAgendaFilter.VERIFYING_SCOPE_KNOWLEDGE_PACKAGE));
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    assertNotNull(result);
    assertEquals(3, result.getBySeverity(Severity.ERROR).size());
    assertEquals(1, result.getBySeverity(Severity.WARNING).size());
    assertEquals(0, result.getBySeverity(Severity.NOTE).size());
}
Also used : DefaultVerifierConfiguration(org.drools.verifier.DefaultVerifierConfiguration) ScopesAgendaFilter(org.drools.verifier.builder.ScopesAgendaFilter) VerifierReport(org.drools.verifier.data.VerifierReport) StringReader(java.io.StringReader) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Aggregations

ScopesAgendaFilter (org.drools.verifier.builder.ScopesAgendaFilter)4 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)4 VerifierReport (org.drools.verifier.data.VerifierReport)4 Test (org.junit.Test)4 ClassPathResource (org.drools.core.io.impl.ClassPathResource)3 StringReader (java.io.StringReader)1 DefaultVerifierConfiguration (org.drools.verifier.DefaultVerifierConfiguration)1 Verifier (org.drools.verifier.Verifier)1