/
ActivationGroupIntegrationTest.java
91 lines (69 loc) · 3.71 KB
/
ActivationGroupIntegrationTest.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
82
83
84
85
86
87
88
89
90
91
package org.kie.server.integrationtests.drools;
import java.util.ArrayList;
import java.util.List;
import org.drools.core.command.runtime.rule.ClearActivationGroupCommand;
import org.junit.BeforeClass;
import org.junit.Test;
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;
public class ActivationGroupIntegrationTest extends DroolsKieServerBaseIntegrationTest {
private static ReleaseId releaseId = new ReleaseId("org.kie.server.testing", "activation-group",
"1.0.0.Final");
private static final String CONTAINER_ID = "activation";
private static final String LIST_NAME = "list";
private static final String LIST_OUTPUT_NAME = "output-list";
private static final String KIE_SESSION = "ksession1";
private static final String ACTIVATION_GROUP = "first-group";
@BeforeClass
public static void buildAndDeployArtifacts() {
KieServerDeployer.buildAndDeployCommonMavenParent();
KieServerDeployer.buildAndDeployMavenProjectFromResource("/kjars-sources/activation-group");
createContainer(CONTAINER_ID, releaseId);
}
/**
* First rule in activation group "First group" is executed, second rule skipped.
*/
@Test
public void testActivationGroup() {
List<Command<?>> commands = new ArrayList<Command<?>>();
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KIE_SESSION);
commands.add(commandsFactory.newSetGlobal(LIST_NAME, new ArrayList<String>(), LIST_OUTPUT_NAME));
commands.add(commandsFactory.newFireAllRules());
commands.add(commandsFactory.newGetGlobal(LIST_NAME, LIST_OUTPUT_NAME));
ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
KieServerAssert.assertSuccess(response);
ExecutionResults result = response.getResult();
List<?> outcome = (List<?>) result.getValue(LIST_OUTPUT_NAME);
assertNotNull(outcome);
assertEquals(2, outcome.size());
assertEquals("First rule in first activation group executed", outcome.get(0));
assertEquals("Rule without activation group executed", outcome.get(1));
}
/**
* Activation group "First group" is cleared, so it isn't executed.
*/
@Test
public void testClearActivationGroup() {
List<Command<?>> commands = new ArrayList<Command<?>>();
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KIE_SESSION);
commands.add(commandsFactory.newSetGlobal(LIST_NAME, new ArrayList<String>(), LIST_OUTPUT_NAME));
// Replace if/after Clear command is added to command factory.
// commands.add(commandsFactory.newClearActivationGroup(ACTIVATION_GROUP));
commands.add(new ClearActivationGroupCommand(ACTIVATION_GROUP));
commands.add(commandsFactory.newFireAllRules());
commands.add(commandsFactory.newGetGlobal(LIST_NAME, LIST_OUTPUT_NAME));
ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
KieServerAssert.assertSuccess(response);
ExecutionResults result = response.getResult();
List<?> outcome = (List<?>) result.getValue(LIST_OUTPUT_NAME);
assertNotNull(outcome);
assertEquals(1, outcome.size());
assertEquals("Rule without activation group executed", outcome.get(0));
}
}