2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.apps.controlloop.feature.management;
23 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
28 import java.util.Collections;
29 import org.junit.After;
30 import org.junit.Assert;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.policy.drools.apps.controlloop.feature.management.ControlLoopManagementFeature.Factory;
34 import org.onap.policy.drools.controller.DroolsController;
35 import org.onap.policy.drools.system.PolicyController;
36 import org.powermock.reflect.Whitebox;
39 * Control Loop Management Feature Test.
41 public class ControlLoopManagementFeatureTest {
42 private static final String FACTORY_FIELD = "factory";
43 private static final String SESSION_NAME = "my-session";
44 private static final String CONTROLLER_NAME = "my-controller";
46 private static Factory saveFactory;
49 public static void setUpBeforeClass() {
50 saveFactory = Whitebox.getInternalState(ControlLoopManagementFeature.class, FACTORY_FIELD);
54 public void tearDown() {
55 Whitebox.setInternalState(ControlLoopManagementFeature.class, FACTORY_FIELD, saveFactory);
59 * Sequence Number Test.
62 public void getSequenceNumber() {
63 Assert.assertEquals(1000, new ControlLoopManagementFeature().getSequenceNumber());
70 public void getName() {
71 Assert.assertEquals("controlloop-management", new ControlLoopManagementFeature().getName());
75 public void testControlLoops_InvalidArgs() {
76 Factory factory = mock(Factory.class);
77 Whitebox.setInternalState(ControlLoopManagementFeature.class, FACTORY_FIELD, factory);
79 // returns null controller
80 when(factory.getController(any())).thenReturn(null);
81 assertThatIllegalArgumentException()
82 .isThrownBy(() -> ControlLoopManagementFeature.controlLoops(CONTROLLER_NAME, SESSION_NAME))
83 .withMessage("Invalid Controller Name");
85 // non-matching session name
86 PolicyController ctlr = mock(PolicyController.class);
87 DroolsController drools = mock(DroolsController.class);
88 when(drools.getSessionNames()).thenReturn(Collections.emptyList());
89 when(ctlr.getDrools()).thenReturn(drools);
90 when(factory.getController(any())).thenReturn(ctlr);
91 assertThatIllegalArgumentException()
92 .isThrownBy(() -> ControlLoopManagementFeature.controlLoops(CONTROLLER_NAME, SESSION_NAME))
93 .withMessage("Invalid Session Name");
97 public void testFactoryGetController() {
98 // invoking controlLoops() will invoke the factory.getController() method
99 assertThatIllegalArgumentException().isThrownBy(
100 () -> ControlLoopManagementFeature.controlLoops("unknown-controller", SESSION_NAME));