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