2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.client.impl.protocol;
27 import org.onap.appc.client.impl.core.MessageContext;
28 import org.onap.appc.client.impl.protocol.AsyncProtocol;
29 import org.onap.appc.client.impl.protocol.AsyncProtocolImpl;
30 import org.onap.appc.client.impl.protocol.ProtocolException;
31 import org.onap.appc.client.impl.protocol.RetrieveMessageCallback;
32 import org.onap.appc.client.impl.protocol.UEBPropertiesKeys;
33 import org.junit.Assert;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
37 import java.io.IOException;
38 import java.io.InputStream;
39 import java.util.Properties;
40 import java.util.concurrent.atomic.AtomicBoolean;
42 public class TestAsyncProtocolImpl {
44 private static AsyncProtocol protocol;
45 private static AtomicBoolean gotResponse;
46 private static Properties props;
48 private static class TestCallback implements RetrieveMessageCallback{
50 public void onResponse(String payload, MessageContext context) {
51 Assert.assertNotEquals(null, payload);
52 Assert.assertNotEquals(null, context);
54 gotResponse.set(true);
59 public static void setUp() throws IOException, ProtocolException {
61 gotResponse = new AtomicBoolean(false);
63 props = new Properties();
64 String propFileName = "ueb.properties";
66 InputStream input = TestAsyncProtocolImpl.class.getClassLoader().getResourceAsStream(propFileName);
70 protocol = new AsyncProtocolImpl();
71 protocol.init(props, new TestCallback());
74 public void testSendRequest() throws ProtocolException {
76 MessageContext context = new MessageContext();
77 context.setType("Test");
79 protocol.sendRequest("{\"Test\":\"\"}", context);
82 Long timeToSleep = Long.parseLong((String)props.get(UEBPropertiesKeys.TOPIC_READ_TIMEOUT))*2;
83 Thread.sleep(timeToSleep);
84 } catch (InterruptedException e) {
85 Assert.assertFalse(e.getMessage(), false);
87 if (gotResponse.get() == false) {
88 Assert.assertFalse("Message was not read !", true);