2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.listener.impl;
28 import java.util.HashSet;
30 import java.util.Properties;
32 import java.util.concurrent.ThreadPoolExecutor;
33 import java.util.concurrent.TimeUnit;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.mockito.Mockito;
38 import org.onap.appc.listener.Controller;
39 import org.onap.appc.listener.Listener;
40 import org.onap.appc.listener.ListenerProperties;
41 import org.onap.appc.listener.demo.impl.ListenerImpl;
42 import org.powermock.reflect.Whitebox;
43 import com.att.eelf.configuration.EELFLogger;
44 import com.att.eelf.configuration.EELFManager;
46 public class TestController {
48 private ListenerProperties listenerProperties;
49 private Set<ListenerProperties> properties = Mockito.spy(new HashSet<>());
50 private EELFLogger log = Mockito.spy(EELFManager.getInstance().getLogger(ControllerImpl.class));
53 public ExpectedException expectedEx = ExpectedException.none();
56 public void testExceptionConstructor() {
57 listenerProperties = Mockito.mock(ListenerProperties.class);
58 properties.add(listenerProperties);
59 new ControllerImpl(properties);
60 Mockito.verify(properties).remove(Mockito.any());
64 public void testStartException() throws NoSuchMethodException, SecurityException {
65 Properties props = new Properties();
66 props.put("TEST", "TEST");
67 listenerProperties = Mockito.spy(new ListenerProperties("TEST", props));
68 listenerProperties.setListenerClass(Listener.class);
69 properties.add(listenerProperties);
70 ControllerImpl controllerImpl = new ControllerImpl(properties);
71 controllerImpl.start();
72 Mockito.verify(listenerProperties, Mockito.times(2)).getListenerClass();
76 public void testStopException() throws NoSuchMethodException, SecurityException, InterruptedException {
77 Properties props = new Properties();
78 props.put("TEST", "TEST");
79 listenerProperties = Mockito.spy(new ListenerProperties("TEST", props));
80 listenerProperties.setListenerClass(Listener.class);
81 properties.add(listenerProperties);
82 ControllerImpl controllerImpl = new ControllerImpl(properties);
83 //controllerImpl.start();
84 Map<String, Listener> map = Whitebox.getInternalState(controllerImpl, "listeners");
85 map.put("TEST", new ListenerImpl(listenerProperties));
86 ThreadPoolExecutor executor = Mockito.mock(ThreadPoolExecutor.class);
87 Mockito.when(executor.awaitTermination(300, TimeUnit.SECONDS)).thenReturn(false);
88 Whitebox.setInternalState(controllerImpl, "executor", executor);
89 controllerImpl.stop(false);
90 Mockito.verify(executor).shutdown();