Add unit tests for router-core
[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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.event;
24
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27
28 import java.io.PrintWriter;
29 import java.io.StringWriter;
30
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 validate() throws Exception {
47
48     try {
49       EventBusComponent rc = new EventBusComponent();
50       EventBusEndpoint endpoint = new EventBusEndpoint("http://host.com:8443/endpoint", rc);
51
52       endpoint.setApiSecret("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
53       endpoint.setApiKey("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
54       endpoint.setEventTopic("eventTopic");
55       endpoint.setGroupId("groupId");
56       endpoint.setGroupName("gn");
57       endpoint.setName("name");
58       endpoint.setPoolSize(45);
59       endpoint.setPollingDelay(10);
60       endpoint.setUrl("url");
61
62       assertTrue(endpoint.getApiSecret().compareTo("onapSecret") == 0);
63       assertTrue(endpoint.getApiKey().compareTo("onapSecret") == 0);
64       assertTrue(endpoint.getEventTopic().compareTo("eventTopic") == 0);
65       assertTrue(endpoint.getGroupId().compareTo("groupId") == 0);
66       assertTrue(endpoint.getGroupName().compareTo("gn") == 0);
67       assertTrue(endpoint.getName().compareTo("name") == 0);
68       assertTrue(endpoint.getPoolSize() == 45);
69       assertTrue(endpoint.getPollingDelay() == 10);
70       assertTrue(endpoint.getUrl().compareTo("url") == 0);
71       assertFalse(endpoint.isSingleton());
72       
73       EventBusProducer producer = (EventBusProducer)endpoint.createProducer();
74       assertTrue(producer.getEndpoint() != null);
75     }
76     catch (Exception ex) {
77       StringWriter writer = new StringWriter();
78       PrintWriter printWriter = new PrintWriter( writer );
79       ex.printStackTrace( printWriter );
80       printWriter.flush();
81       System.out.println(writer.toString());
82       throw ex;
83     }
84   }
85     
86 }