2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Copyright (C) 2017 Amdocs
 
   8  * =============================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License");
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  21  * ============LICENSE_END=========================================================
 
  24 package org.onap.appc.adapter.messaging.dmaap;
 
  27 import org.junit.Assert;
 
  28 import org.junit.BeforeClass;
 
  29 import org.junit.Test;
 
  30 import org.onap.appc.adapter.message.Consumer;
 
  31 import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapConsumerImpl;
 
  32 import org.onap.appc.adapter.messaging.dmaap.impl.DmaapConsumerImpl;
 
  33 import org.onap.appc.configuration.Configuration;
 
  34 import org.onap.appc.configuration.ConfigurationFactory;
 
  35 import org.junit.Ignore;
 
  37 import java.util.Arrays;
 
  38 import java.util.List;
 
  41  * Must have a DMaaP cluster or simulator up and running
 
  42  * Update the hostname, topic, client properties in
 
  43  * resources/org/onap/appc/default.properties
 
  46 public class TestDmaapConsuming {
 
  48     private static Consumer dmaapConsumer;
 
  49     private static Consumer httpConsumer;
 
  52     public static void setUp() {
 
  54         Configuration configuration = ConfigurationFactory.getConfiguration();
 
  56         List<String> hosts = Arrays.asList(configuration.getProperty("poolMembers").split(","));
 
  57         String topic = configuration.getProperty("topic.read");
 
  58         String consumerName = configuration.getProperty("client.name");
 
  59         String consumerId = configuration.getProperty("client.name.id");
 
  60         String msgFilter = configuration.getProperty("message.filter");
 
  61         String user = configuration.getProperty("dmaap.appc.username");
 
  62         String password = configuration.getProperty("dmaap.appc.password");
 
  64         httpConsumer = new HttpDmaapConsumerImpl(hosts, topic, consumerName, consumerId, msgFilter);
 
  65         dmaapConsumer = new DmaapConsumerImpl(hosts, topic, consumerName, consumerId,user,password,msgFilter);
 
  70     public void testHttpFetchMessages() {
 
  71         testFetchMessages(httpConsumer);
 
  76     public void testFetchMessages() {
 
  77         testFetchMessages(dmaapConsumer);
 
  80     private void testFetchMessages(Consumer consumer) {
 
  81         List<String> messages = consumer.fetch(1000, 100);
 
  82         Assert.assertNotNull(messages);
 
  83         Assert.assertFalse(messages.isEmpty());