org.kie.api.builder.Results Java Examples

The following examples show how to use org.kie.api.builder.Results. 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: 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 #2
Source File: CommonTestMethodBase.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public static byte[] createJar(KieServices ks, String kmoduleContent, Predicate<String> classFilter, ReleaseId releaseId, Resource... resources) {
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kmoduleContent);
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] != null) {
            kfs.write(resources[i]);
        }
    }
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    ((InternalKieBuilder) kieBuilder).buildAll(classFilter);
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new IllegalStateException(results.getMessages(Message.Level.ERROR).toString());
    }
    InternalKieModule kieModule = (InternalKieModule) ks.getRepository()
            .getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return jar;
}
 
Example #3
Source File: MessageImplTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
//See DROOLS-193 (KnowledgeBuilderResult does not always contain a Resource)
public void testMessageFromInvalidDSL() throws Exception {
    //Some suitably duff DSL
    String dsl = "bananna\n";

    //Some suitably valid DRL
    String drl = "import org.drools.compiler.Person;\n"
            + "rule R1\n"
            + "when\n"
            + "There is a Person\n"
            + "then\n"
            + "end\n";

    KieServices ks = KieServices.Factory.get();

    KieFileSystem kfs = ks.newKieFileSystem()
            .write( "src/main/resources/dsl.dsl", dsl )
            .write( "src/main/resources/drl.dslr", drl );

    KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();
    Results results = kieBuilder.getResults();

    assertEquals( 3,
                  results.getMessages().size() );
}
 
Example #4
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 #5
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 #6
Source File: DslTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testGreedyDsl() {
    // BZ-1078839
    String dsl = "[when]There is a number with value of {value}=i:Integer(intValue() == {value})\n"
            + "[when]There is a number with=i:Integer()\n";

    String dslr = "package org.test \n"
                 + "rule 'sample rule' \n"
                 + "when \n" + "  There is a number with value of 10\n"
                 + "then \n" + "end \n";

    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem()
                          .write("src/main/resources/r1.dslr", dslr)
                          .write("src/main/resources/r1.dsl", dsl);
    Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertEquals(0, results.getMessages().size());
}
 
Example #7
Source File: StrictAnnotationTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnknownAnnotation() {
    String str =
            "package org.simple \n" +
            "@Xyz rule yyy \n" +
            "when \n" +
            "  $s : String()\n" +
            "then \n" +
            "end  \n";

    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem()
                          .write( "src/main/resources/r1.drl", str )
                          .writeKModuleXML(ks.newKieModuleModel()
                                             .setConfigurationProperty(LanguageLevelOption.PROPERTY_NAME,
                                                                       LanguageLevelOption.DRL6_STRICT.toString())
                                             .toXML());
    Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertEquals(1, results.getMessages().size());
}
 
Example #8
Source File: StrictAnnotationTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testImportedAnnotation() {
    String str =
            "package org.simple \n" +
            "import " + Xyz.class.getCanonicalName() + " \n" +
            "@Xyz rule yyy \n" +
            "when \n" +
            "  $s : String()\n" +
            "then \n" +
            "end  \n";

    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem()
                          .write( "src/main/resources/r1.drl", str )
                          .writeKModuleXML(ks.newKieModuleModel()
                                             .setConfigurationProperty(LanguageLevelOption.PROPERTY_NAME,
                                                                       LanguageLevelOption.DRL6_STRICT.toString())
                                             .toXML());
    Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertEquals(0, results.getMessages().size());
}
 
Example #9
Source File: StrictAnnotationTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testStirctWatchWithoutQuotes() {
    String str =
            "package com.sample;\n" +
            "import " + MyClass.class.getCanonicalName() + ";\n" +
            "rule R1 when\n" +
            "    @Watch( !value ) $m : MyClass( value < 10 )\n" +
            "then \n" +
            "    modify( $m ) { setValue( $m.getValue()+1 ) };\n" +
            "end\n";

    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem()
                          .write( "src/main/resources/r1.drl", str )
                          .writeKModuleXML(ks.newKieModuleModel()
                                             .setConfigurationProperty(LanguageLevelOption.PROPERTY_NAME,
                                                                       LanguageLevelOption.DRL6_STRICT.toString())
                                             .toXML());
    Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertEquals(1, results.getMessages().size());
}
 
Example #10
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 #11
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 #12
Source File: KieSessionUtils.java    From hacep with Apache License 2.0 6 votes vote down vote up
public static void logResults(Results results) {
    for (Message result : results.getMessages()) {
        switch (result.getLevel()) {
            case ERROR:
                LOGGER.error(result.toString());
                break;
            case WARNING:
                LOGGER.warn(result.toString());
                break;
            case INFO:
                LOGGER.info(result.toString());
                break;
            default:
                LOGGER.warn(result.toString());
        }
    }
}
 
Example #13
Source File: RulesConfiguration.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Kie container.
 *
 * @return the kie container
 */
@Bean
public KieContainer kieContainer() {
	final KieServices kieServices = KieServices.Factory.get();

	final KieContainer kContainer = kieServices.getKieClasspathContainer();
	LOGGER.info("Using classloader {}, parent {}",kContainer.getClassLoader(),kContainer.getClassLoader().getParent());
	
	final Results verifyResults = kContainer.verify();
	for (final Message m : verifyResults.getMessages()) {
		LOGGER.warn("Kie container message: {}", m);
	}

	final KieBase kieBase = kContainer.getKieBase();
	for (final KiePackage kp : kieBase.getKiePackages()) {
		for (final Rule rule : kp.getRules()) {
			LOGGER.info("Loadded Rule: {} {}", kp, rule.getName());
		}
	}
	

	return kContainer;
}
 
Example #14
Source File: BaseTest.java    From iot-ocp with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    KieServices kieServices = KieServices.Factory.get();

    KieContainer kContainer = kieServices.getKieClasspathContainer();
    Results verifyResults = kContainer.verify();
    for (Message m : verifyResults.getMessages()) {
        LOG.debug("Kie container message: {}", m);
    }

    KieBase kieBase = kContainer.getKieBase();
    LOG.debug("Created kieBase");

    for ( KiePackage kp : kieBase.getKiePackages() ) {
        for (Rule rule : kp.getRules()) {
            LOG.debug("kp " + kp + " rule " + rule.getName());
        }
    }

    session = kieBase.newKieSession();
    LOG.info(session.getGlobals().toString());
    Logger kieLogger = LoggerFactory.getLogger(this.getClass());
   // session.setGlobal("logger",kieLogger);
}
 
Example #15
Source File: RulesManager.java    From hacep with Apache License 2.0 6 votes vote down vote up
public boolean updateToVersion(String version) {
    checkStatus();
    if (StringUtils.isEmpty(version)) {
        throw new IllegalArgumentException("Update to version cannot accept an empty version");
    }
    ReleaseId releaseId = kieServices.newReleaseId(
            rulesConfiguration.getGroupId(),
            rulesConfiguration.getArtifactId(),
            version);
    Results results = kieContainer.updateToVersion(releaseId);
    this.releaseId = kieContainer.getReleaseId();
    KieSessionUtils.logResults(results);
    if (results.hasMessages(Message.Level.ERROR)) {
        LOGGER.error("Update to version {} aborted due to errors", version);
        return false;
    }
    LOGGER.info("Update to version {} completed", version);
    return true;
}
 
Example #16
Source File: KieContainerImpl.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public Results updateDependencyToVersion(ReleaseId currentReleaseId, ReleaseId newReleaseId) {
    ReleaseId installedReleaseId = getReleaseId();
    if (currentReleaseId.getGroupId().equals(installedReleaseId.getGroupId()) &&
        currentReleaseId.getArtifactId().equals(installedReleaseId.getArtifactId())) {
        // upgrading the kProject itself: taking the kmodule from there
        return updateToVersion(newReleaseId);
    }

    checkNotClasspathKieProject();
    // upgrading a transitive dependency: taking the kmodule from the krepo
    // if the new and the current release are equal (a snapshot) check if there is an older version with the same releaseId
    InternalKieModule currentKM = currentReleaseId.equals(newReleaseId) ?
                                  (InternalKieModule) ((KieRepositoryImpl) kr).getOldKieModule(currentReleaseId) :
                                  (InternalKieModule) kr.getKieModule(currentReleaseId);
    return update(currentKM, newReleaseId);
}
 
Example #17
Source File: OOPathReactiveTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidDoubleNonReactivePart() {
    final String drl =
            "import org.drools.compiler.oopath.model.*;\n" +
                    "global java.util.List list\n" +
                    "\n" +
                    "rule R when\n" +
                    "  Man( $toy: /wife?/children[age > 10]?/toys )\n" +
                    "then\n" +
                    "  list.add( $toy.getName() );\n" +
                    "end\n";

    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", drl );
    final Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertTrue( results.hasMessages( Message.Level.ERROR ) );
}
 
Example #18
Source File: OOPathCastTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidCast() {
    final String drl =
            "import org.drools.compiler.oopath.model.*;\n" +
                    "global java.util.List list\n" +
                    "\n" +
                    "rule R when\n" +
                    "  Man( $toy: /wife/children#Man/toys )\n" +
                    "then\n" +
                    "  list.add( $toy.getName() );\n" +
                    "end\n";

    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", drl );
    final Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertTrue( results.hasMessages( Message.Level.ERROR ) );
}
 
Example #19
Source File: LengthSlidingWindowTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompilationFailureWithUnknownWindow() {
    // DROOLS-841
    String drl =
            "import " + StockTick.class.getCanonicalName() + "\n" +
            "global java.util.List list;\n" +
            "declare StockTick @role( event ) end\n" +
            "declare window RhtStocksWindow\n" +
            "    StockTick() over window:length( 3 )\n" +
            "end\n" +
            "rule R\n" +
            "when \n" +
            "   accumulate( StockTick( company == \"RHT\", $price : price ) from window AbcStocksWindow; $total : sum($price) )\n"  +
            "then \n" +
            "    list.add($total);\n" +
            "end \n";

    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", drl );
    Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertEquals(1, results.getMessages().size());
}
 
Example #20
Source File: QueryTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotExistingDeclarationInQuery() {
    // DROOLS-414
    String drl =
            "import org.drools.compiler.Person\n" +
            "global java.util.List persons;\n" +
            "\n" +
            "query checkLength(String $s, int $l)\n" +
            "    $s := String( length == $l )\n" +
            "end\n" +
            "\n" +
            "rule R when\n" +
            "    $i : Integer()\n" +
            "    $p : Person()\n" +
            "    checkLength( $p.name, 1 + $x + $p.age; )\n" +
            "then\n" +
            "    persons.add( $p );\n" +
            "end\n";

    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", drl );
    Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertFalse( results.getMessages().isEmpty() );
}
 
Example #21
Source File: IncrementalCompilationTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncrementalProcessCompilation() throws Exception {

    String invalidProcessDefinition = getResource( "/BPMN2-Incremental-Build-Invalid.bpmn2" );
    String validProcessDefinition = getResource( "/BPMN2-Incremental-Build-Valid.bpmn2" );

    KieServices ks = KieServices.Factory.get();

    //This process file contains 4 errors
    KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/p1.bpmn2",
                                                     invalidProcessDefinition );

    KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();
    Results results = kieBuilder.getResults();
    assertEquals( 3,
                  results.getMessages( org.kie.api.builder.Message.Level.ERROR ).size() );

    //This process file has the errors fixed
    kfs.write("src/main/resources/p1.bpmn2",
              validProcessDefinition);
    IncrementalResults addResults = ((InternalKieBuilder)kieBuilder).createFileSet("src/main/resources/p1.bpmn2").build();

    //I'd expect the 4 previous errors to be cleared
    assertEquals( 0,
                  addResults.getAddedMessages().size() );
    assertEquals( 3,
                  addResults.getRemovedMessages().size() );
}
 
Example #22
Source File: KieContainerTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateToNonExistingRelease() {
    // DROOLS-1562
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "test-release", "1.0.0");
    createAndDeployJar( ks, releaseId, createDRL("ruleA") );

    KieContainer kieContainer = ks.newKieContainer(releaseId);

    Results results = kieContainer.updateToVersion( ks.newReleaseId( "org.kie", "test-release", "1.0.1" ) );
    assertEquals( 1, results.getMessages( Level.ERROR ).size() );
    assertEquals( "1.0.0", ( (InternalKieContainer) kieContainer ).getContainerReleaseId().getVersion() );
}
 
Example #23
Source File: KnowledgeBuilderTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testMalformedDrl() throws Exception {
    // DROOLS-928
    byte[] content = new byte[]{0x04,0x44,0x00,0x00,0x60,0x00,0x00,0x00};
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", new String(content) );
    Results results = ks.newKieBuilder( kfs ).buildAll().getResults();
    assertTrue( results.getMessages().size() > 0 );
}
 
Example #24
Source File: KieBuilderTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private void checkKModule( final String kmodule, final int expectedErrors ) {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId releaseId = ks.newReleaseId( "org.kie", "test-kie-builder", "1.0.0" );
    final KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML( releaseId ).writeKModuleXML( kmodule );
    final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
    kieBuilder.buildAll();
    final Results results = kieBuilder.getResults();
    assertEquals( expectedErrors, results.getMessages( org.kie.api.builder.Message.Level.ERROR ).size() );
    assertNotNull(((InternalKieBuilder) kieBuilder ).getKieModuleIgnoringErrors());
}
 
Example #25
Source File: KieBuilderTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testReportKBuilderErrorWhenUsingAJavaClassWithNoPkg() {
    // BZ-995018
    final String java = "public class JavaClass { }\n";
    final KieServices ks = KieServices.Factory.get();

    final KieFileSystem kfs = ks.newKieFileSystem()
            .write( "src/main/java/JavaClass.java", java );

    final Results results = ks.newKieBuilder( kfs ).buildAll().getResults();

    System.out.println( results.getMessages() );

    assertEquals( 1, results.getMessages().size() );
}
 
Example #26
Source File: MessageImplTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageWithIncrementalBuild() throws Exception {
    //Some suitably duff DSL to generate errors
    String dsl1 = "bananna\n";

    //Some suitably valid DRL
    String drl1 = "import org.drools.compiler.Person;\n"
            + "rule R1\n"
            + "when\n"
            + "There is a Person\n"
            + "then\n"
            + "end\n";

    //Some suitably valid DRL
    String drl2 = "rule R2\n"
            + "when\n"
            + "then\n"
            + "end\n";

    KieServices ks = KieServices.Factory.get();

    KieFileSystem kfs = ks.newKieFileSystem()
            .write( "src/main/resources/dsl.dsl", dsl1 )
            .write( "src/main/resources/drl.dslr", drl1 );

    KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();
    Results fullBuildResults = kieBuilder.getResults();
    assertEquals( 3,
                  fullBuildResults.getMessages().size() );

    kfs.write( "src/main/resources/r2.drl", drl2 );
    IncrementalResults incrementalBuildResults = ( (InternalKieBuilder) kieBuilder ).createFileSet( "src/main/resources/r2.drl" ).build();

    assertEquals( 0, incrementalBuildResults.getAddedMessages().size() );
    assertEquals( 0, incrementalBuildResults.getRemovedMessages().size() );
}
 
Example #27
Source File: PhreakInspector.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
private void assertBuildResults(Results results) {
    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.printf("[%s] - %s[%s,%s]: %s", message.getLevel(), message.getPath(), message.getLine(), message.getColumn(), message.getText());
        }

        throw new IllegalStateException("Compilation errors were found. Check the logs.");
    }
}
 
Example #28
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 #29
Source File: KieHelper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public KieContainer getKieContainer() {
    KieBuilder kieBuilder = ks.newKieBuilder( kfs, classLoader ).buildAll();
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException(results.getMessages().toString());
    }
    KieContainer kieContainer = ks.newKieContainer( ks.getRepository().getDefaultReleaseId(), classLoader );
    return kieContainer;
}
 
Example #30
Source File: AbductionTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindNonAbductiveQueryError() {
    String droolsSource =
            "package org.drools.abductive.test; \n" +
            "" +                "" +
            "query foo() \n" +
            "end \n" +
            "rule R1 " +
            "when " +
            "   $x : foo( ) " +
            "then " +
            "end \n" +
            "";
    /////////////////////////////////////

    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write( ks.getResources()
                       .newByteArrayResource( droolsSource.getBytes() )
                       .setSourcePath( "drl1.drl" )
                       .setResourceType( ResourceType.DRL ) );
    KieBuilder kieBuilder = ks.newKieBuilder( kfs );
    kieBuilder.buildAll();

    Results res = kieBuilder.getResults();
    assertTrue( res.hasMessages( Message.Level.ERROR ) );

}