summaryrefslogtreecommitdiffstats
path: root/controlloop/common/feature-controlloop-management/src/test/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-27 10:52:06 -0400
committerJim Hahn <jrh3@att.com>2019-06-27 18:00:21 -0400
commitd0932a1a2339a02dab04eedefa0480535e68d31c (patch)
treedc6bcde6b279e5dd7a4a332b0494ab108096f173 /controlloop/common/feature-controlloop-management/src/test/java
parentd8118c6638bb2440f89eae9d3f979bdfb0e013c3 (diff)
Fix some sonar issues in drools-applications
Added coverage to: - feature-controlloop-management Fixed sonar issues, but didn't add coverage to: - feature-controlloop-trans - eventmanager - guard Change-Id: I12f09c4a533e838c6fb9762ba56194e51ce864eb Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/feature-controlloop-management/src/test/java')
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java60
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java4
2 files changed, 59 insertions, 5 deletions
diff --git a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java
index ac9bff93b..e5034017f 100644
--- a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java
+++ b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
@@ -20,13 +20,40 @@
package org.onap.policy.drools.apps.controlloop.feature.management;
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.drools.apps.controlloop.feature.management.ControlLoopManagementFeature.Factory;
+import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.system.PolicyController;
+import org.powermock.reflect.Whitebox;
/**
* Control Loop Management Feature Test.
*/
public class ControlLoopManagementFeatureTest {
+ private static final String FACTORY_FIELD = "factory";
+ private static final String SESSION_NAME = "my-session";
+ private static final String CONTROLLER_NAME = "my-controller";
+
+ private static Factory saveFactory;
+
+ @BeforeClass
+ public static void setUpBeforeClass() {
+ saveFactory = Whitebox.getInternalState(ControlLoopManagementFeature.class, FACTORY_FIELD);
+ }
+
+ @After
+ public void tearDown() {
+ Whitebox.setInternalState(ControlLoopManagementFeature.class, FACTORY_FIELD, saveFactory);
+ }
/**
* Sequence Number Test.
@@ -43,4 +70,33 @@ public class ControlLoopManagementFeatureTest {
public void getName() {
Assert.assertEquals("controlloop-management", new ControlLoopManagementFeature().getName());
}
-} \ No newline at end of file
+
+ @Test
+ public void testControlLoops_InvalidArgs() {
+ Factory factory = mock(Factory.class);
+ Whitebox.setInternalState(ControlLoopManagementFeature.class, FACTORY_FIELD, factory);
+
+ // returns null controller
+ when(factory.getController(any())).thenReturn(null);
+ assertThatIllegalArgumentException()
+ .isThrownBy(() -> ControlLoopManagementFeature.controlLoops(CONTROLLER_NAME, SESSION_NAME))
+ .withMessage("Invalid Controller Name");
+
+ // non-matching session name
+ PolicyController ctlr = mock(PolicyController.class);
+ DroolsController drools = mock(DroolsController.class);
+ when(drools.getSessionNames()).thenReturn(Collections.emptyList());
+ when(ctlr.getDrools()).thenReturn(drools);
+ when(factory.getController(any())).thenReturn(ctlr);
+ assertThatIllegalArgumentException()
+ .isThrownBy(() -> ControlLoopManagementFeature.controlLoops(CONTROLLER_NAME, SESSION_NAME))
+ .withMessage("Invalid Session Name");
+ }
+
+ @Test
+ public void testFactoryGetController() {
+ // invoking controlLoops() will invoke the factory.getController() method
+ assertThatIllegalArgumentException().isThrownBy(
+ () -> ControlLoopManagementFeature.controlLoops("unknown-controller", SESSION_NAME));
+ }
+}
diff --git a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
index 3ed1adfe3..3d89e5a1e 100644
--- a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
+++ b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
@@ -126,7 +126,6 @@ public class RestControlLoopManagerTest {
Files.deleteIfExists(controllerPath);
} catch (Exception ignored) {
/* to satisfy checkstyle */
- ;
}
Path controllerBakPath =
@@ -136,7 +135,6 @@ public class RestControlLoopManagerTest {
Files.deleteIfExists(controllerBakPath);
} catch (Exception ignored) {
/* to satisfy checkstyle */
- ;
}
}