TCA: Replace any openecomp reference by onap
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-plugins / src / test / java / org / onap / dcae / apod / analytics / cdap / plugins / batch / sink / dmaap / DMaaPMRRecordWriterTest.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 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.dcae.apod.analytics.cdap.plugins.batch.sink.dmaap;
22
23 import org.apache.hadoop.mapreduce.TaskAttemptContext;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.onap.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
28 import org.onap.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher;
29
30 import java.util.Arrays;
31
32 import static org.mockito.Mockito.times;
33
34 /**
35  * @author Rajiv Singla . Creation Date: 1/30/2017.
36  */
37 public class DMaaPMRRecordWriterTest extends BaseAnalyticsCDAPPluginsUnitTest {
38
39     private DMaaPMRPublisher publisher;
40     private DMaaPMRRecordWriter dMaaPMRRecordWriter;
41
42     @Before
43     public void before() {
44         publisher = Mockito.mock(DMaaPMRPublisher.class);
45         dMaaPMRRecordWriter = new DMaaPMRRecordWriter(publisher);
46     }
47
48     @Test
49     public void testWrite() throws Exception {
50         final String testMessage = "test Message";
51         dMaaPMRRecordWriter.write(testMessage, null);
52         Mockito.verify(publisher, times(1)).publish(Arrays.asList(testMessage));
53     }
54
55     @Test
56     public void testClose() throws Exception {
57         final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class);
58         dMaaPMRRecordWriter.close(taskAttemptContext);
59         Mockito.verify(publisher, times(1)).flush();
60     }
61
62 }