2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * Copyright (C) 2017 Amdocs
 
   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=========================================================
 
  20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  23 package org.openecomp.appc.listener;
 
  25 import static org.junit.Assert.assertEquals;
 
  26 import static org.junit.Assert.assertFalse;
 
  27 import static org.junit.Assert.assertNotNull;
 
  28 import static org.junit.Assert.assertTrue;
 
  30 import java.util.Properties;
 
  31 import java.util.concurrent.ThreadPoolExecutor;
 
  33 import org.junit.Before;
 
  34 import org.junit.Test;
 
  35 import org.openecomp.appc.listener.AbstractListener;
 
  36 import org.openecomp.appc.listener.ListenerProperties;
 
  38 public class TestAbstractListener {
 
  40     private class DummyListener extends AbstractListener {
 
  41         public DummyListener(ListenerProperties props) {
 
  45         public boolean getRun() {
 
  49         public ThreadPoolExecutor getExecutor() {
 
  54     private DummyListener listener;
 
  55     private ListenerProperties props;
 
  58     public void setup() throws Exception {
 
  59         Properties regularProps = new Properties();
 
  60         regularProps.load(getClass().getResourceAsStream("/org/openecomp/appc/default.properties"));
 
  61         props = new ListenerProperties("", regularProps);
 
  62         listener = new DummyListener(props);
 
  66     public void testRun() {
 
  67         Thread t = new Thread(listener);
 
  69         assertFalse(t.isAlive()); // Should die immediately
 
  73     public void testStop() {
 
  75         assertFalse(listener.getRun());
 
  76         assertTrue(listener.getExecutor().isShutdown());
 
  80     public void testStopNow() {
 
  82         assertFalse(listener.getRun());
 
  83         assertTrue(listener.getExecutor().isShutdown());
 
  87     public void testBenchmark() {
 
  88         String out = listener.getBenchmark();
 
  90         assertTrue(out.contains(listener.getListenerId()));
 
  94     public void testListenerId() {
 
  95         assertEquals(props.getPrefix(), listener.getListenerId());
 
  96         listener.setListenerId("newId");
 
  97         assertEquals("newId", listener.getListenerId());