Search in sources :

Example 6 with VerifierComponent

use of org.drools.verifier.data.VerifierComponent in project drools by kiegroup.

the class PackageDescrVisitorTest method testSubPatterns.

@Test
public void testSubPatterns() throws Exception {
    PackageDescr packageDescr = getPackageDescr(getClass().getResourceAsStream("SubPattern.drl"));
    assertNotNull(packageDescr);
    packageDescrVisitor.visitPackageDescr(packageDescr);
    Collection<VerifierComponent> all = verifierData.getAll();
    assertNotNull(all);
    SubPattern test1SubPattern = null;
    SubPattern test2SubPattern = null;
    SubRule test1SubRule = null;
    SubRule test2SubRule = null;
    for (VerifierComponent verifierComponent : all) {
        // System.out.println( verifierComponent );
        System.out.println("-" + verifierComponent);
        if (verifierComponent.getDescr() != null) {
            System.out.println(" \n\t\t => " + verifierComponent.getDescr().getLine() + ":" + +verifierComponent.getDescr().getEndLine() + " " + verifierComponent.getDescr().getText());
        } else {
            System.out.println(" \n\t\t => null for " + verifierComponent.getClass().getSimpleName());
        }
        if (verifierComponent.getVerifierComponentType().equals(VerifierComponentType.SUB_PATTERN)) {
            SubPattern subPattern = (SubPattern) verifierComponent;
            if ("Test 1".equals(subPattern.getRuleName())) {
                assertNull(test1SubPattern);
                test1SubPattern = subPattern;
            } else if ("Test 2".equals(subPattern.getRuleName())) {
                assertNull(test2SubPattern);
                test2SubPattern = subPattern;
            }
        }
        if (verifierComponent.getVerifierComponentType().equals(VerifierComponentType.SUB_RULE)) {
            SubRule subRule = (SubRule) verifierComponent;
            if ("Test 1".equals(subRule.getRuleName())) {
                assertNull(test1SubRule);
                test1SubRule = subRule;
            } else if ("Test 2".equals(subRule.getRuleName())) {
                assertNull(test2SubRule);
                test2SubRule = subRule;
            }
        }
    }
    assertNotNull(test1SubPattern);
    assertEquals(3, test1SubPattern.getItems().size());
    assertNotNull(test2SubPattern);
    assertEquals(3, test2SubPattern.getItems().size());
    assertNotNull(test1SubRule);
    assertEquals(1, test1SubRule.getItems().size());
    assertNotNull(test2SubRule);
    assertEquals(1, test2SubRule.getItems().size());
}
Also used : SubRule(org.drools.verifier.components.SubRule) SubPattern(org.drools.verifier.components.SubPattern) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) VerifierComponent(org.drools.verifier.data.VerifierComponent) Test(org.junit.Test)

Example 7 with VerifierComponent

use of org.drools.verifier.data.VerifierComponent in project drools by kiegroup.

the class PackageDescrVisitorTest method testVisit.

@Test
public void testVisit() throws Exception {
    PackageDescr packageDescr = getPackageDescr(Verifier.class.getResourceAsStream("Misc3.drl"));
    assertNotNull(packageDescr);
    packageDescrVisitor.visitPackageDescr(packageDescr);
    Collection<VerifierComponent> all = verifierData.getAll();
    Set<String> names = new HashSet<String>();
    for (VerifierComponent verifierComponent : all) {
        String path = verifierComponent.getPath();
        System.out.println("-" + verifierComponent);
        if (verifierComponent.getDescr() != null) {
            System.out.println(" \n\t\t => " + verifierComponent.getDescr().getLine() + ":" + +verifierComponent.getDescr().getEndLine() + " " + verifierComponent.getDescr().getText());
        } else {
            System.out.println(" \n\t\t => null for " + verifierComponent.getClass().getSimpleName());
        }
        if (names.contains(path)) {
            fail("Dublicate path " + path);
        } else {
            names.add(path);
        }
    }
    assertNotNull(all);
    assertEquals(45, all.size());
}
Also used : PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Verifier(org.drools.verifier.Verifier) VerifierComponent(org.drools.verifier.data.VerifierComponent) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

VerifierComponent (org.drools.verifier.data.VerifierComponent)7 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 Test (org.junit.Test)4 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 DrlParser (org.drools.compiler.compiler.DrlParser)2 Verifier (org.drools.verifier.Verifier)2 SubPattern (org.drools.verifier.components.SubPattern)2 SubRule (org.drools.verifier.components.SubRule)2 VerifierData (org.drools.verifier.data.VerifierData)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Pattern (org.drools.verifier.components.Pattern)1 Restriction (org.drools.verifier.components.Restriction)1