Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBPM-9774] Incorrect object type returned in a DMN business-rule task of a BPMN #1947

Merged
merged 1 commit into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions jbpm-test-coverage/src/test/java/org/jbpm/test/JbpmTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,32 @@

package org.jbpm.test;

import java.io.File;
import java.nio.file.Files;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;

import org.apache.commons.io.IOUtils;
import org.assertj.core.api.Assertions;
import org.drools.compiler.kie.builder.impl.InternalKieModule;
import org.jbpm.test.persistence.util.PersistenceUtil;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.kie.api.KieServices;
import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;
import org.kie.api.builder.Message;
import org.kie.api.builder.ReleaseId;
import org.kie.api.builder.Results;
import org.kie.api.command.KieCommands;
import org.kie.api.io.Resource;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.builder.InternalKieBuilder;
import org.kie.scanner.KieMavenRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -104,5 +117,32 @@ protected static KieCommands getCommands() {
return getServices().getCommands();
}

protected byte[] createAndDeployJar(KieServices ks, ReleaseId releaseId, Resource... resources) throws Exception {
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId);
for (int i = 0; i < resources.length; i++) {
if (resources[i] != null) {
kfs.write(resources[i]);
}
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
((InternalKieBuilder) kieBuilder).buildAll(o -> true);
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[] pomXmlContent = IOUtils.toByteArray(kieModule.getPomAsStream());
File pom = new File("target",
UUID.randomUUID().toString());
Files.write(pom.toPath(),
pomXmlContent);
KieMavenRepository.getKieMavenRepository().installArtifact(releaseId,
kieModule,
pom);

byte[] jar = kieModule.getBytes();
return jar;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright 2017 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.test.functional.task;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.jbpm.process.workitem.bpmn2.BusinessRuleTaskHandler;
import org.jbpm.test.JbpmTestCase;
import org.jbpm.test.domain.Person;
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
import org.junit.Assert;
import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.process.ProcessInstance;

/**
* Business rules task test. testing execution of rules with specified rule-flow group.
*/
public class BusinessRuleTaskTest extends JbpmTestCase {

private static final String RULE_TASK = "org/jbpm/test/functional/task/businessRuleTaskProcess.bpmn2";
private static final String RULE_TASK_ID = "org.jbpm.test.functional.task.businessRuleTask";

private static final String RULE_TASK_COLLECTION = "org/jbpm/test/functional/task/businessRuleCollectionTaskProcess.bpmn2";
private static final String RULE_TASK_COLLECTION_ID = "org.jbpm.test.functional.task.businessRuleTask";

private static final String GROUP_ID = "org.jbpm";
private static final String ARTIFACT_ID = "test-kjar";
private static final String VERSION = "1.0";

private KieServices ks = KieServices.Factory.get();

public BusinessRuleTaskTest() {
super(false);
}

@Test
public void testRuleTask() throws Exception {
// deploy external kjar
createAndDeployJar(ks,
ks.newReleaseId(GROUP_ID,
ARTIFACT_ID,
VERSION),
ks.getResources().newClassPathResource("org/jbpm/test/functional/task/buildPersonDecision.dmn"),
ks.getResources().newFileSystemResource("src/main/java/org/jbpm/test/domain/Person.java"));

// create the brt
BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID,
ARTIFACT_ID,
VERSION,0, this.getClass().getClassLoader(), this.manager);
addWorkItemHandler("BusinessRuleTask", handler);

KieSession kieSession = createKSession(RULE_TASK);
handler.setRuntimeManager(manager);

WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) kieSession.startProcess(RULE_TASK_ID);
Assert.assertTrue(pi.getVariable("person") instanceof Person);

}

@Test
public void testRuleTaskCollection() throws Exception {
// deploy external kjar
createAndDeployJar(ks,
ks.newReleaseId(GROUP_ID,
ARTIFACT_ID,
VERSION),
ks.getResources().newClassPathResource("org/jbpm/test/functional/task/buildPersonCollectionDecision.dmn"),
ks.getResources().newFileSystemResource("src/main/java/org/jbpm/test/domain/Person.java"));

// create the brt
BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID,
ARTIFACT_ID,
VERSION,0, this.getClass().getClassLoader(), this.manager);
addWorkItemHandler("BusinessRuleTask", handler);

KieSession kieSession = createKSession(RULE_TASK_COLLECTION);
handler.setRuntimeManager(manager);

WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) kieSession.startProcess(RULE_TASK_COLLECTION_ID);
Assert.assertTrue(pi.getVariable("person") instanceof List);
Assert.assertTrue(((List<Person>) pi.getVariable("person")).get(0) instanceof Person);

}

public KieSession createKSession(Map<String, ResourceType> res) {
createRuntimeManager(res);
return getRuntimeEngine().getKieSession();
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" ?>
<dmn:definitions
xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/"
xmlns="https://kiegroup.org/dmn/_DBBCAFFF-161B-4D7A-809B-320EDF3933FC"
xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
xmlns:kie="http://www.drools.org/kie/dmn/1.2"
xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/"
xmlns:dmndi="http://www.omg.org/spec/DMN/20180521/DMNDI/"
xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="_972F1166-02C5-4389-8405-224781EFCF6A" name="simple" expressionLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" namespace="https://kiegroup.org/dmn/_DBBCAFFF-161B-4D7A-809B-320EDF3933FC">
<dmn:extensionElements/>
<dmn:itemDefinition id="_B7DC43AB-5DD9-4CFC-93F9-A9F3F563C0AB" name="Person" isCollection="true">
<dmn:itemComponent id="_A8E45253-E12B-4CB8-80EE-BB2DACDA8C6C" name="age" isCollection="false">
<dmn:typeRef>number</dmn:typeRef>
</dmn:itemComponent>
<dmn:itemComponent id="_8097D6E0-01DD-410D-A189-8D69704654F2" name="name" isCollection="false">
<dmn:typeRef>string</dmn:typeRef>
</dmn:itemComponent>
</dmn:itemDefinition>
<dmn:decision id="_F3595CA0-6666-4CF3-A81A-D21870D95379" name="personBRL">
<dmn:extensionElements/>
<dmn:variable id="_828DED89-ADA3-4973-8469-95C564DF06BD" name="personBRL" typeRef="Person"/>
<dmn:literalExpression id="_90FB7F94-F7E6-4375-847A-8E6F53BB1817">
<dmn:text>[ { "name" : "john dow", age: 12 } ]</dmn:text>
</dmn:literalExpression>
</dmn:decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram id="_61093636-D97F-4D97-BEE9-E1440BD42002" name="DRG">
<di:extension>
<kie:ComponentsWidthsExtension>
<kie:ComponentWidths dmnElementRef="_90FB7F94-F7E6-4375-847A-8E6F53BB1817">
<kie:width>300</kie:width>
</kie:ComponentWidths>
</kie:ComponentsWidthsExtension>
</di:extension>
<dmndi:DMNShape id="dmnshape-drg-_F3595CA0-6666-4CF3-A81A-D21870D95379" dmnElementRef="_F3595CA0-6666-4CF3-A81A-D21870D95379" isCollapsed="false">
<dmndi:DMNStyle>
<dmndi:FillColor red="255" green="255" blue="255"/>
<dmndi:StrokeColor red="0" green="0" blue="0"/>
<dmndi:FontColor red="0" green="0" blue="0"/>
</dmndi:DMNStyle>
<dc:Bounds x="278" y="145" width="100" height="50"/>
<dmndi:DMNLabel/>
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</dmn:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" ?>
<dmn:definitions
xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/"
xmlns="https://kiegroup.org/dmn/_DBBCAFFF-161B-4D7A-809B-320EDF3933FC"
xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
xmlns:kie="http://www.drools.org/kie/dmn/1.2"
xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/"
xmlns:dmndi="http://www.omg.org/spec/DMN/20180521/DMNDI/"
xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="_972F1166-02C5-4389-8405-224781EFCF6A" name="simple" expressionLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" namespace="https://kiegroup.org/dmn/_DBBCAFFF-161B-4D7A-809B-320EDF3933FC">
<dmn:extensionElements/>
<dmn:itemDefinition id="_B7DC43AB-5DD9-4CFC-93F9-A9F3F563C0AB" name="Person" isCollection="false">
<dmn:itemComponent id="_A8E45253-E12B-4CB8-80EE-BB2DACDA8C6C" name="age" isCollection="false">
<dmn:typeRef>number</dmn:typeRef>
</dmn:itemComponent>
<dmn:itemComponent id="_8097D6E0-01DD-410D-A189-8D69704654F2" name="name" isCollection="false">
<dmn:typeRef>string</dmn:typeRef>
</dmn:itemComponent>
</dmn:itemDefinition>
<dmn:decision id="_F3595CA0-6666-4CF3-A81A-D21870D95379" name="personBRL">
<dmn:extensionElements/>
<dmn:variable id="_828DED89-ADA3-4973-8469-95C564DF06BD" name="personBRL" typeRef="Person"/>
<dmn:literalExpression id="_90FB7F94-F7E6-4375-847A-8E6F53BB1817">
<dmn:text>{ "name" : "john dow", age: 12 }</dmn:text>
</dmn:literalExpression>
</dmn:decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram id="_61093636-D97F-4D97-BEE9-E1440BD42002" name="DRG">
<di:extension>
<kie:ComponentsWidthsExtension>
<kie:ComponentWidths dmnElementRef="_90FB7F94-F7E6-4375-847A-8E6F53BB1817">
<kie:width>300</kie:width>
</kie:ComponentWidths>
</kie:ComponentsWidthsExtension>
</di:extension>
<dmndi:DMNShape id="dmnshape-drg-_F3595CA0-6666-4CF3-A81A-D21870D95379" dmnElementRef="_F3595CA0-6666-4CF3-A81A-D21870D95379" isCollapsed="false">
<dmndi:DMNStyle>
<dmndi:FillColor red="255" green="255" blue="255"/>
<dmndi:StrokeColor red="0" green="0" blue="0"/>
<dmndi:FontColor red="0" green="0" blue="0"/>
</dmndi:DMNStyle>
<dc:Bounds x="278" y="145" width="100" height="50"/>
<dmndi:DMNLabel/>
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</dmn:definitions>
Loading