MR Java 11 Uplift
[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.PowerMockIgnore;
39 import org.powermock.core.classloader.annotations.PrepareForTest;
40 import org.powermock.modules.junit4.PowerMockRunner;
41
42 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
43
44 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
45 @RunWith(PowerMockRunner.class)
46 @PrepareForTest({ AJSCPropertiesMap.class })
47 public class Kafka011ConsumerTest {
48         
49                 
50         @Mock
51         private KafkaConsumer<String, String> cc;
52         @Mock
53         private KafkaLiveLockAvoider2 klla;
54
55         @Before
56         public void setUp() throws Exception {
57                 MockitoAnnotations.initMocks(this);
58                 
59         }
60
61         @After
62         public void tearDown() throws Exception {
63         }
64         
65         @Test
66         public void testKafka011Consumer() {
67                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
68                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "consumer.timeout")).thenReturn("10");
69                 Kafka011Consumer consumer=null;
70                 try {
71                          consumer= new Kafka011Consumer("topic", "group", "id", cc, klla)       ;
72                          consumer.commitOffsets();
73                          consumer.touch();
74                          consumer.setOffset(10);
75                 } catch (Exception e) {
76                         
77                 }
78                 assertNotNull(consumer);
79                 assertNotNull(consumer.getConsumer());
80                 assertNotNull(consumer.getConsumerGroup());
81                 assertNotNull(consumer.getConsumerId());
82                 assertNotNull(consumer.getConsumerId());
83                 assertNotNull(consumer.getCreateTimeMs());
84                 assertNotNull(consumer.getLastAccessMs());
85                 assertNotNull(consumer.getName());
86                 assertNotNull(consumer.getOffset());
87                 assertNotNull(consumer.getLastTouch());
88                 
89                 
90         }
91         
92
93 }