982fbf22bc4c1ad9422e26f21ee946e52911cd25
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / cambria / backends / kafka / KafkaPublisherTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21  package org.onap.dmaap.mr.cambria.backends.kafka;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.ClassRule;
33 import org.junit.Test;
34
35 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
36 import org.onap.dmaap.dmf.mr.backends.Publisher.message;
37 import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
38
39 import kafka.common.FailedToSendMessageException;
40 import kafka.producer.KeyedMessage;
41
42 public class KafkaPublisherTest {
43         
44         
45
46         /*@Before
47         public void setUp() throws Exception {
48                 ClassLoader classLoader = getClass().getClassLoader();          
49                 AJSCPropertiesMap.refresh(new File(classLoader.getResource("MsgRtrApi.properties").getFile()));
50         }
51
52         @After
53         public void tearDown() throws Exception {
54         }
55
56         @Test
57         public void testSendMessages() {
58
59                 String topic = "testTopic";
60
61                 KafkaPublisher kafka = null;
62                 try {
63                         kafka = new KafkaPublisher(null);
64                         
65                 } catch (missingReqdSetting e) {
66                         // TODO Auto-generated catch block
67                         e.printStackTrace();
68                 } catch (NoClassDefFoundError e) {
69                         try {
70                                 kafka.sendMessage(topic, null);
71                         } catch (NullPointerException e1) {
72                                 // TODO Auto-generated catch block
73                                 assertTrue(true);
74                         } catch (FailedToSendMessageException e1) {
75                                 // TODO Auto-generated catch block
76                                 e1.printStackTrace();
77                         } catch (IOException e1) {
78                                 // TODO Auto-generated catch block
79                                 e1.printStackTrace();
80                         }
81                 } catch (FailedToSendMessageException e) {
82                         // TODO Auto-generated catch block
83                         e.printStackTrace();
84                 }
85
86         }
87
88         @Test
89         public void testSendBatchMessage() {
90
91                 String topic = "testTopic";
92
93                 KafkaPublisher kafka = null;
94                 ArrayList<KeyedMessage<String, String>> kms = null;
95                 try {
96                         kafka = new KafkaPublisher(null);
97                         
98                 } catch (missingReqdSetting e) {
99                         // TODO Auto-generated catch block
100                         e.printStackTrace();
101                 } catch (NoClassDefFoundError e) {
102                         try {
103                                 kafka.sendBatchMessage(topic, kms);
104                         } catch (NullPointerException e1) {
105                                 // TODO Auto-generated catch block
106                                 assertTrue(true);
107                         } catch (IOException e1) {
108                                 // TODO Auto-generated catch block
109                                 e1.printStackTrace();
110                         }
111                 } catch (FailedToSendMessageException e) {
112                         // TODO Auto-generated catch block
113                         e.printStackTrace();
114                 }
115
116         }
117         
118         @Test
119         public void sendMessages() {
120
121                 String topic = "testTopic";
122                 
123                 List<message> msgs = null;
124
125                 KafkaPublisher kafka = null;
126                 //ArrayList<KeyedMessage<String, String>> kms = null;
127                 try {
128                         kafka = new KafkaPublisher(null);
129                         
130                 } catch (missingReqdSetting e) {
131                         // TODO Auto-generated catch block
132                         e.printStackTrace();
133                 } catch (NoClassDefFoundError e) {
134                         try {
135                                 kafka.sendMessages(topic, msgs);
136                         } catch (NullPointerException e1) {
137                                 // TODO Auto-generated catch block
138                                 assertTrue(true);
139                         } catch (FailedToSendMessageException e1) {
140                                 // TODO Auto-generated catch block
141                                 e1.printStackTrace();
142                         } catch (IOException e1) {
143                                 // TODO Auto-generated catch block
144                                 e1.printStackTrace();
145                         }
146                 } catch (FailedToSendMessageException e) {
147                         // TODO Auto-generated catch block
148                         e.printStackTrace();
149                 }
150
151         }*/
152
153 }