88d703e1b8d4ee0ac217461ae236fa62821bfba5
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / cambria / backends / kafka / Kafka011ConsumerTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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  *        http://www.apache.org/licenses/LICENSE-2.0
11 *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *  
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.mr.cambria.backends.kafka;
23
24 import static org.junit.Assert.assertNotNull;
25
26
27 import org.apache.kafka.clients.consumer.KafkaConsumer;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.dmaap.dmf.mr.backends.kafka.Kafka011Consumer;
35 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaLiveLockAvoider2;
36 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
37 import org.powermock.api.mockito.PowerMockito;
38 import org.powermock.core.classloader.annotations.PrepareForTest;
39 import org.powermock.modules.junit4.PowerMockRunner;
40
41 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
42
43 @RunWith(PowerMockRunner.class)
44 @PrepareForTest({ AJSCPropertiesMap.class })
45 public class Kafka011ConsumerTest {
46         
47                 
48         @Mock
49         private KafkaConsumer<String, String> cc;
50         @Mock
51         private KafkaLiveLockAvoider2 klla;
52
53         @Before
54         public void setUp() throws Exception {
55                 MockitoAnnotations.initMocks(this);
56                 
57         }
58
59         @After
60         public void tearDown() throws Exception {
61         }
62         
63         @Test
64         public void testKafka011Consumer() {
65                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
66                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "consumer.timeout")).thenReturn("10");
67                 Kafka011Consumer consumer=null;
68                 try {
69                          consumer= new Kafka011Consumer("topic", "group", "id", cc, klla)       ;
70                          consumer.commitOffsets();
71                          consumer.touch();
72                          consumer.setOffset(10);
73                 } catch (Exception e) {
74                         
75                 }
76                 assertNotNull(consumer);
77                 assertNotNull(consumer.getConsumer());
78                 assertNotNull(consumer.getConsumerGroup());
79                 assertNotNull(consumer.getConsumerId());
80                 assertNotNull(consumer.getConsumerId());
81                 assertNotNull(consumer.getCreateTimeMs());
82                 assertNotNull(consumer.getLastAccessMs());
83                 assertNotNull(consumer.getName());
84                 assertNotNull(consumer.getOffset());
85                 assertNotNull(consumer.getLastTouch());
86                 
87                 
88         }
89         
90
91 }