1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
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
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=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.mr.cambria.backends.kafka;
24 import static org.junit.Assert.assertNotNull;
26 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
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;
42 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
43 @RunWith(PowerMockRunner.class)
44 @PrepareForTest({ AJSCPropertiesMap.class })
45 public class Kafka011ConsumerTest {
49 private KafkaConsumer<String, String> cc;
51 private KafkaLiveLockAvoider2 klla;
54 public void setUp() throws Exception {
55 MockitoAnnotations.initMocks(this);
60 public void tearDown() throws Exception {
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;
69 consumer= new Kafka011Consumer("topic", "group", "id", cc, klla) ;
70 consumer.commitOffsets();
72 consumer.setOffset(10);
73 } catch (Exception e) {
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());