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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*-
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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.
* ============LICENSE_END=========================================================
*/
package org.onap.policy.drools.controller.internal;
import java.io.IOException;
import java.nio.file.Paths;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.builder.ReleaseId;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.util.KieUtils;
public class MavenDroolsControllerTest {
public static final String JUNIT_ECHO_KSESSION = "echo";
public static final String JUNIT_ECHO_KMODULE_DRL_PATH = "src/test/resources/echo.drl";
public static final String JUNIT_ECHO_KMODULE_POM_PATH = "src/test/resources/echo.pom";
public static final String JUNIT_ECHO_KMODULE_PATH = "src/test/resources/echo.kmodule";
public static final String JUNIT_ECHO_KJAR_DRL_PATH =
"src/main/resources/kbEcho/org/onap/policy/drools/test/echo.drl";
private static volatile ReleaseId releaseId;
@BeforeClass
public static void setUp() throws IOException {
releaseId =
KieUtils.installArtifact(Paths.get(JUNIT_ECHO_KMODULE_PATH).toFile(),
Paths.get(JUNIT_ECHO_KMODULE_POM_PATH).toFile(),
JUNIT_ECHO_KJAR_DRL_PATH,
Paths.get(JUNIT_ECHO_KMODULE_DRL_PATH).toFile());
}
@Test
public void stop() throws IOException, InterruptedException {
createDroolsController(10000L).stop();
}
@Test
public void shutdown() throws IOException, InterruptedException {
createDroolsController(10000L).shutdown();
}
@Test
public void lock() throws IOException, InterruptedException {
DroolsController controller = createDroolsController(30000L);
controller.lock();
Assert.assertTrue(controller.isLocked());
controller.unlock();
Assert.assertFalse(controller.isLocked());
controller.halt();
Assert.assertFalse(controller.isAlive());
}
private DroolsController createDroolsController(long courtesyStartTimeMs) throws InterruptedException {
if (releaseId == null)
throw new IllegalStateException("no prereq artifact installed in maven repository");
DroolsController controller = new MavenDroolsController(releaseId.getGroupId(),
releaseId.getArtifactId(), releaseId.getVersion(), null, null);
Assert.assertFalse(controller.isAlive());
Assert.assertTrue(controller.isBrained());
controller.start();
Assert.assertTrue(controller.isAlive());
Assert.assertTrue(controller.isBrained());
Assert.assertEquals(releaseId.getGroupId(), controller.getGroupId());
Assert.assertEquals(releaseId.getArtifactId(), controller.getArtifactId());
Assert.assertEquals(releaseId.getVersion(), controller.getVersion());
Assert.assertEquals(releaseId.getGroupId(), controller.getContainer().getGroupId());
Assert.assertEquals(releaseId.getArtifactId(), controller.getContainer().getArtifactId());
Assert.assertEquals(releaseId.getVersion(), controller.getContainer().getVersion());
/* courtesy timer to allow full initialization from local maven repository */
Thread.sleep(courtesyStartTimeMs);
Assert.assertTrue(controller.getSessionNames().size() == 1);
Assert.assertEquals(JUNIT_ECHO_KSESSION, controller.getSessionNames().get(0));
Assert.assertTrue(controller.getCanonicalSessionNames().size() == 1);
Assert.assertTrue(controller.getCanonicalSessionNames().get(0).contains(JUNIT_ECHO_KSESSION));
return controller;
}
}
|