Search in sources :

Example 6 with ClassPathResource

use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.

the class VerifierTest method testVerifier.

@Test
public void testVerifier() {
    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("Misc3.drl", Verifier.class), 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());
    assertEquals(6, result.getBySeverity(Severity.WARNING).size());
    assertEquals(1, result.getBySeverity(Severity.NOTE).size());
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 7 with ClassPathResource

use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.

the class VerifierTest method testFactTypesFromJar.

@Test
public void testFactTypesFromJar() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    Verifier verifier = vBuilder.newVerifier();
    try {
        JarInputStream jar = new JarInputStream(this.getClass().getResourceAsStream("model.jar"));
        verifier.addObjectModel(jar);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    verifier.addResourcesToVerify(new ClassPathResource("imports.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    Collection<ObjectType> objectTypes = result.getVerifierData().getAll(VerifierComponentType.OBJECT_TYPE);
    assertNotNull(objectTypes);
    assertEquals(3, objectTypes.size());
    Collection<Field> fields = result.getVerifierData().getAll(VerifierComponentType.FIELD);
    assertNotNull(fields);
    assertEquals(10, fields.size());
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Field(org.drools.verifier.components.Field) JarInputStream(java.util.jar.JarInputStream) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) IOException(java.io.IOException) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 8 with ClassPathResource

use of org.drools.core.io.impl.ClassPathResource 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 9 with ClassPathResource

use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.

the class ConditionalBranchDescrTest method testVerifier.

@Test
public void testVerifier() {
    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("ConditionalBranchDescrTest.drl", Verifier.class), 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() );
// assertEquals( 6,
// result.getBySeverity( Severity.WARNING ).size() );
// assertEquals( 1,
// result.getBySeverity( Severity.NOTE ).size() );
}
Also used : VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 10 with ClassPathResource

use of org.drools.core.io.impl.ClassPathResource 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

ClassPathResource (org.drools.core.io.impl.ClassPathResource)88 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)45 Test (org.junit.jupiter.api.Test)38 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)33 Test (org.junit.Test)24 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)21 HashMap (java.util.HashMap)16 ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)16 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)14 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)12 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)11 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)11 VerifierReport (org.drools.verifier.data.VerifierReport)10 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)10 WorkItem (org.kie.kogito.process.WorkItem)10 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)9 ArrayList (java.util.ArrayList)6 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)6 KieSession (org.kie.api.runtime.KieSession)6 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)6