Remove cambria client dependency
[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
30 import org.apache.camel.Endpoint;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 public class EventBusTest {
35
36     /**
37      * Test case initialization
38      * 
39      * @throws Exception the exception
40      */
41     @Before
42     public void init() throws Exception {
43     }
44
45     @Test
46     public void validateProducer() throws Exception {
47         try {
48             DMaaPEventBusComponent rc = new DMaaPEventBusComponent();
49             DMaaPEventBusEndpoint endpoint = new DMaaPEventBusEndpoint("http://host.com:8443/endpoint", rc);
50             endpoint.setPassword("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
51             endpoint.setUsername("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
52             endpoint.setEventTopic("eventTopic");
53             endpoint.setConsumerId("groupId");
54             endpoint.setConsumerGroup("gn");
55             endpoint.setName("name");
56             endpoint.setPoolSize(45);
57             endpoint.setPollingDelay(10);
58             endpoint.setUrl("url");
59
60             assertTrue(endpoint.getPassword().compareTo("onapSecret") == 0);
61             assertTrue(endpoint.getUsername().compareTo("onapSecret") == 0);
62             assertTrue(endpoint.getEventTopic().compareTo("eventTopic") == 0);
63             assertTrue(endpoint.getConsumerId().compareTo("groupId") == 0);
64             assertTrue(endpoint.getConsumerGroup().compareTo("gn") == 0);
65             assertTrue(endpoint.getName().compareTo("name") == 0);
66             assertTrue(endpoint.getPoolSize() == 45);
67             assertTrue(endpoint.getPollingDelay() == 10);
68             assertTrue(endpoint.getUrl().compareTo("url") == 0);
69             assertFalse(endpoint.isSingleton());
70
71             EventBusProducer producer = (EventBusProducer)endpoint.createProducer();
72             assertTrue(producer.getEndpoint() != null);
73         }
74         catch (Exception ex) {
75             StringWriter writer = new StringWriter();
76             PrintWriter printWriter = new PrintWriter( writer );
77             ex.printStackTrace( printWriter );
78             printWriter.flush();
79             System.out.println(writer.toString());
80             throw ex;
81         }
82     }
83     
84     @Test
85     public void validateEventBusComponent() throws Exception {
86         DMaaPEventBusComponent rc = new DMaaPEventBusComponent(new TestCamelContext());
87         Endpoint endpoint = rc.createEndpoint("http://host.com:8443/endpoint", null, new HashMap<String, Object>());
88         assertTrue(endpoint.getEndpointUri().equals("http://host.com:8443/endpoint"));
89     }
90     
91     @Test
92     public void validateConsumer() throws Exception {
93         try {
94             DMaaPEventBusComponent rc = new DMaaPEventBusComponent();
95             DMaaPEventBusEndpoint endpoint = new DMaaPEventBusEndpoint("http://host.com:8443/endpoint", rc);
96
97             endpoint.setPassword("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
98             endpoint.setUsername("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
99             endpoint.setEventTopic("eventTopic");
100             endpoint.setConsumerId("groupId");
101             endpoint.setConsumerGroup("gn");
102             endpoint.setName("name");
103             endpoint.setPoolSize(45);
104             endpoint.setPollingDelay(10);
105             endpoint.setUrl("url");
106
107             TestProcessor processor = new TestProcessor();
108             EventBusConsumer consumer = (EventBusConsumer)endpoint.createConsumer(processor);
109
110         }
111         catch (Exception ex) {
112             StringWriter writer = new StringWriter();
113             PrintWriter printWriter = new PrintWriter( writer );
114             ex.printStackTrace( printWriter );
115             printWriter.flush();
116             System.out.println(writer.toString());
117             throw ex;
118         }
119     }
120 }