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;
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 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
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 {
51 private KafkaConsumer<String, String> cc;
53 private KafkaLiveLockAvoider2 klla;
56 public void setUp() throws Exception {
57 MockitoAnnotations.initMocks(this);
62 public void tearDown() throws Exception {
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;
71 consumer= new Kafka011Consumer("topic", "group", "id", cc, klla) ;
72 consumer.commitOffsets();
74 consumer.setOffset(10);
75 } catch (Exception e) {
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());