Java Code Examples for org.kie.internal.utils.KieHelper#verify()

The following examples show how to use org.kie.internal.utils.KieHelper#verify() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbductionTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
protected KieSession getSessionFromString( String drlString, KieBaseConfiguration kbConf ) {
    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent( drlString, ResourceType.DRL );

    Results res = kieHelper.verify();
    if ( res.hasMessages( Message.Level.ERROR ) ) {
        fail( res.getMessages( Message.Level.ERROR ).toString() );
    }

    if ( kbConf == null ) {
        kbConf = KieServices.Factory.get().newKieBaseConfiguration();
    }
    kbConf.setOption( EqualityBehaviorOption.EQUALITY );
    KieBase kieBase = kieHelper.build( kbConf );


    KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ((SessionConfiguration) ksConf).setBeliefSystemType( BeliefSystemType.DEFEASIBLE );
    return kieBase.newKieSession( ksConf, null );
}
 
Example 2
Source File: EnumTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnumsWithCompositeBuildingProcess() throws Exception {
    final String drl = "package org.test; " +
                 "" +
                 "declare enum DaysOfWeek " +
                 "    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;\n" +
                 "end\n" +

                 "declare Test " +
                 "  field: DaysOfWeek " +
                 "end";

    final KieHelper kieHelper = new KieHelper();
    kieHelper.addContent( drl, ResourceType.DRL );
    final Results res = kieHelper.verify();
    assertEquals( 0, res.getMessages().size() );
}
 
Example 3
Source File: QueryTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryWithIncompatibleArgs() {
    String drl = "global java.util.List list; " +
                 "" +
                 "query foo( String $s, String $s, String $s ) end " +
                 "" +
                 "rule React \n" +
                 "when\n" +
                 "  $i : Integer() " +
                 "  foo( $i, $x, $i ; ) " +
                 "then\n" +
                 "end";

    KieHelper helper = new KieHelper();
    helper.addContent( drl, ResourceType.DRL );
    Results results = helper.verify();
    assertTrue( results.hasMessages( Message.Level.ERROR ) );
    assertEquals( 2, results.getMessages( Message.Level.ERROR ).size() );
}
 
Example 4
Source File: QueryTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryWithSyntaxError() {
    String drl = "global java.util.List list; " +
                 "" +
                 "query foo( Integer $i ) end " +
                 "" +
                 "rule React \n" +
                 "when\n" +
                 "  $i : Integer() " +
                 "  foo( $i ) " +   // missing ";" should result in 1 compilation error
                 "then\n" +
                 "end";

    KieHelper helper = new KieHelper();
    helper.addContent( drl, ResourceType.DRL );
    Results results = helper.verify();
    assertTrue( results.hasMessages( Message.Level.ERROR ) );
    assertEquals( 1, results.getMessages( Message.Level.ERROR ).size() );
}
 
Example 5
Source File: QueryTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryWithWrongParamNumber() {
    String drl = "global java.util.List list; " +
                 "" +
                 "query foo( Integer $i ) end " +
                 "" +
                 "rule React \n" +
                 "when\n" +
                 "  $i : Integer() " +
                 "  $j : Integer() " +
                 "  foo( $i, $j ; ) " +
                "then\n" +
                 "end";

    KieHelper helper = new KieHelper();
    helper.addContent( drl, ResourceType.DRL );
    Results results = helper.verify();
    assertTrue( results.hasMessages( Message.Level.ERROR ) );
    assertEquals( 1, results.getMessages( Message.Level.ERROR ).size() );
}
 
Example 6
Source File: KieSessionUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
public static KieSession createKieSessionFromDRL(String drl) throws Exception{
    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent(drl, ResourceType.DRL);
    Results results = kieHelper.verify();
    if (results.hasMessages(Message.Level.WARNING, Message.Level.ERROR)) {
        List<Message> messages = results.getMessages(Message.Level.WARNING, Message.Level.ERROR);
        for (Message message : messages) {
            System.out.println("Error: "+message.getText());
        }
        // throw new IllegalStateException("Compilation errors were found. Check the logs.");
    }
    return kieHelper.build().newKieSession();
}
 
Example 7
Source File: AbductionTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testAbductiveLogicWithNonExistingArgsMapping() {
    String droolsSource =
            "package org.drools.abductive.test; \n" +
            "" +
            "import " + Abducible.class.getName() + "; \n" +
            "global java.util.List list; \n" +
            "" +
            "declare Foo \n" +
            "   @Abducible \n" +
            "   id : String @key \n" +
            "   name : String @key \n" +
            "end \n" +

            "query foo( String $name ) \n" +
            "   @Abductive( target=Foo.class, args={ $missing, $name } ) \n" +
            "end \n" +

            "";
    /////////////////////////////////////

    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent( droolsSource, ResourceType.DRL );

    Results res = kieHelper.verify();
    assertEquals( 1, res.getMessages( Message.Level.ERROR ).size() );
}
 
Example 8
Source File: AbductionTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testAbductiveLogicWithWrongTypeArgsMapping() {
    String droolsSource =
            "package org.drools.abductive.test; \n" +
            "" +
            "import " + Abducible.class.getName() + "; \n" +
            "global java.util.List list; \n" +
            "" +
            "declare Foo \n" +
            "   @Abducible \n" +
            "   id : String @key \n" +
            "   name : String @key \n" +
            "end \n" +

            "query foo( String $name, int $x ) \n" +
            "   @Abductive( target=Foo.class, args={ $x, $name } ) \n" +
            "end \n" +

            "rule R0 " +
            "when " +
            "   $f := foo( \"name_test\", 99 ; ) " +
            "then " +
            "   list.add( $f ); " +
            "end \n" +

            "";
    /////////////////////////////////////

    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent( droolsSource, ResourceType.DRL );

    Results res = kieHelper.verify();
    assertEquals( 1, res.getMessages( Message.Level.ERROR ).size() );
}
 
Example 9
Source File: AbductionTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testAbductiveLogicNoConstructorFoundError() {
    String droolsSource =
            "package org.drools.abductive.test; \n" +
            "" +
            "import " + Abducible.class.getName() + "; \n" +
            "global java.util.List list; \n" +
            "" +
            "declare Foo \n" +
            "   @Abducible \n" +
            "   id : Integer @key \n" +
            "end \n" +

            "query foo( String $x ) \n" +
                // Foo does not have a String constructor
            "   @Abductive( target=Foo.class ) \n" +
            "end \n" +

            "rule R1 " +
            "when " +
            "   $x : foo( \"x\" ; ) " +
            "then " +
            "   list.add( $x ); " +
            "end \n" +
            "" +
            "";
    /////////////////////////////////////

    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent( droolsSource, ResourceType.DRL );

    Results res = kieHelper.verify();
    assertEquals( 1, res.getMessages( Message.Level.ERROR ).size() );
}