update link to upper-constraints.txt
[dmaap/messagerouter/messageservice.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 import static org.junit.jupiter.api.Assertions.assertTrue;
26
27 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
28 import org.apache.kafka.clients.consumer.KafkaConsumer;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.dmaap.dmf.mr.backends.kafka.Kafka011Consumer;
36 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaLiveLockAvoider2;
37 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
38 import org.powermock.api.mockito.PowerMockito;
39 import org.powermock.core.classloader.annotations.PowerMockIgnore;
40 import org.powermock.core.classloader.annotations.PrepareForTest;
41 import org.powermock.modules.junit4.PowerMockRunner;
42
43 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
44 @RunWith(PowerMockRunner.class)
45 @PrepareForTest({ AJSCPropertiesMap.class })
46 public class Kafka011ConsumerTest {
47
48
49         @Mock
50         private KafkaConsumer<String, String> cc;
51         @Mock
52         private KafkaLiveLockAvoider2 klla;
53
54         @Before
55         public void setUp() throws Exception {
56                 MockitoAnnotations.initMocks(this);
57
58         }
59
60         @After
61         public void tearDown() throws Exception {
62         }
63
64         @Test
65         public void testKafka011Consumer() {
66                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
67                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "consumer.timeout")).thenReturn("10");
68                 Kafka011Consumer consumer=null;
69                 try {
70                          consumer= new Kafka011Consumer("topic", "group", "id", cc, klla)       ;
71                          consumer.commitOffsets();
72                          consumer.touch();
73                          consumer.setOffset(10);
74                 } catch (Exception e) {
75
76                 }
77                 assertNotNull(consumer);
78                 assertNotNull(consumer.getConsumer());
79                 assertNotNull(consumer.getConsumerGroup());
80                 assertNotNull(consumer.getConsumerId());
81                 assertNotNull(consumer.getConsumerId());
82                 assertTrue(consumer.getCreateTimeMs() > 0);
83                 assertTrue(consumer.getLastAccessMs() > 0);
84                 assertNotNull(consumer.getName());
85                 assertTrue(consumer.getOffset() > 0);
86                 assertTrue(consumer.getLastTouch() > 0);
87
88
89         }
90
91
92 }