aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/test/java/org
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-03-14 13:41:17 +0000
committerliamfallon <liam.fallon@ericsson.com>2018-03-14 14:03:09 +0000
commit6b7958a2b6844ef61269adc9b8f0d9571a590718 (patch)
treef037d859645726662928d53ce7369251b913cc2d /policy-management/src/test/java/org
parent22a233570c270369fbe20a712f97430a21652b20 (diff)
Unit test modified to be order independent
The change of dmaap version caused the order of execution of unit tests to change. This triggered an assertion fail in this test. The test has been redesigned to be independent of test invocation order. Also some small Sonar issues fixed. Change-Id: I3b3a5b1cb69785c69f818eab2473fdbfbb85dbd1 Issue-ID: POLICY-694 Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'policy-management/src/test/java/org')
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java56
1 files changed, 43 insertions, 13 deletions
diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java b/policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java
index 3db2e7c7..4fb4d92d 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.drools.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.List;
import java.util.Properties;
@@ -33,10 +34,11 @@ public class DroolsControllerFactoryTest {
@Test
public void buildNullController() {
Properties droolsProps = new Properties();
- DroolsController droolsController =
- DroolsController.factory.build(droolsProps, null, null);
+ DroolsController droolsController = DroolsController.factory.build(droolsProps, null, null);
- assertNullController(droolsController);
+ if (!isNullController(droolsController)) {
+ fail("drools controller is not a null controller");
+ }
}
@Test
@@ -46,17 +48,21 @@ public class DroolsControllerFactoryTest {
DroolsController.NO_ARTIFACT_ID, DroolsController.NO_VERSION);
assertNotNull(controller);
- assertEquals(controller.getGroupId(), DroolsController.NO_GROUP_ID);
- assertEquals(controller.getArtifactId(), DroolsController.NO_ARTIFACT_ID);
- assertEquals(controller.getVersion(), DroolsController.NO_VERSION);
+ assertEquals(DroolsController.NO_GROUP_ID, controller.getGroupId());
+ assertEquals(DroolsController.NO_ARTIFACT_ID, controller.getArtifactId());
+ assertEquals(DroolsController.NO_VERSION, controller.getVersion());
}
@Test
public void inventory() {
List<DroolsController> controllers = DroolsController.factory.inventory();
assertNotNull(controllers);
- assertTrue(controllers.size() == 1);
- assertNullController(controllers.get(0));
+
+ for (int i = 0; i < controllers.size(); i++) {
+ if (!isNullController(controllers.get(i)) && !isActualController(controllers.get(i))) {
+ fail("drools controller is not a null controller");
+ }
+ }
}
@Test
@@ -73,11 +79,35 @@ public class DroolsControllerFactoryTest {
assertTrue(droolsFactory.inventory().isEmpty());
}
- private void assertNullController(DroolsController droolsController) {
- assertNotNull(droolsController);
- assertEquals(droolsController.getGroupId(), DroolsController.NO_GROUP_ID);
- assertEquals(droolsController.getArtifactId(), DroolsController.NO_ARTIFACT_ID);
- assertEquals(droolsController.getVersion(), DroolsController.NO_VERSION);
+ private boolean isNullController(DroolsController droolsController) {
+ if (droolsController == null) {
+ return false;
+ }
+
+ if (!DroolsController.NO_GROUP_ID.equals(droolsController.getGroupId())) {
+ return false;
+ }
+
+ if (!DroolsController.NO_ARTIFACT_ID.equals(droolsController.getArtifactId())) {
+ return false;
+ }
+
+ return DroolsController.NO_VERSION.equals(droolsController.getVersion());
}
+ private boolean isActualController(DroolsController droolsController) {
+ if (droolsController == null) {
+ return false;
+ }
+
+ if (!"org.onap.policy.drools.test".equals(droolsController.getGroupId())) {
+ return false;
+ }
+
+ if (!"protocolcoder".equals(droolsController.getArtifactId())) {
+ return false;
+ }
+
+ return droolsController.getVersion() != null && droolsController.getVersion().substring(0, 1).matches("[0-9]");
+ }
}