Modify dmaap adapter license headers.
[appc.git] / appc-adapters / appc-dmaap-adapter / appc-dmaap-adapter-bundle / src / test / java / org / onap / appc / adapter / messaging / dmaap / TestDmaapProducing.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.adapter.messaging.dmaap;
25
26
27 import org.junit.Assert;
28 import org.junit.BeforeClass;
29 import org.junit.Ignore;
30 import org.junit.Test;
31 import org.onap.appc.adapter.message.Producer;
32 import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapProducerImpl;
33 import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl;
34 import org.onap.appc.configuration.Configuration;
35 import org.onap.appc.configuration.ConfigurationFactory;
36
37 import java.util.Arrays;
38 import java.util.List;
39
40 /**
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
44  *
45  */
46 public class TestDmaapProducing {
47
48     private static Producer httpProducer;
49     private static Producer dmaapProducer;
50
51     @BeforeClass
52     public static void setUp() {
53
54         Configuration configuration = ConfigurationFactory.getConfiguration();
55
56         List<String> hosts = Arrays.asList(configuration.getProperty("poolMembers").split(","));
57         String topic = configuration.getProperty("topic.write");
58         String user = configuration.getProperty("dmaap.appc.username");
59         String password = configuration.getProperty("dmaap.appc.password");
60
61         dmaapProducer = new DmaapProducerImpl(hosts, topic,user,password);
62         httpProducer = new HttpDmaapProducerImpl(hosts, topic);
63         httpProducer.updateCredentials(user,password);
64     }
65
66     @Test
67     @Ignore
68     public void testHttpPostMessage() {
69         testPostMessage(httpProducer);
70     }
71
72     @Test
73     @Ignore
74     public void testPostMessages() {
75         testPostMessage(dmaapProducer);
76     }
77
78     private void testPostMessage(Producer producer) {
79         Assert.assertTrue(producer.post("partition", "{\"message\": \"Hello, world!\"}"));
80     }
81
82 }