8d294cd3c8bbf9a97a41eecf493bcdd17fcfcc99
[aai/router-core.git] / src / test / java / org / onap / aai / event / EventBusTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 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  */
21 package org.onap.aai.event;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25
26 import java.io.PrintWriter;
27 import java.io.StringWriter;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import org.apache.camel.Endpoint;
32 import org.junit.Before;
33 import org.junit.Test;
34
35 public class EventBusTest {
36
37     /**
38      * Test case initialization
39      * 
40      * @throws Exception the exception
41      */
42     @Before
43     public void init() throws Exception {
44     }
45
46     @Test
47     public void validateProducer() throws Exception {
48         try {
49             EventBusComponent rc = new EventBusComponent();            
50             EventBusEndpoint endpoint = new EventBusEndpoint("http://host.com:8443/endpoint", rc);
51             endpoint.setApiSecret("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
52             endpoint.setApiKey("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
53             endpoint.setEventTopic("eventTopic");
54             endpoint.setGroupId("groupId");
55             endpoint.setGroupName("gn");
56             endpoint.setName("name");
57             endpoint.setPoolSize(45);
58             endpoint.setPollingDelay(10);
59             endpoint.setUrl("url");
60
61             assertTrue(endpoint.getApiSecret().compareTo("onapSecret") == 0);
62             assertTrue(endpoint.getApiKey().compareTo("onapSecret") == 0);
63             assertTrue(endpoint.getEventTopic().compareTo("eventTopic") == 0);
64             assertTrue(endpoint.getGroupId().compareTo("groupId") == 0);
65             assertTrue(endpoint.getGroupName().compareTo("gn") == 0);
66             assertTrue(endpoint.getName().compareTo("name") == 0);
67             assertTrue(endpoint.getPoolSize() == 45);
68             assertTrue(endpoint.getPollingDelay() == 10);
69             assertTrue(endpoint.getUrl().compareTo("url") == 0);
70             assertFalse(endpoint.isSingleton());
71
72             EventBusProducer producer = (EventBusProducer)endpoint.createProducer();
73             assertTrue(producer.getEndpoint() != null);
74         }
75         catch (Exception ex) {
76             StringWriter writer = new StringWriter();
77             PrintWriter printWriter = new PrintWriter( writer );
78             ex.printStackTrace( printWriter );
79             printWriter.flush();
80             System.out.println(writer.toString());
81             throw ex;
82         }
83     }
84     
85     @Test
86     public void validateEventBusComponent() throws Exception {
87         EventBusComponent rc = new EventBusComponent(new TestCamelContext());
88         Endpoint endpoint = rc.createEndpoint("http://host.com:8443/endpoint", null, new HashMap<String, Object>());
89         assertTrue(endpoint.getEndpointUri().equals("http://host.com:8443/endpoint"));
90     }
91     
92     @Test
93     public void validateConsumer() throws Exception {
94         try {
95             EventBusComponent rc = new EventBusComponent();
96             EventBusEndpoint endpoint = new EventBusEndpoint("http://host.com:8443/endpoint", rc);
97
98             endpoint.setApiSecret("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
99             endpoint.setApiKey("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
100             endpoint.setEventTopic("eventTopic");
101             endpoint.setGroupId("groupId");
102             endpoint.setGroupName("gn");
103             endpoint.setName("name");
104             endpoint.setPoolSize(45);
105             endpoint.setPollingDelay(10);
106             endpoint.setUrl("url");
107
108             TestProcessor processor = new TestProcessor();
109             EventBusConsumer consumer = new EventBusConsumer(endpoint, processor);
110             
111         }
112         catch (Exception ex) {
113             StringWriter writer = new StringWriter();
114             PrintWriter printWriter = new PrintWriter( writer );
115             ex.printStackTrace( printWriter );
116             printWriter.flush();
117             System.out.println(writer.toString());
118             throw ex;
119         }
120     }
121 }