2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.listener;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
30 import static org.junit.Assert.assertTrue;
32 import java.util.Properties;
33 import java.util.concurrent.ThreadPoolExecutor;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.openecomp.appc.listener.AbstractListener;
38 import org.openecomp.appc.listener.ListenerProperties;
40 public class TestAbstractListener {
42 private class DummyListener extends AbstractListener {
43 public DummyListener(ListenerProperties props) {
47 public boolean getRun() {
51 public ThreadPoolExecutor getExecutor() {
56 private DummyListener listener;
57 private ListenerProperties props;
60 public void setup() throws Exception {
61 Properties regularProps = new Properties();
62 regularProps.load(getClass().getResourceAsStream("/org/openecomp/appc/default.properties"));
63 props = new ListenerProperties("", regularProps);
64 listener = new DummyListener(props);
68 public void testRun() {
69 Thread t = new Thread(listener);
71 assertFalse(t.isAlive()); // Should die immediately
75 public void testStop() {
77 assertFalse(listener.getRun());
78 assertTrue(listener.getExecutor().isShutdown());
82 public void testStopNow() {
84 assertFalse(listener.getRun());
85 assertTrue(listener.getExecutor().isShutdown());
89 public void testBenchmark() {
90 String out = listener.getBenchmark();
92 assertTrue(out.contains(listener.getListenerId()));
96 public void testListenerId() {
97 assertEquals(props.getPrefix(), listener.getListenerId());
98 listener.setListenerId("newId");
99 assertEquals("newId", listener.getListenerId());