aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2019-11-12 14:36:19 -0600
committerjhh <jorge.hernandez-herrero@att.com>2019-11-12 14:39:51 -0600
commit037c5ff588a3967d9f1b9f81900198aafc3ed228 (patch)
tree029d1bfe7b6c3dba21112b3bd39fad2e9532eb3b
parent2b0f80062f0609f483eea287bdf503be45f12472 (diff)
Dispose drools controllers in junit tests
Issue-ID: POLICY-1407 Change-Id: I4db3489c242a6cdd39444de19c9c8da83559bee4 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java39
1 files changed, 30 insertions, 9 deletions
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
index 456c22f8..9c38e7e7 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
@@ -26,13 +26,16 @@ import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;
import java.util.Properties;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.builder.ReleaseId;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.controller.internal.MavenDroolsControllerTest;
import org.onap.policy.drools.properties.DroolsPropertyConstants;
@@ -47,9 +50,9 @@ import org.slf4j.LoggerFactory;
* ProtocolCoder Toolset Junits.
*/
public class ProtocolCoderToolsetTest {
- public static final String JUNIT_PROTOCOL_CODER_ARTIFACT_ID = "protocolcoder";
- public static final String JUNIT_PROTOCOL_CODER_TOPIC = JUNIT_PROTOCOL_CODER_ARTIFACT_ID;
- public static final String CONTROLLER_ID = "blah";
+ private static final String JUNIT_PROTOCOL_CODER_ARTIFACT_ID = "protocolcoder";
+ private static final String JUNIT_PROTOCOL_CODER_TOPIC = JUNIT_PROTOCOL_CODER_ARTIFACT_ID;
+ private static final String CONTROLLER_ID = "blah";
private static Logger logger = LoggerFactory.getLogger(ProtocolCoderToolset.class);
@@ -58,11 +61,13 @@ public class ProtocolCoderToolsetTest {
// customCoder has to be public to be accessed in tests below
public static final Gson customCoder = new GsonBuilder().create();
+ private DroolsController controller;
+
/**
* Test Class Initialization.
*/
@BeforeClass
- public static void setupClass() throws IOException {
+ public static void setUpClass() throws IOException {
releaseId = KieUtils.installArtifact(
Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_PATH).toFile(),
Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_POM_PATH).toFile(),
@@ -70,11 +75,27 @@ public class ProtocolCoderToolsetTest {
Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_DRL_PATH).toFile());
}
+ /**
+ * Test Set Up.
+ */
+ @Before
+ public void setUp() {
+ controller = createController();
+ }
+
+ /**
+ * Test Termination.
+ */
+ @After
+ public void tearDown() {
+ if (controller != null) {
+ DroolsControllerConstants.getFactory().destroy(controller);
+ }
+ }
+
@Test
public void testToolsets() {
- createController();
testGsonToolset(createFilterSet());
- DroolsControllerConstants.getFactory().destroy();
}
/**
@@ -82,7 +103,7 @@ public class ProtocolCoderToolsetTest {
*
* @param protocolFilter protocol filter
*/
- public void testGsonToolset(JsonProtocolFilter protocolFilter) {
+ private void testGsonToolset(JsonProtocolFilter protocolFilter) {
GsonProtocolCoderToolset gsonToolset = new GsonProtocolCoderToolset(
EventProtocolParams.builder().topic(JUNIT_PROTOCOL_CODER_TOPIC)
.groupId(releaseId.getGroupId())
@@ -209,7 +230,7 @@ public class ProtocolCoderToolsetTest {
Assert.assertEquals(coderFilters.getFilter(), protocolFilter);
}
- private void createController() {
+ private DroolsController createController() {
if (releaseId == null) {
throw new IllegalStateException("no prereq artifact installed in maven repository");
}
@@ -225,7 +246,7 @@ public class ProtocolCoderToolsetTest {
droolsControllerConfig.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS + "." + JUNIT_PROTOCOL_CODER_TOPIC
+ PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX, Triple.class.getName());
- DroolsControllerConstants.getFactory().build(droolsControllerConfig, null, noopTopics);
+ return DroolsControllerConstants.getFactory().build(droolsControllerConfig, null, noopTopics);
}
private JsonProtocolFilter createFilterSet() {