@Test public void testKieMarshaller() throws Exception { final KieServices ks = KieServices.Factory.get(); final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0"); KieHelper.createAndDeployJar(ks, v100, wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()))); KieContainer kieContainer = ks.newKieContainer(v100); KieSession kieSession = kieContainer.newKieSession(); KieBase kieBase = kieSession.getKieBase(); DMNRuntime runtime = kieSession.getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); check0001_input_data_string(runtime); KieMarshallers kieMarshallers = ks.getMarshallers(); Marshaller marshaller = kieMarshallers.newMarshaller(kieBase); ByteArrayOutputStream baos = new ByteArrayOutputStream(); marshaller.marshall(baos, kieSession); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); baos.close(); kieSession = marshaller.unmarshall(bais); bais.close(); runtime = kieSession.getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); check0001_input_data_string(runtime); }
@Test public void testUpgrade() throws Exception { final KieServices ks = KieServices.Factory.get(); final ReleaseId releaseId_v10 = ks.newReleaseId("org.kie", "dmn-test-PR1997", "1.0"); KieHelper.createAndDeployJar(ks, releaseId_v10, wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("/org/kie/dmn/core/incrementalcompilation/v1/20180731-pr1997.dmn", this.getClass()) .setTargetPath("20180731-pr1997.dmn"), ks.getResources().newClassPathResource("/org/kie/dmn/core/incrementalcompilation/v1/Person.java", this.getClass()) .setTargetPath("acme/Person.java"))); final KieContainer kieContainer = ks.newKieContainer(releaseId_v10); final DMNRuntime runtime = DMNRuntimeUtil.typeSafeGetKieRuntime(kieContainer); checkTestUpgrade(kieContainer, runtime, "setFirstName", "setLastName", "Hello John Doe, your age is: 47"); final ReleaseId releaseId_v11 = ks.newReleaseId("org.kie", "dmn-test-PR1997", "1.1"); KieHelper.createAndDeployJar(ks, releaseId_v11, wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("/org/kie/dmn/core/incrementalcompilation/v2/20180731-pr1997.dmn", this.getClass()) .setTargetPath("20180731-pr1997.dmn"), ks.getResources().newClassPathResource("/org/kie/dmn/core/incrementalcompilation/v2/Person.java", this.getClass()) .setTargetPath("acme/Person.java"))); kieContainer.updateToVersion(releaseId_v11); checkTestUpgrade(kieContainer, runtime, "setFN", "setLN", "UPGRADED Hello John Doe, your age is: 47"); }
@Test public void testFromClonedKiePackage() { final KieServices ks = KieServices.Factory.get(); final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0"); KieHelper.createAndDeployJar(ks, v100, wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()))); KieContainer kieContainer = ks.newKieContainer(v100); DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); kieContainer.dispose(); kieContainer = ks.newKieContainer(v100); runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); }
@Test public void testFromClonedKiePackageThenUpgrade() { final KieServices ks = KieServices.Factory.get(); final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0"); KieHelper.createAndDeployJar(ks, v100, wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()))); KieContainer kieContainer = ks.newKieContainer(v100); DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); kieContainer.dispose(); kieContainer = ks.newKieContainer(v100); runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); final ReleaseId v101 = ks.newReleaseId("org.kie", "dmn-test", "1.0.1"); final Resource newClassPathResource = ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass()); newClassPathResource.setTargetPath("0001-input-data-string.dmn"); KieHelper.createAndDeployJar(ks, v101, wrapWithDroolsModelResource(ks, newClassPathResource)); final Results updateResults = kieContainer.updateToVersion(v101); assertThat(updateResults.hasMessages(Level.ERROR), is(false)); runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); }
@Test public void testRemoveAndAddSomething() { final KieServices ks = KieServices.Factory.get(); final KieContainer kieContainer = KieHelper.getKieContainer( ks.newReleaseId("org.kie", "dmn-test", "1.0.0"), wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()))); DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); check0001_input_data_string(runtime); final ReleaseId v101 = ks.newReleaseId("org.kie", "dmn-test", "1.0.1"); KieHelper.createAndDeployJar(ks, v101, wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass()))); final Results updateResults = kieContainer.updateToVersion(v101); assertThat(updateResults.hasMessages(Level.ERROR), is(false)); runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); final DMNContext dmnContext2 = runtime.newContext(); dmnContext2.set("Full Name", "John Doe"); final DMNResult evaluateAll2 = runtime.evaluateAll(runtime.getModels().get(0), dmnContext2); assertThat(evaluateAll2.getDecisionResultByName("Greeting Message").getResult(), is("Salve John Doe")); }
@Test public void testReplace() { final KieServices ks = KieServices.Factory.get(); final KieContainer kieContainer = KieHelper.getKieContainer( ks.newReleaseId("org.kie", "dmn-test", "1.0.0"), wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()))); DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); check0001_input_data_string(runtime); final ReleaseId v101 = ks.newReleaseId("org.kie", "dmn-test", "1.0.1"); final Resource newClassPathResource = ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass()); newClassPathResource.setTargetPath("0001-input-data-string.dmn"); KieHelper.createAndDeployJar(ks, v101, wrapWithDroolsModelResource(ks, newClassPathResource)); final Results updateResults = kieContainer.updateToVersion(v101); assertThat(updateResults.hasMessages(Level.ERROR), is(false)); runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); final DMNContext dmnContext2 = runtime.newContext(); dmnContext2.set("Full Name", "John Doe"); final DMNResult evaluateAll2 = runtime.evaluateAll(runtime.getModels().get(0), dmnContext2); assertThat(evaluateAll2.getDecisionResultByName("Greeting Message").getResult(), is("Salve John Doe")); }
@Test public void test_as_kie_wb_common_services_backend_Builder() throws Exception { final KieServices ks = KieServices.Factory.get(); final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0"); final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()))); final KieContainer kieContainer = ks.newKieContainer(v100); final KieSession kieSession = kieContainer.newKieSession(); final DMNRuntime runtime = kieSession.getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); check0001_input_data_string(runtime); // the below is performed by the WB at: https://github.com/kiegroup/kie-wb-common/blob/master/kie-wb-common-services/kie-wb-common-services-backend/src/main/java/org/kie/workbench/common/services/backend/builder/core/Builder.java#L592 final KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieModule, null); final KieContainer kieContainer2 = new KieContainerImpl(kieProject, ks.getRepository(), v100); final KieSession kieSession2 = kieContainer2.newKieSession(); // exhibit the issue. final DMNRuntime runtime2 = kieSession2.getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime2); assertThat(runtime2.getModels(), hasSize(1)); check0001_input_data_string(runtime2); }
@Test public void test_as_kie_wb_common_services_backend_Builder2() throws Exception { final KieServices ks = KieServices.Factory.get(); final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0"); final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, wrapWithDroolsModelResource(ks, ks.getResources().newClassPathResource("v1_2/dmn-hotcold.dmn", this.getClass()))); final KieContainer kieContainer = ks.newKieContainer(v100); final KieSession kieSession = kieContainer.newKieSession(); final DMNRuntime runtime = kieSession.getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime); assertThat(runtime.getModels(), hasSize(1)); checkDMNHotColdDMN12WithNSScattered(runtime); // the below is performed by the WB at: https://github.com/kiegroup/kie-wb-common/blob/master/kie-wb-common-services/kie-wb-common-services-backend/src/main/java/org/kie/workbench/common/services/backend/builder/core/Builder.java#L592 final KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieModule, null); final KieContainer kieContainer2 = new KieContainerImpl(kieProject, ks.getRepository(), v100); final KieSession kieSession2 = kieContainer2.newKieSession(); // exhibit the issue. final DMNRuntime runtime2 = kieSession2.getKieRuntime(DMNRuntime.class); Assert.assertNotNull(runtime2); assertThat(runtime2.getModels(), hasSize(1)); checkDMNHotColdDMN12WithNSScattered(runtime2); }
final Resource newClassPathResource = ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass()); newClassPathResource.setTargetPath("0001-input-data-string.dmn"); KieHelper.createAndDeployJar(ks, v101, wrapWithDroolsModelResource(ks, newClassPathResource));