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.client.impl.protocol;
26 import org.onap.appc.client.impl.core.MessageContext;
27 import org.onap.appc.client.impl.protocol.AsyncProtocol;
28 import org.onap.appc.client.impl.protocol.AsyncProtocolImpl;
29 import org.onap.appc.client.impl.protocol.ProtocolException;
30 import org.onap.appc.client.impl.protocol.RetrieveMessageCallback;
31 import org.onap.appc.client.impl.protocol.UEBPropertiesKeys;
32 import org.junit.Assert;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.util.Properties;
39 import java.util.concurrent.atomic.AtomicBoolean;
41 public class TestAsyncProtocolImpl {
43 private static AsyncProtocol protocol;
44 private static AtomicBoolean gotResponse;
45 private static Properties props;
47 private static class TestCallback implements RetrieveMessageCallback{
49 public void onResponse(String payload, MessageContext context) {
50 Assert.assertNotEquals(null, payload);
51 Assert.assertNotEquals(null, context);
53 gotResponse.set(true);
58 public static void setUp() throws IOException, ProtocolException {
60 gotResponse = new AtomicBoolean(false);
62 props = new Properties();
63 String propFileName = "ueb.properties";
65 InputStream input = TestAsyncProtocolImpl.class.getClassLoader().getResourceAsStream(propFileName);
69 protocol = new AsyncProtocolImpl();
70 protocol.init(props, new TestCallback());
73 public void testSendRequest() throws ProtocolException {
75 MessageContext context = new MessageContext();
76 context.setType("Test");
78 protocol.sendRequest("{\"Test\":\"\"}", context);
81 Long timeToSleep = Long.parseLong((String)props.get(UEBPropertiesKeys.TOPIC_READ_TIMEOUT))*2;
82 Thread.sleep(timeToSleep);
83 } catch (InterruptedException e) {
84 Assert.assertFalse(e.getMessage(), false);
86 if (gotResponse.get() == false) {
87 Assert.assertFalse("Message was not read !", true);