2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.appc.listener;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
29 import java.util.Properties;
30 import java.util.concurrent.ThreadPoolExecutor;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.openecomp.appc.listener.AbstractListener;
35 import org.openecomp.appc.listener.ListenerProperties;
37 public class TestAbstractListener {
39 private class DummyListener extends AbstractListener {
40 public DummyListener(ListenerProperties props) {
44 public boolean getRun() {
48 public ThreadPoolExecutor getExecutor() {
53 private DummyListener listener;
54 private ListenerProperties props;
57 public void setup() throws Exception {
58 Properties regularProps = new Properties();
59 regularProps.load(getClass().getResourceAsStream("/org/openecomp/appc/default.properties"));
60 props = new ListenerProperties("", regularProps);
61 listener = new DummyListener(props);
65 public void testRun() {
66 Thread t = new Thread(listener);
68 assertFalse(t.isAlive()); // Should die immediately
72 public void testStop() {
74 assertFalse(listener.getRun());
75 assertTrue(listener.getExecutor().isShutdown());
79 public void testStopNow() {
81 assertFalse(listener.getRun());
82 assertTrue(listener.getExecutor().isShutdown());
86 public void testBenchmark() {
87 String out = listener.getBenchmark();
89 assertTrue(out.contains(listener.getListenerId()));
93 public void testListenerId() {
94 assertEquals(props.getPrefix(), listener.getListenerId());
95 listener.setListenerId("newId");
96 assertEquals("newId", listener.getListenerId());