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