Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-plugins / src / test / java / org / openecomp / dcae / apod / analytics / cdap / plugins / batch / sink / dmaap / DMaaPMRRecordWriterTest.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\r
4  * ================================================================================\r
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  *  Licensed under the Apache License, Version 2.0 (the "License");\r
8  *  you may not use this file except in compliance with the License.\r
9  *   You may obtain a copy of the License at\r
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  *  Unless required by applicable law or agreed to in writing, software\r
14  *  distributed under the License is distributed on an "AS IS" BASIS,\r
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  *  See the License for the specific language governing permissions and\r
17  *  limitations under the License.\r
18  *  ============================LICENSE_END===========================================\r
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.cdap.plugins.batch.sink.dmaap;\r
22 \r
23 import org.apache.hadoop.mapreduce.TaskAttemptContext;\r
24 import org.junit.Before;\r
25 import org.junit.Test;\r
26 import org.mockito.Mockito;\r
27 import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;\r
28 import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher;\r
29 \r
30 import java.util.Arrays;\r
31 \r
32 import static org.mockito.Mockito.times;\r
33 \r
34 /**\r
35  * @author Rajiv Singla . Creation Date: 1/30/2017.\r
36  */\r
37 public class DMaaPMRRecordWriterTest extends BaseAnalyticsCDAPPluginsUnitTest {\r
38 \r
39     private DMaaPMRPublisher publisher;\r
40     private DMaaPMRRecordWriter dMaaPMRRecordWriter;\r
41 \r
42     @Before\r
43     public void before() {\r
44         publisher = Mockito.mock(DMaaPMRPublisher.class);\r
45         dMaaPMRRecordWriter = new DMaaPMRRecordWriter(publisher);\r
46     }\r
47 \r
48     @Test\r
49     public void testWrite() throws Exception {\r
50         final String testMessage = "test Message";\r
51         dMaaPMRRecordWriter.write(testMessage, null);\r
52         Mockito.verify(publisher, times(1)).publish(Arrays.asList(testMessage));\r
53     }\r
54 \r
55     @Test\r
56     public void testClose() throws Exception {\r
57         final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class);\r
58         dMaaPMRRecordWriter.close(taskAttemptContext);\r
59         Mockito.verify(publisher, times(1)).flush();\r
60     }\r
61 \r
62 }\r