Second part of onap rename
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / test / java / org / openecomp / appc / listener / impl / TestListener.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.listener.impl;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.fail;
29
30 import java.util.Properties;
31
32 import org.junit.Before;
33 import org.junit.Ignore;
34 import org.junit.Test;
35 import org.onap.appc.listener.Listener;
36 import org.onap.appc.listener.ListenerProperties;
37 import org.onap.appc.listener.demo.impl.ListenerImpl;
38
39 @Ignore
40 public class TestListener {
41
42     private static final String PROP_FILE = "/org/onap/appc/default.properties";
43
44     private Listener listener;
45
46     private Properties props;
47
48     @Before
49     public void setup() {
50         props = new Properties();
51         try {
52             props.load(getClass().getResourceAsStream(PROP_FILE));
53             props.setProperty("topic.read", "DCAE-CLOSED-LOOP-EVENTS-DEV1510SIM");
54         } catch (Exception e) {
55             e.printStackTrace();
56             fail("Failed to setup test: " + e.getMessage());
57         }
58         listener = new ListenerImpl(new ListenerProperties("appc.ClosedLoop", props));
59     }
60
61     @Test
62     public void testListenerId() {
63         String originalId = listener.getListenerId();
64         String newId = originalId + "-new";
65
66         listener.setListenerId(newId);
67         assertEquals(newId, listener.getListenerId());
68     }
69
70     @Test
71     public void testRun() {
72         try {
73             Thread t = new Thread(listener);
74             t.start();
75
76             Thread.sleep(5000);
77
78             listener.stopNow();
79
80             System.out.println(listener.getBenchmark());
81
82         } catch (Exception e) {
83             e.printStackTrace();
84             fail(e.getMessage());
85         }
86     }
87
88     @Test
89     public void testUpdateProperties() {
90
91     }
92
93     @Test
94     public void printSampleData() {
95         try {
96             props.setProperty("threads.queuesize.min", "1");
97             props.setProperty("threads.queuesize.max", "1");
98             props.setProperty("threads.poolsize.min", "1");
99             props.setProperty("threads.poolsize.max", "1");
100
101             Thread t = new Thread(listener);
102             t.start();
103
104             Thread.sleep(2000);
105
106             listener.stop();
107
108             System.out.println(listener.getBenchmark());
109
110         } catch (Exception e) {
111             e.printStackTrace();
112             fail(e.getMessage());
113         }
114     }
115 }