summaryrefslogtreecommitdiffstats
path: root/controlloop/common/feature-controlloop-management/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/feature-controlloop-management/src/test')
-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 */
- ;
}
}