org.kie.api.builder.ReleaseId Java Examples
The following examples show how to use
org.kie.api.builder.ReleaseId.
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: KieRepositoryTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testLoadingNotAKJar() { // DROOLS-1351 ClassLoader cl = Thread.currentThread().getContextClassLoader(); URLClassLoader urlClassLoader = new URLClassLoader( new URL[]{this.getClass().getResource( "/only-jar-pojo-not-kjar-no-kmodule-1.0.0.jar" )} ); Thread.currentThread().setContextClassLoader( urlClassLoader ); try { KieServices ks = KieServices.Factory.get(); KieRepository kieRepository = ks.getRepository(); ReleaseId releaseId = ks.newReleaseId( "org.test", "only-jar-pojo-not-kjar-no-kmodule", "1.0.0" ); KieModule kieModule = kieRepository.getKieModule( releaseId ); assertNull( kieModule ); } finally { Thread.currentThread().setContextClassLoader( cl ); } }
Example #2
Source File: KieBuilderTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testOnDisc() throws ClassNotFoundException, InterruptedException, IOException { String namespace = "org.kie.test"; KieModuleModel kProj = createKieProject(namespace); ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "memory", "1.0"); KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem(); generateAll(kfs, namespace, releaseId, kProj); MemoryFileSystem mfs = ((KieFileSystemImpl)kfs).asMemoryFileSystem(); File file = fileManager.getRootDirectory() ; mfs.writeAsFs( file ); createAndTestKieContainer(releaseId, createKieBuilder(kfs), namespace); }
Example #3
Source File: SecurityPolicyTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testSerializationUntrustedMvelConsequence() throws Exception { String drl = "package org.foo.bar\n" + "rule R1 dialect \"mvel\" when\n" + "then\n" + " System.exit(0);" + "end\n"; try { KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newByteArrayResource(drl.getBytes()) .setSourcePath("org/foo/bar/r1.drl")); ks.newKieBuilder(kfs).buildAll(); ReleaseId releaseId = ks.getRepository().getDefaultReleaseId(); KieContainer kc = ks.newKieContainer(releaseId); KieBase kbase = kc.getKieBase(); kbase = SerializationHelper.serializeObject( kbase ); } catch (Exception e) { e.printStackTrace(); fail(e.toString()); // test succeeded. the policy in place prevented the rule from executing the System.exit(). } }
Example #4
Source File: DroolsAutoConfiguration.java From spring-boot-starter-drools with MIT License | 6 votes |
@Bean @ConditionalOnMissingBean(KieContainer.class) public KieContainer kieContainer() throws IOException { final KieRepository kieRepository = getKieServices().getRepository(); kieRepository.addKieModule(new KieModule() { public ReleaseId getReleaseId() { return kieRepository.getDefaultReleaseId(); } }); KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem()); kieBuilder.buildAll(); return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId()); }
Example #5
Source File: KieHelloWorldTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testHelloWorldWithPackages() throws Exception { KieServices ks = KieServices.Factory.get(); ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0"); KieFileSystem kfs = ks.newKieFileSystem() .generateAndWritePomXML( releaseId ) .write( "src/main/resources/KBase1/org/pkg1/r1.drl", createDrl( "org.pkg1", "R1" ) ) .write( "src/main/resources/KBase1/org/pkg2/r2.drl", createDrl( "org.pkg2", "R2" ) ) .writeKModuleXML( createKieProjectWithPackages( ks, "org.pkg1" ).toXML() ); ks.newKieBuilder( kfs ).buildAll(); KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1"); ksession.insert(new Message("Hello World")); int count = ksession.fireAllRules(); assertEquals( 1, count ); }
Example #6
Source File: DslExpansionTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testDSLExpansion_MessageImplNPE() throws Exception { final KieServices ks = KieServices.Factory.get(); final ReleaseId releaseId = ks.newReleaseId( "org.kie", "dsl-test", "1.0" ); final KieModuleModel kproj = ks.newKieModuleModel(); final KieFileSystem kfs = ks.newKieFileSystem(); kfs.writeKModuleXML( kproj.toXML() ) .writePomXML( generatePomXml( releaseId ) ) .write( "src/main/resources/KBase1/test-dsl.dsl", createDSL() ) .write( "src/main/resources/KBase1/test-rule.dslr", createDRL() ); final KieBuilder kieBuilder = ks.newKieBuilder( kfs ); final List<Message> messages = kieBuilder.buildAll().getResults().getMessages(); if ( !messages.isEmpty() ) { for ( final Message m : messages ) { System.out.println( m.getText() ); } } assertTrue( messages.isEmpty() ); }
Example #7
Source File: DslExpansionTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testDSLExpansion_NoExpansion() throws Exception { final KieServices ks = KieServices.Factory.get(); final ReleaseId releaseId = ks.newReleaseId( "org.kie", "dsl-test", "1.0" ); final KieModuleModel kproj = ks.newKieModuleModel(); final KieFileSystem kfs = ks.newKieFileSystem(); kfs.writeKModuleXML( kproj.toXML() ) .writePomXML( generatePomXml( releaseId ) ) .write( "src/main/resources/KBase1/test-dsl.dsl", createDSL() ) .write( "src/main/resources/KBase1/test-rule.drl", createDRL() ); final KieBuilder kieBuilder = ks.newKieBuilder( kfs ); final List<Message> messages = kieBuilder.buildAll().getResults().getMessages(); if ( !messages.isEmpty() ) { for ( final Message m : messages ) { System.out.println( m.getText() ); } } assertFalse( messages.isEmpty() ); }
Example #8
Source File: KieModuleKieProject.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public Map<String, KieBaseModel> updateToModule(InternalKieModule updatedKieModule) { Map<String, KieBaseModel> oldKieBaseModels = new HashMap<String, KieBaseModel>(); oldKieBaseModels.putAll( kBaseModels ); this.kieModules = null; this.kJarFromKBaseName.clear(); ReleaseId currentReleaseId = this.kieModule.getReleaseId(); ReleaseId updatingReleaseId = updatedKieModule.getReleaseId(); if (currentReleaseId.getGroupId().equals(updatingReleaseId.getGroupId()) && currentReleaseId.getArtifactId().equals(updatingReleaseId.getArtifactId())) { this.kieModule = updatedKieModule; } else if (this.kieModule.getKieDependencies().keySet().contains(updatingReleaseId)) { this.kieModule.addKieDependency(updatedKieModule); } synchronized (this) { cleanIndex(); init(); // this might override class definitions, not sure we can do it any other way though // reset resource provider so it will serve resources from updated kmodule this.cl.setResourceProvider(kieModule.createResourceProvider()); } return oldKieBaseModels; }
Example #9
Source File: CommonTestMethodBase.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public static byte[] createKJar(KieServices ks, KieModuleModel kproj, ReleaseId releaseId, String pom, String... drls) { KieFileSystem kfs = ks.newKieFileSystem(); if (kproj != null) { kfs.writeKModuleXML(kproj.toXML()); } if (pom != null) { kfs.write("pom.xml", pom); } else { kfs.generateAndWritePomXML(releaseId); } for (int i = 0; i < drls.length; i++) { if (drls[i] != null) { kfs.write("src/main/resources/r" + i + ".drl", drls[i]); } } return buildKJar(ks, kfs, releaseId); }
Example #10
Source File: KieServicesTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testDisposeClearTheIDReference() { ReleaseId releaseId = ks.newReleaseId("org.kie", "test-delete", "1.0.0"); createAndDeployJar( ks, releaseId, createDRL("ruleA") ); KieContainer c1 = ks.newKieContainer("id1", releaseId); try { ks.newKieClasspathContainer("id1"); fail("should not allow repeated container IDs."); } catch (IllegalStateException is) { // ok. } ((KieContainerImpl) c1).dispose(); ks.newKieClasspathContainer("id1"); // now OK. }
Example #11
Source File: KieContainerTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testGetDefaultKieSessionModelEmptyKmodule() { KieServices kieServices = KieServices.Factory.get(); String drl = "package org.drools.test\n" + "rule R1 when\n" + " $m : Object()\n" + "then\n" + "end\n"; Resource resource = kieServices.getResources().newReaderResource( new StringReader( drl), "UTF-8" ); resource.setTargetPath("org/drools/test/rules.drl"); String kmodule = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + "</kmodule>"; // Create an in-memory jar for version 1.0.0 ReleaseId releaseId = kieServices.newReleaseId("org.kie", "test-testGetDefaultKieSessionModelEmptyKmodule", "1.0.0"); createAndDeployJar(kieServices, kmodule, releaseId, resource); KieContainer kieContainer = kieServices.newKieContainer(releaseId); KieSessionModel sessionModel = kieContainer.getKieSessionModel(null); assertNotNull(sessionModel); }
Example #12
Source File: KieBuilderTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testNoPomXml() throws ClassNotFoundException, InterruptedException, IOException { String namespace = "org.kie.test"; KieModuleModel kProj = createKieProject( namespace ); ReleaseId releaseId = KieServices.Factory.get().getRepository().getDefaultReleaseId(); KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem(); generateKProjectXML( kfs, namespace, kProj ); generateMessageClass( kfs, namespace ); generateRule( kfs, namespace ); MemoryFileSystem mfs = ((KieFileSystemImpl)kfs).asMemoryFileSystem(); createAndTestKieContainer( releaseId, createKieBuilder( kfs ), namespace ); }
Example #13
Source File: KieRepositoryTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testLoadKjarFromClasspath() { // DROOLS-1335 ClassLoader cl = Thread.currentThread().getContextClassLoader(); URLClassLoader urlClassLoader = new URLClassLoader( new URL[]{this.getClass().getResource( "/kie-project-simple-1.0.0.jar" )} ); Thread.currentThread().setContextClassLoader( urlClassLoader ); try { KieServices ks = KieServices.Factory.get(); KieRepository kieRepository = ks.getRepository(); ReleaseId releaseId = ks.newReleaseId( "org.test", "kie-project-simple", "1.0.0" ); KieModule kieModule = kieRepository.getKieModule( releaseId ); assertNotNull( kieModule ); assertEquals( releaseId, kieModule.getReleaseId() ); } finally { Thread.currentThread().setContextClassLoader( cl ); } }
Example #14
Source File: KieRepositoryImpl.java From kogito-runtimes with Apache License 2.0 | 6 votes |
synchronized KieModule remove(ReleaseId releaseId) { KieModule removedKieModule = null; String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId(); ComparableVersion comparableVersion = new ComparableVersion(releaseId.getVersion()); NavigableMap<ComparableVersion, KieModule> artifactMap = kieModules.get(ga); if (artifactMap != null) { removedKieModule = artifactMap.remove(comparableVersion); if (artifactMap.isEmpty()) { kieModules.remove(ga); } oldKieModules.remove(releaseId); } return removedKieModule; }
Example #15
Source File: DynamicRuleLoadTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testKJarUpgrade() throws Exception { // DROOLS-919 KieServices ks = KieServices.Factory.get(); // Create an in-memory jar for version 1.0.0 ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade", "1.0.0" ); KieModule km = createAndDeployJar( ks, releaseId1, drl1, drl2_1 ); // Create a session and fire rules kieContainer = ks.newKieContainer( km.getReleaseId() ); ksession = kieContainer.newKieSession(); ksession.setGlobal( "test", this ); ksession.insert( new Message( "Hi Universe" ) ); ksession.fireAllRules(); assertTrue( done ); }
Example #16
Source File: KieBuilderTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testJavaSourceFileAndDrlDeploy() { final String java = "package org.drools.compiler;\n" + "public class JavaSourceMessage { }\n"; final String drl = "package org.drools.compiler;\n" + "import org.drools.compiler.JavaSourceMessage;" + "rule R1 when\n" + " $m : JavaSourceMessage()\n" + "then\n" + "end\n"; final String kmodule = "<kmodule xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + " <kbase name=\"kbase1\">\n" + " <ksession name=\"ksession1\" default=\"true\"/>\n" + " </kbase>\n" + "</kmodule>"; final KieServices ks = KieServices.Factory.get(); final ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-kie-builder", "1.0.0" ); final Resource javaResource = ResourceFactory.newByteArrayResource( java.getBytes() ).setResourceType( ResourceType.JAVA ) .setSourcePath( "org/drools/compiler/JavaSourceMessage.java" ); final Resource drlResource = ResourceFactory.newByteArrayResource( drl.getBytes() ).setResourceType( ResourceType.DRL ) .setSourcePath( "kbase1/drl1.drl" ); final KieModule km = createAndDeployJar( ks, kmodule, releaseId1, javaResource, drlResource); final KieContainer kieContainer = ks.newKieContainer(km.getReleaseId()); try { final Class<?> messageClass = kieContainer.getClassLoader().loadClass("org.drools.compiler.JavaSourceMessage"); assertNotNull(messageClass); } catch (final ClassNotFoundException e) { throw new IllegalStateException("Loading the java class failed.", e); } }
Example #17
Source File: ReleaseIdTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testDecendingSort() { List<ReleaseId> list = newUnsortedList(); list.sort(new ReleaseIdComparator(DESCENDING)); assertSame(gav7, list.get(0)); assertSame(gav6, list.get(1)); assertSame(gav5, list.get(2)); assertSame(gav4, list.get(3)); assertSame(gav3, list.get(4)); assertSame(gav2, list.get(5)); assertSame(gav1, list.get(6)); assertSame(gav0, list.get(7)); }
Example #18
Source File: KieContainerImpl.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Results updateToVersion(ReleaseId newReleaseId) { checkNotClasspathKieProject(); Results results = update(((KieModuleKieProject) kProject).getInternalKieModule(), newReleaseId); if (results != null) { containerReleaseId = newReleaseId; } else { results = new ResultsImpl(); ( (ResultsImpl) results ).addMessage( Message.Level.ERROR, null, "Cannot find KieModule with ReleaseId: " + newReleaseId ); } return results; }
Example #19
Source File: ReleaseIdImpl.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public static ReleaseId fromPropertiesStream( InputStream stream, String path ) { Properties props = new Properties(); try { props.load(stream); return getReleaseIdFromProperties(props, path); } catch (IOException e) { throw new RuntimeException("pom.properties was malformed\n" + path, e); } }
Example #20
Source File: WireChannelTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private void build(KieServices ks, ReleaseId releaseId) throws IOException { KieModuleModel kproj = ks.newKieModuleModel(); KieSessionModel ksession1 = kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setDefault(true); ksession1.newChannelModel("testChannel", RecordingChannel.class.getName()); KieFileSystem kfs = ks.newKieFileSystem(); kfs.writeKModuleXML(kproj.toXML()) .writePomXML( generatePomXml(releaseId) ) .write("src/main/resources/KBase1/rules.drl", createDRL()); KieBuilder kieBuilder = ks.newKieBuilder(kfs); assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty()); }
Example #21
Source File: ListenersTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
/** * Inserts a new KieModule containing single KieBase and a stateful and stateless KieSessions with listeners * into KieRepository. * * @return created KIE module ReleaseId */ private ReleaseId prepareKieModule() { final KieServices ks = KieServices.Factory.get(); KieModuleModel module = ks.newKieModuleModel(); KieBaseModel baseModel = module.newKieBaseModel("defaultKBase"); baseModel.setDefault(true); baseModel.addPackage("*"); KieSessionModel sessionModel = baseModel.newKieSessionModel("defaultKSession"); sessionModel.setDefault(true); sessionModel.setType(KieSessionModel.KieSessionType.STATEFUL); sessionModel.newListenerModel(MarkingAgendaEventListener.class.getName(), ListenerModel.Kind.AGENDA_EVENT_LISTENER); sessionModel.newListenerModel(MarkingRuntimeEventListener.class.getName(), ListenerModel.Kind.RULE_RUNTIME_EVENT_LISTENER); KieSessionModel statelessSessionModel = baseModel.newKieSessionModel("defaultStatelessKSession"); statelessSessionModel.setDefault(true); statelessSessionModel.setType(KieSessionModel.KieSessionType.STATELESS); statelessSessionModel.newListenerModel(MarkingAgendaEventListener.class.getName(), ListenerModel.Kind.AGENDA_EVENT_LISTENER); statelessSessionModel.newListenerModel(MarkingRuntimeEventListener.class.getName(), ListenerModel.Kind.RULE_RUNTIME_EVENT_LISTENER); KieFileSystem kfs = ks.newKieFileSystem(); kfs.writeKModuleXML(module.toXML()); kfs.generateAndWritePomXML(RELEASE_ID); kfs.write("src/main/resources/" + PACKAGE_PATH + "/test.drl", ResourceFactory.newByteArrayResource(DRL.getBytes())); KieBuilder builder = ks.newKieBuilder(kfs).buildAll(); assertEquals(0, builder.getResults().getMessages().size(), "Unexpected compilation errors"); ks.getRepository().addKieModule(builder.getKieModule()); return RELEASE_ID; }
Example #22
Source File: RulesManager.java From hacep with Apache License 2.0 | 5 votes |
public KieContainer newKieContainer(String version) { ReleaseId releaseId = kieServices.newReleaseId( rulesConfiguration.getGroupId(), rulesConfiguration.getArtifactId(), StringUtils.isEmpty(version) ? rulesConfiguration.getVersion() : version); return kieServices.newKieContainer(releaseId); }
Example #23
Source File: SecurityPolicyTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testUntrustedMVELSalience() throws Exception { String drl = "package org.foo.bar\n" + "import "+MaliciousExitHelper.class.getName().replace('$', '.')+" \n" + "rule R1 dialect \"mvel\" salience( MaliciousExitHelper.exit() ) \n" + "when\n" + "then\n" + "end\n"; try { KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newByteArrayResource(drl.getBytes()) .setSourcePath("org/foo/bar/r1.drl")); ks.newKieBuilder(kfs).buildAll(); ReleaseId releaseId = ks.getRepository().getDefaultReleaseId(); KieContainer kc = ks.newKieContainer(releaseId); KieSession ksession = kc.newKieSession(); ksession.fireAllRules(); fail("The security policy for the rule should have prevented this from executing..."); } catch (PropertyAccessException e) { // weak way of testing but couldn't find a better way if( e.toString().contains( "The security policy should have prevented" ) ) { fail("The security policy for the rule should have prevented this from executing..."); } else { // test succeeded } } }
Example #24
Source File: RulesConfigurationTestImpl.java From hacep with Apache License 2.0 | 5 votes |
public static RulesConfigurationTestImpl buildRulesWithRetract() { try { ReleaseId releaseId = KieServices.Factory.get().newReleaseId("it.redhat.jdg.retract", "rules", "1.0.0"); KieAPITestUtils.buildReleaseFromTemplates(releaseId, "rules/complex-retract-rule.drl"); return new RulesConfigurationTestImpl("kbase-test", "ksession-test", "it.redhat.jdg.retract", "rules", "1.0.0"); } catch (Exception e) { throw new RuntimeException(e); } }
Example #25
Source File: ClasspathKieProject.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private static InternalKieModule fetchKModule(URL url, String fixedURL) { if ( url.getPath().endsWith("-spring.xml")) { // the entire kmodule creation is happening in the kie-spring module, // hence we force a null return fetchKModuleFromSpring(url); return null; } KieModuleModel kieProject = KieModuleModelImpl.fromXML( url ); setDefaultsforEmptyKieModule(kieProject); String pomProperties = getPomProperties( fixedURL ); if (pomProperties == null) { log.warn("Cannot find maven pom properties for this project. Using the container's default ReleaseId"); } ReleaseId releaseId = pomProperties != null ? ReleaseIdImpl.fromPropertiesString(pomProperties) : KieServices.get().getRepository().getDefaultReleaseId(); String rootPath = fixedURL; if ( rootPath.lastIndexOf( ':' ) > 0 ) { rootPath = IoUtils.asSystemSpecificPath( rootPath, rootPath.lastIndexOf( ':') ); } return createInternalKieModule(kieProject, releaseId, rootPath); }
Example #26
Source File: KieBuilderTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testOldXsdTargetNamespace() { final String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n"; final String kmodule = "<kmodule xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + " <kbase name=\"kbase1\">\n" + " <ksession name=\"ksession1\" default=\"true\"/>\n" + " </kbase>\n" + "</kmodule>"; final KieServices ks = KieServices.Factory.get(); // Create an in-memory jar for version 1.0.0 final ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-kie-builder", "1.0.0" ); final Resource r1 = ResourceFactory.newByteArrayResource( drl1.getBytes() ).setResourceType( ResourceType.DRL ).setSourcePath( "kbase1/drl1.drl" ); final KieModule km = createAndDeployJar( ks, kmodule, releaseId1, r1); ks.newKieContainer( km.getReleaseId() ); }
Example #27
Source File: KieHelloWorldTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testHelloWorldOnVersionRange() throws Exception { KieServices ks = KieServices.Factory.get(); buildVersion(ks, "Hello World", "1.0"); buildVersion(ks, "Aloha Earth", "1.1"); buildVersion(ks, "Hi Universe", "1.2"); ReleaseId latestReleaseId = ks.newReleaseId("org.kie", "hello-world", "LATEST"); KieSession ksession = ks.newKieContainer(latestReleaseId).newKieSession("KSession1"); ksession.insert(new Message("Hello World")); assertEquals( 0, ksession.fireAllRules() ); ksession = ks.newKieContainer(latestReleaseId).newKieSession("KSession1"); ksession.insert(new Message("Hi Universe")); assertEquals( 1, ksession.fireAllRules() ); ReleaseId releaseId1 = ks.newReleaseId("org.kie", "hello-world", "1.0"); ksession = ks.newKieContainer(releaseId1).newKieSession("KSession1"); ksession.insert(new Message("Hello World")); assertEquals( 1, ksession.fireAllRules() ); ksession = ks.newKieContainer(releaseId1).newKieSession("KSession1"); ksession.insert(new Message("Hi Universe")); assertEquals( 0, ksession.fireAllRules() ); ReleaseId releaseId2 = ks.newReleaseId("org.kie", "hello-world", "[1.0,1.2)"); ksession = ks.newKieContainer(releaseId2).newKieSession("KSession1"); ksession.insert(new Message("Aloha Earth")); assertEquals( 1, ksession.fireAllRules() ); ksession = ks.newKieContainer(releaseId2).newKieSession("KSession1"); ksession.insert(new Message("Hi Universe")); assertEquals( 0, ksession.fireAllRules() ); }
Example #28
Source File: CommonTestMethodBase.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public static byte[] buildKJar(KieServices ks, KieFileSystem kfs, ReleaseId releaseId) { KieBuilder kb = ks.newKieBuilder(kfs).buildAll(); if (kb.getResults().hasMessages(Message.Level.ERROR)) { for (Message result : kb.getResults().getMessages()) { System.out.println(result.getText()); } return null; } InternalKieModule kieModule = (InternalKieModule) ks.getRepository() .getKieModule(releaseId); byte[] jar = kieModule.getBytes(); return jar; }
Example #29
Source File: SimulateTestBase.java From kogito-runtimes with Apache License 2.0 | 5 votes |
protected ReleaseId createKJar(String... pairs) throws IOException { KieServices ks = KieServices.Factory.get(); KieModuleModel kproj = ks.newKieModuleModel(); KieFileSystem kfs = ks.newKieFileSystem(); for ( int i = 0; i < pairs.length; i += 2 ) { String id = pairs[i]; String rule = pairs[i + 1]; kfs.write( "src/main/resources/" + id.replaceAll( "\\.", "/" ) + "/rule" + i + ".drl", rule ); KieBaseModel kBase1 = kproj.newKieBaseModel( id ) .setEqualsBehavior( EqualityBehaviorOption.EQUALITY ) .setEventProcessingMode( EventProcessingOption.STREAM ) .addPackage( id ); KieSessionModel ksession1 = kBase1.newKieSessionModel(id + ".KSession1") .setType(KieSessionModel.KieSessionType.STATEFUL) .setClockType(ClockTypeOption.get("pseudo")); } kfs.writeKModuleXML(kproj.toXML()); // buildAll() automatically adds the module to the kieRepository KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(); assertTrue(kieBuilder.getResults().getMessages().isEmpty()); KieModule kieModule = kieBuilder.getKieModule(); return kieModule.getReleaseId(); }
Example #30
Source File: KieFileSystemScannerTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testDoNotUpgradeOnOlderVersion() throws Exception { Path tempDir = Files.createTempDirectory(FileSystems.getDefault().getPath("./target"), null); File file2 = null; try { KieServices ks = KieServices.Factory.get(); ReleaseId releaseIdNew = ks.newReleaseId( "org.kie", "scanner-test", "1.1.0" ); ReleaseId releaseIdOld = ks.newReleaseId( "org.kie", "scanner-test", "1.0.0" ); createKieJar( ks, releaseIdNew, "R1" ); KieContainer kieContainer = ks.newKieContainer( releaseIdNew ); KieSession ksession = kieContainer.newKieSession(); checkKSession( ksession, "R1" ); KieScanner scanner = ks.newKieScanner( kieContainer, tempDir.toString() ); file2 = write( createKieJar( ks, releaseIdOld, "R2" ), tempDir, releaseIdOld ); scanner.scanNow(); ksession = kieContainer.newKieSession(); checkKSession( ksession, "R1" ); } finally { if (file2 != null) { file2.delete(); } Files.delete(tempDir); } }