/
GuidedDecisionTableIntegrationTest.java
81 lines (66 loc) · 3.27 KB
/
GuidedDecisionTableIntegrationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright 2015 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.
*
* 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.kie.server.integrationtests.drools;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.api.command.BatchExecutionCommand;
import org.kie.api.command.Command;
import org.kie.api.runtime.ExecutionResults;
import org.kie.server.api.model.ReleaseId;
import org.kie.server.api.model.ServiceResponse;
import static org.junit.Assert.*;
import org.kie.server.integrationtests.shared.KieServerAssert;
import org.kie.server.integrationtests.shared.KieServerDeployer;
import org.kie.server.integrationtests.shared.KieServerReflections;
/**
* Test used for verification of spreadsheet decision table processing.
*/
public class GuidedDecisionTableIntegrationTest extends DroolsKieServerBaseIntegrationTest {
private static ReleaseId releaseId = new ReleaseId("org.kie.server.testing", "gdst-project", "1.0.0");
private static final String CONTAINER_ID = "gdst";
private static final String PERSON_CLASS_NAME = "org.kie.server.testing.Person";
private static final String PERSON_OUT_IDENTIFIER = "person";
private static final String PERSON_NAME = "Robert";
private static final String PERSON_SURNAME_FIELD = "surname";
private static ClassLoader kjarClassLoader;
@BeforeClass
public static void buildAndDeployArtifacts() {
KieServerDeployer.buildAndDeployCommonMavenParent();
KieServerDeployer.buildAndDeployMavenProjectFromResource("/kjars-sources/gdst-project");
kjarClassLoader = KieServices.Factory.get().newKieContainer(releaseId).getClassLoader();
createContainer(CONTAINER_ID, releaseId);
}
@Override
protected void addExtraCustomClasses(Map<String, Class<?>> extraClasses) throws Exception {
extraClasses.put(PERSON_CLASS_NAME, Class.forName(PERSON_CLASS_NAME, true, kjarClassLoader));
}
@Test
public void testExecuteGuidedDecisionTableRule() {
Object person = createInstance(PERSON_CLASS_NAME, PERSON_NAME);
List<Command<?>> commands = new ArrayList<Command<?>>();
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, "kbase1.stateless");
commands.add(commandsFactory.newInsert(person, PERSON_OUT_IDENTIFIER));
commands.add(commandsFactory.newFireAllRules());
ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
KieServerAssert.assertSuccess(response);
ExecutionResults results = response.getResult();
Object value = results.getValue(PERSON_OUT_IDENTIFIER);
assertEquals("Bob", KieServerReflections.valueOf(value, PERSON_SURNAME_FIELD));
}
}