From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../appc/client/impl/core/ResponseManagerTest.java | 163 +++++++++++++++++++++ .../onap/appc/client/impl/core/SyncFlowTest.java | 151 +++++++++++++++++++ .../impl/protocol/APPCMessageReaderWriterTest.java | 104 +++++++++++++ .../impl/protocol/TestAsyncProtocolImpl.java | 91 ++++++++++++ .../TestAsyncProtocolImplMissingProps.java | 75 ++++++++++ .../TestAsyncProtocolImplNullCallback.java | 60 ++++++++ .../impl/protocol/TestUEBMessagingService.java | 70 +++++++++ .../appc/client/impl/core/ResponseManagerTest.java | 163 --------------------- .../appc/client/impl/core/SyncFlowTest.java | 151 ------------------- .../impl/protocol/APPCMessageReaderWriterTest.java | 104 ------------- .../impl/protocol/TestAsyncProtocolImpl.java | 91 ------------ .../TestAsyncProtocolImplMissingProps.java | 75 ---------- .../TestAsyncProtocolImplNullCallback.java | 60 -------- .../impl/protocol/TestUEBMessagingService.java | 70 --------- 14 files changed, 714 insertions(+), 714 deletions(-) create mode 100644 appc-client/client-lib/src/test/java/org/onap/appc/client/impl/core/ResponseManagerTest.java create mode 100644 appc-client/client-lib/src/test/java/org/onap/appc/client/impl/core/SyncFlowTest.java create mode 100644 appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/APPCMessageReaderWriterTest.java create mode 100644 appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImpl.java create mode 100644 appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImplMissingProps.java create mode 100644 appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImplNullCallback.java create mode 100644 appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestUEBMessagingService.java delete mode 100644 appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/core/ResponseManagerTest.java delete mode 100644 appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/core/SyncFlowTest.java delete mode 100644 appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/APPCMessageReaderWriterTest.java delete mode 100644 appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImpl.java delete mode 100644 appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImplMissingProps.java delete mode 100644 appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImplNullCallback.java delete mode 100644 appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestUEBMessagingService.java (limited to 'appc-client/client-lib/src/test') diff --git a/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/core/ResponseManagerTest.java b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/core/ResponseManagerTest.java new file mode 100644 index 000000000..cc157e5c4 --- /dev/null +++ b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/core/ResponseManagerTest.java @@ -0,0 +1,163 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.client.impl.core; + +import org.onap.appc.client.impl.core.AsyncRequestResponseHandler; +import org.onap.appc.client.impl.core.CoreException; +import org.onap.appc.client.impl.core.CoreManager; +import org.onap.appc.client.impl.core.ICoreAsyncResponseHandler; +import org.onap.appc.client.impl.core.MessageContext; +import org.onap.appc.client.impl.protocol.AsyncProtocol; +import org.onap.appc.client.impl.protocol.ProtocolException; +import org.onap.appc.client.impl.protocol.RetrieveMessageCallback; +import org.junit.Before; + +import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import static org.mockito.Mockito.mock; + +public class ResponseManagerTest { + + private final ExecutorService executorService = Executors.newFixedThreadPool(10); + ICoreAsyncResponseHandler listener1 = new ListenerImpl(); + ICoreAsyncResponseHandler listener2 = new SleeepListenerImpl(); + ICoreAsyncResponseHandler listener3 = new ListenerImpl(); + CoreManager coreManager = null; + + public void initialize() throws CoreException { + Properties prop = new Properties(); + prop.setProperty("client.pool.size", "10"); + prop.setProperty("client.response.timeout", "7000"); + coreManager = new ResponseManagerTest.CoreManagerTest(prop); + } + + void asyncRequest(String request, ICoreAsyncResponseHandler businessCallback, String correlationId, String rpcName) throws CoreException { + AsyncRequestResponseHandler requestResponseHandler = new AsyncRequestResponseHandler(correlationId, businessCallback, coreManager); + requestResponseHandler.sendRequest(request, correlationId, rpcName); + } + + public void simpleResponseTest() throws Exception { + System.out.println("simpleResponseTest"); + asyncRequest("request 1", listener1,"vasia1", "test"); + MessageContext msgCtx = new MessageContext(); + msgCtx.setCorrelationID("vasia1"); + msgCtx.setType("response"); + coreManager.getProtocolCallback().onResponse("vasia1 response",msgCtx); + coreManager.getProtocolCallback().onResponse("vasia2 response",msgCtx); + Thread.sleep(10); + } + + public void twoResponseTest() throws Exception { + System.out.println("twoResponseTest"); + asyncRequest("twoResponseTest request 1", listener2,"vasia2", "test"); + MessageContext msgCtx = new MessageContext(); + msgCtx.setCorrelationID("vasia2"); + msgCtx.setType("response"); + coreManager.getProtocolCallback().onResponse("second of vasia2",msgCtx); + Thread.sleep(100); + asyncRequest("twoResponseTest request 2", listener1,"vasia1", "test"); + MessageContext msgCtx2 = new MessageContext(); + msgCtx2.setCorrelationID("vasia1"); + msgCtx2.setType("response"); + coreManager.getProtocolCallback().onResponse("first of vasia1",msgCtx2); + Thread.sleep(150); + } + + public void threeResponseTest() throws Exception { + System.out.println("treeResponseTest"); + asyncRequest("threeResponseTest request 2", listener1,"vasia4", "test"); + asyncRequest("threeResponseTest request 1", listener2,"vasia2", "test"); + MessageContext msgCtx2 = new MessageContext(); + msgCtx2.setCorrelationID("vasia2"); + msgCtx2.setType("response"); + coreManager.getProtocolCallback().onResponse("second of vasia2",msgCtx2); + + asyncRequest("threeResponseTest request 2", listener1,"vasia1", "test"); + MessageContext msgCtx1 = new MessageContext(); + msgCtx1.setCorrelationID("vasia1"); + msgCtx1.setType("response"); + coreManager.getProtocolCallback().onResponse("vasia1",msgCtx1); + + asyncRequest("threeResponseTest request 3", listener3,"vasia3", "test"); + MessageContext msgCtx3 = new MessageContext(); + msgCtx3.setCorrelationID("vasia3"); + msgCtx3.setType("response"); + coreManager.getProtocolCallback().onResponse("three1",msgCtx3); + + coreManager.getProtocolCallback().onResponse("three2", msgCtx3); + + coreManager.getProtocolCallback().onResponse("first1", msgCtx1); + Thread.sleep(250); + + coreManager.getProtocolCallback().onResponse("first2", msgCtx1); + Thread.sleep(10000); + } + + private class ListenerImpl implements ICoreAsyncResponseHandler{ + + public boolean onResponse(String message, String type) { + System.out.println("callback " + message); + return message != null; + } + + @Override + public void onException(Exception e) { + e.printStackTrace(); + } + } + + private class SleeepListenerImpl implements ICoreAsyncResponseHandler{ + + public boolean onResponse(String message, String type) { + try { + Thread.sleep(150); + System.out.println("sleep callback " + message); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return message != null; + } + + @Override + public void onException(Exception e) { + e.printStackTrace(); + } + } + + class CoreManagerTest extends CoreManager{ + CoreManagerTest(Properties properties) throws CoreException { + super(properties); + protocol = mock(AsyncProtocol.class); + } + protected void sendRequest2Protocol(String request, String corrId, String rpcName) throws CoreException { + } + + protected void initProtocol(Properties properties, RetrieveMessageCallback protocolCallback) throws ProtocolException { + + } + } +} diff --git a/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/core/SyncFlowTest.java b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/core/SyncFlowTest.java new file mode 100644 index 000000000..2e69369b9 --- /dev/null +++ b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/core/SyncFlowTest.java @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.client.impl.core; + +import org.onap.appc.client.impl.core.CoreException; +import org.onap.appc.client.impl.core.CoreManager; +import org.onap.appc.client.impl.core.ICoreSyncResponseHandler; +import org.onap.appc.client.impl.core.MessageContext; +import org.onap.appc.client.impl.core.SyncRequestResponseHandler; +import org.onap.appc.client.impl.protocol.AsyncProtocol; +import org.onap.appc.client.impl.protocol.ProtocolException; +import org.onap.appc.client.impl.protocol.RetrieveMessageCallback; +import org.junit.Assert; +import org.junit.Before; + +import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeoutException; + +import static org.mockito.Mockito.mock; + +public class SyncFlowTest { + CoreManager coreManager = null; + + public void initialize() throws CoreException { + Properties prop = new Properties(); + prop.setProperty("client.pool.size", "10"); + prop.setProperty("client.response.timeout", "7000"); + coreManager = new CoreManagerTest(prop); + } + + T syncRequest(String request, ICoreSyncResponseHandler businessCallback, String correlationId, String rpcName ) throws CoreException, TimeoutException { + SyncRequestResponseHandler requestResponseHandler = new SyncRequestResponseHandler(correlationId, businessCallback, coreManager); + requestResponseHandler.sendRequest(request, correlationId, rpcName); + T responseObject = (T) requestResponseHandler.getResponse(); + return responseObject; + } + + public void blockRequestTest(){ + ICoreSyncResponseHandler handler = new ICoreSyncResponseHandlerImpl1(); + try { + syncRequest("request 1", handler, "vasia1", "test"); + }catch (Throwable e){ + e.printStackTrace(); + Assert.assertTrue(e != null); + } + + } + + public void blockRequestSucceedTest() throws InterruptedException { + ExecutorService executorService = Executors.newFixedThreadPool(2); + final ICoreSyncResponseHandler handler = new ICoreSyncResponseHandlerImpl1(); + try { + executorService.submit(new Runnable() { + public void run() { + System.out.println("Send request"); + T response; + try { + response = syncRequest("request 1", handler, "vasia1", "test"); + System.out.println("=======" + response.toString()); + } catch (CoreException e) { + e.printStackTrace(); + } catch (TimeoutException e) { + e.printStackTrace(); + } + } + }); + }catch (Throwable e){ + Assert.assertTrue((RuntimeException)e != null); + } + Thread.sleep(2000); + executorService.submit(new Runnable() { + public void run() { + MessageContext ctx = new MessageContext(); + ctx.setCorrelationID("vasia1"); + ctx.setType("response"); + try { + System.out.println("Send response 1"); + coreManager.getProtocolCallback().onResponse("response for request 1", ctx); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + + Thread.sleep(2000); + executorService.submit(new Runnable() { + public void run() { + MessageContext ctx = new MessageContext(); + ctx.setCorrelationID("vasia1"); + ctx.setType("response"); + try { + System.out.println("Send response 2"); + coreManager.getProtocolCallback().onResponse("response for request 1 final", ctx); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + Thread.sleep(1000); + + } + + class ICoreSyncResponseHandlerImpl1 implements ICoreSyncResponseHandler{ + + + public T onResponse(String message, String type) { + System.out.println("Received message = " + message) ; + if(message.contains("final")){ + return (T) new String(message); + } + return null; + } + } + + class CoreManagerTest extends CoreManager{ + CoreManagerTest(Properties properties) throws CoreException { + super(properties); + protocol = mock(AsyncProtocol.class); + } + protected void sendRequest2Protocol(String request, String corrId, String rpcName) throws CoreException { + } + + protected void initProtocol(Properties properties, RetrieveMessageCallback protocolCallback) throws ProtocolException{ + + } + } +} diff --git a/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/APPCMessageReaderWriterTest.java b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/APPCMessageReaderWriterTest.java new file mode 100644 index 000000000..1d41a52f8 --- /dev/null +++ b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/APPCMessageReaderWriterTest.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.client.impl.protocol; + +import org.onap.appc.client.impl.core.MessageContext; +import org.onap.appc.client.impl.protocol.APPCMessageReaderWriter; +import org.onap.appc.client.impl.protocol.ProtocolException; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.io.StringWriter; + +public class APPCMessageReaderWriterTest { + + private APPCMessageReaderWriter messageReaderWriter; + private ObjectMapper mapper; + + private static final String VERSION = "2.0"; + private static final String TYPE = "typeTest"; + private static final String CORRELATION_ID = "correlationIdTest"; + private static final String PARTITION = "partitionTest"; + private static final String RPC = "rpcTest"; + private static final String PAYLOAD = "{\"key1\":\"val1\",\"key2\":\"val2\",\"key3\":{\"key3.1\":\"val3.1\"}}"; + + @Before + public void init() throws IOException { + mapper = new ObjectMapper(); + messageReaderWriter = new APPCMessageReaderWriter(); + } + + @Test + public void writeTest() throws IOException, ProtocolException { + MessageContext context = new MessageContext(); + context.setType(TYPE); + context.setCorrelationID(CORRELATION_ID); + context.setPartiton(PARTITION); + context.setRpc(RPC); + String payload = PAYLOAD; + String message = messageReaderWriter.write(payload, context); + + JsonNode messageJson = mapper.readTree(message); + Assert.assertEquals(VERSION, messageJson.get("version").asText()); + Assert.assertEquals(context.getType(), messageJson.get("type").asText()); + Assert.assertEquals(context.getCorrelationID(), messageJson.get("correlation-id").asText()); + Assert.assertEquals(context.getPartiton(), messageJson.get("cambria.partition").asText()); + Assert.assertEquals(context.getRpc(), messageJson.get("rpc-name").asText()); + Assert.assertEquals(payload, messageJson.get("body").toString()); + } + + @Test + public void readTest() throws IOException, ProtocolException { + ObjectNode node = mapper.createObjectNode(); + node.put("version", VERSION); + node.put("type", TYPE); + node.put("correlation-id", CORRELATION_ID); + node.put("cambria.partition", PARTITION); + node.put("rpc-name", RPC); + JsonNode payload = mapper.valueToTree(PAYLOAD); + node.set("body", payload); + String message = node.toString(); + + MessageContext returnContext = new MessageContext(); + String returnPayload = messageReaderWriter.read(message, returnContext); + + Assert.assertEquals(TYPE, returnContext.getType()); + Assert.assertEquals(CORRELATION_ID, returnContext.getCorrelationID()); + Assert.assertEquals(PARTITION, returnContext.getPartiton()); + Assert.assertEquals(RPC, returnContext.getRpc()); + Assert.assertEquals(payload.toString(), returnPayload); + } + +} diff --git a/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImpl.java b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImpl.java new file mode 100644 index 000000000..ceba10b58 --- /dev/null +++ b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImpl.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.client.impl.protocol; + +import org.onap.appc.client.impl.core.MessageContext; +import org.onap.appc.client.impl.protocol.AsyncProtocol; +import org.onap.appc.client.impl.protocol.AsyncProtocolImpl; +import org.onap.appc.client.impl.protocol.ProtocolException; +import org.onap.appc.client.impl.protocol.RetrieveMessageCallback; +import org.onap.appc.client.impl.protocol.UEBPropertiesKeys; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicBoolean; + +public class TestAsyncProtocolImpl { + + private static AsyncProtocol protocol; + private static AtomicBoolean gotResponse; + private static Properties props; + + private static class TestCallback implements RetrieveMessageCallback{ + + public void onResponse(String payload, MessageContext context) { + Assert.assertNotEquals(null, payload); + Assert.assertNotEquals(null, context); + protocol = null; + gotResponse.set(true); + } + } + + @BeforeClass + public static void setUp() throws IOException, ProtocolException { + + gotResponse = new AtomicBoolean(false); + + props = new Properties(); + String propFileName = "ueb.properties"; + + InputStream input = TestAsyncProtocolImpl.class.getClassLoader().getResourceAsStream(propFileName); + + props.load(input); + + protocol = new AsyncProtocolImpl(); + protocol.init(props, new TestCallback()); + } + + public void testSendRequest() throws ProtocolException { + + MessageContext context = new MessageContext(); + context.setType("Test"); + + protocol.sendRequest("{\"Test\":\"\"}", context); + + try { + Long timeToSleep = Long.parseLong((String)props.get(UEBPropertiesKeys.TOPIC_READ_TIMEOUT))*2; + Thread.sleep(timeToSleep); + } catch (InterruptedException e) { + Assert.assertFalse(e.getMessage(), false); + } + if (gotResponse.get() == false) { + Assert.assertFalse("Message was not read !", true); + } + } +} diff --git a/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImplMissingProps.java b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImplMissingProps.java new file mode 100644 index 000000000..267282abd --- /dev/null +++ b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImplMissingProps.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.client.impl.protocol; + +import org.onap.appc.client.impl.core.MessageContext; +import org.onap.appc.client.impl.protocol.AsyncProtocol; +import org.onap.appc.client.impl.protocol.AsyncProtocolImpl; +import org.onap.appc.client.impl.protocol.RetrieveMessageCallback; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class TestAsyncProtocolImplMissingProps { + + private static AsyncProtocol protocol; + + private static class TestCallback implements RetrieveMessageCallback { + + public void onResponse(String payload, MessageContext context) { + Assert.assertFalse("bad Callback !",false); + } + } + + @Test + /** + * protocol should throw illegal argument exception due to null properties + */ + public void testSetUpMissingProps() { + + Properties props = new Properties(); + String propFileName = "ueb.missing.properties"; + + InputStream input = TestAsyncProtocolImplMissingProps.class.getClassLoader().getResourceAsStream(propFileName); + + try { + props.load(input); + } catch (IOException e) { + Assert.assertFalse(e.getMessage(),false); + } + + protocol = new AsyncProtocolImpl(); + try { + protocol.init(props, new TestCallback()); + } catch (IllegalArgumentException e) { + Assert.assertTrue(true); + } catch (Exception e) { + Assert.assertFalse(e.getMessage(),false); + } + } +} diff --git a/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImplNullCallback.java b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImplNullCallback.java new file mode 100644 index 000000000..22954cd75 --- /dev/null +++ b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestAsyncProtocolImplNullCallback.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.client.impl.protocol; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.client.impl.protocol.AsyncProtocol; +import org.onap.appc.client.impl.protocol.AsyncProtocolImpl; +import org.onap.appc.client.impl.protocol.ProtocolException; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class TestAsyncProtocolImplNullCallback { + + private static AsyncProtocol protocol; + + public void testSetUpNoCallback() throws IOException { + + Properties props = new Properties(); + String propFileName = "ueb.properties"; + + InputStream input = TestAsyncProtocolImpl.class.getClassLoader().getResourceAsStream(propFileName); + + props.load(input); + + protocol = new AsyncProtocolImpl(); + + try { + protocol.init(props, null); + } catch (ProtocolException e) { + Assert.assertTrue(true); + } catch (Exception e){ + Assert.assertFalse(e.getMessage(),false); + } + } +} diff --git a/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestUEBMessagingService.java b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestUEBMessagingService.java new file mode 100644 index 000000000..de192ab12 --- /dev/null +++ b/appc-client/client-lib/src/test/java/org/onap/appc/client/impl/protocol/TestUEBMessagingService.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.client.impl.protocol; + +import org.junit.*; +import org.junit.runners.MethodSorters; +import org.onap.appc.client.impl.protocol.MessagingService; +import org.onap.appc.client.impl.protocol.UEBMessagingService; + +import java.io.IOException; +import java.io.InputStream; +import java.security.GeneralSecurityException; +import java.util.List; +import java.util.Properties; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestUEBMessagingService { + + private static MessagingService ueb; + + public static void setUp() throws IOException, GeneralSecurityException, NoSuchFieldException, IllegalAccessException { + + Properties props = new Properties(); + String propFileName = "ueb.properties"; + + InputStream input = TestUEBMessagingService.class.getClassLoader().getResourceAsStream(propFileName); + + props.load(input); + + ueb = new UEBMessagingService(); + ueb.init(props); + } + + public void test1Send() throws IOException { + System.out.println("Here"); + + String message = "Test Message Service"; + ueb.send(null,message); + } + + public void test2Fetch() throws IOException { + + System.out.println("Here2"); + List messages = ueb.fetch(1); + Assert.assertEquals(1,messages.size()); + } + +} diff --git a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/core/ResponseManagerTest.java b/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/core/ResponseManagerTest.java deleted file mode 100644 index cc157e5c4..000000000 --- a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/core/ResponseManagerTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.client.impl.core; - -import org.onap.appc.client.impl.core.AsyncRequestResponseHandler; -import org.onap.appc.client.impl.core.CoreException; -import org.onap.appc.client.impl.core.CoreManager; -import org.onap.appc.client.impl.core.ICoreAsyncResponseHandler; -import org.onap.appc.client.impl.core.MessageContext; -import org.onap.appc.client.impl.protocol.AsyncProtocol; -import org.onap.appc.client.impl.protocol.ProtocolException; -import org.onap.appc.client.impl.protocol.RetrieveMessageCallback; -import org.junit.Before; - -import java.util.Properties; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static org.mockito.Mockito.mock; - -public class ResponseManagerTest { - - private final ExecutorService executorService = Executors.newFixedThreadPool(10); - ICoreAsyncResponseHandler listener1 = new ListenerImpl(); - ICoreAsyncResponseHandler listener2 = new SleeepListenerImpl(); - ICoreAsyncResponseHandler listener3 = new ListenerImpl(); - CoreManager coreManager = null; - - public void initialize() throws CoreException { - Properties prop = new Properties(); - prop.setProperty("client.pool.size", "10"); - prop.setProperty("client.response.timeout", "7000"); - coreManager = new ResponseManagerTest.CoreManagerTest(prop); - } - - void asyncRequest(String request, ICoreAsyncResponseHandler businessCallback, String correlationId, String rpcName) throws CoreException { - AsyncRequestResponseHandler requestResponseHandler = new AsyncRequestResponseHandler(correlationId, businessCallback, coreManager); - requestResponseHandler.sendRequest(request, correlationId, rpcName); - } - - public void simpleResponseTest() throws Exception { - System.out.println("simpleResponseTest"); - asyncRequest("request 1", listener1,"vasia1", "test"); - MessageContext msgCtx = new MessageContext(); - msgCtx.setCorrelationID("vasia1"); - msgCtx.setType("response"); - coreManager.getProtocolCallback().onResponse("vasia1 response",msgCtx); - coreManager.getProtocolCallback().onResponse("vasia2 response",msgCtx); - Thread.sleep(10); - } - - public void twoResponseTest() throws Exception { - System.out.println("twoResponseTest"); - asyncRequest("twoResponseTest request 1", listener2,"vasia2", "test"); - MessageContext msgCtx = new MessageContext(); - msgCtx.setCorrelationID("vasia2"); - msgCtx.setType("response"); - coreManager.getProtocolCallback().onResponse("second of vasia2",msgCtx); - Thread.sleep(100); - asyncRequest("twoResponseTest request 2", listener1,"vasia1", "test"); - MessageContext msgCtx2 = new MessageContext(); - msgCtx2.setCorrelationID("vasia1"); - msgCtx2.setType("response"); - coreManager.getProtocolCallback().onResponse("first of vasia1",msgCtx2); - Thread.sleep(150); - } - - public void threeResponseTest() throws Exception { - System.out.println("treeResponseTest"); - asyncRequest("threeResponseTest request 2", listener1,"vasia4", "test"); - asyncRequest("threeResponseTest request 1", listener2,"vasia2", "test"); - MessageContext msgCtx2 = new MessageContext(); - msgCtx2.setCorrelationID("vasia2"); - msgCtx2.setType("response"); - coreManager.getProtocolCallback().onResponse("second of vasia2",msgCtx2); - - asyncRequest("threeResponseTest request 2", listener1,"vasia1", "test"); - MessageContext msgCtx1 = new MessageContext(); - msgCtx1.setCorrelationID("vasia1"); - msgCtx1.setType("response"); - coreManager.getProtocolCallback().onResponse("vasia1",msgCtx1); - - asyncRequest("threeResponseTest request 3", listener3,"vasia3", "test"); - MessageContext msgCtx3 = new MessageContext(); - msgCtx3.setCorrelationID("vasia3"); - msgCtx3.setType("response"); - coreManager.getProtocolCallback().onResponse("three1",msgCtx3); - - coreManager.getProtocolCallback().onResponse("three2", msgCtx3); - - coreManager.getProtocolCallback().onResponse("first1", msgCtx1); - Thread.sleep(250); - - coreManager.getProtocolCallback().onResponse("first2", msgCtx1); - Thread.sleep(10000); - } - - private class ListenerImpl implements ICoreAsyncResponseHandler{ - - public boolean onResponse(String message, String type) { - System.out.println("callback " + message); - return message != null; - } - - @Override - public void onException(Exception e) { - e.printStackTrace(); - } - } - - private class SleeepListenerImpl implements ICoreAsyncResponseHandler{ - - public boolean onResponse(String message, String type) { - try { - Thread.sleep(150); - System.out.println("sleep callback " + message); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return message != null; - } - - @Override - public void onException(Exception e) { - e.printStackTrace(); - } - } - - class CoreManagerTest extends CoreManager{ - CoreManagerTest(Properties properties) throws CoreException { - super(properties); - protocol = mock(AsyncProtocol.class); - } - protected void sendRequest2Protocol(String request, String corrId, String rpcName) throws CoreException { - } - - protected void initProtocol(Properties properties, RetrieveMessageCallback protocolCallback) throws ProtocolException { - - } - } -} diff --git a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/core/SyncFlowTest.java b/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/core/SyncFlowTest.java deleted file mode 100644 index 2e69369b9..000000000 --- a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/core/SyncFlowTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.client.impl.core; - -import org.onap.appc.client.impl.core.CoreException; -import org.onap.appc.client.impl.core.CoreManager; -import org.onap.appc.client.impl.core.ICoreSyncResponseHandler; -import org.onap.appc.client.impl.core.MessageContext; -import org.onap.appc.client.impl.core.SyncRequestResponseHandler; -import org.onap.appc.client.impl.protocol.AsyncProtocol; -import org.onap.appc.client.impl.protocol.ProtocolException; -import org.onap.appc.client.impl.protocol.RetrieveMessageCallback; -import org.junit.Assert; -import org.junit.Before; - -import java.util.Properties; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeoutException; - -import static org.mockito.Mockito.mock; - -public class SyncFlowTest { - CoreManager coreManager = null; - - public void initialize() throws CoreException { - Properties prop = new Properties(); - prop.setProperty("client.pool.size", "10"); - prop.setProperty("client.response.timeout", "7000"); - coreManager = new CoreManagerTest(prop); - } - - T syncRequest(String request, ICoreSyncResponseHandler businessCallback, String correlationId, String rpcName ) throws CoreException, TimeoutException { - SyncRequestResponseHandler requestResponseHandler = new SyncRequestResponseHandler(correlationId, businessCallback, coreManager); - requestResponseHandler.sendRequest(request, correlationId, rpcName); - T responseObject = (T) requestResponseHandler.getResponse(); - return responseObject; - } - - public void blockRequestTest(){ - ICoreSyncResponseHandler handler = new ICoreSyncResponseHandlerImpl1(); - try { - syncRequest("request 1", handler, "vasia1", "test"); - }catch (Throwable e){ - e.printStackTrace(); - Assert.assertTrue(e != null); - } - - } - - public void blockRequestSucceedTest() throws InterruptedException { - ExecutorService executorService = Executors.newFixedThreadPool(2); - final ICoreSyncResponseHandler handler = new ICoreSyncResponseHandlerImpl1(); - try { - executorService.submit(new Runnable() { - public void run() { - System.out.println("Send request"); - T response; - try { - response = syncRequest("request 1", handler, "vasia1", "test"); - System.out.println("=======" + response.toString()); - } catch (CoreException e) { - e.printStackTrace(); - } catch (TimeoutException e) { - e.printStackTrace(); - } - } - }); - }catch (Throwable e){ - Assert.assertTrue((RuntimeException)e != null); - } - Thread.sleep(2000); - executorService.submit(new Runnable() { - public void run() { - MessageContext ctx = new MessageContext(); - ctx.setCorrelationID("vasia1"); - ctx.setType("response"); - try { - System.out.println("Send response 1"); - coreManager.getProtocolCallback().onResponse("response for request 1", ctx); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - - Thread.sleep(2000); - executorService.submit(new Runnable() { - public void run() { - MessageContext ctx = new MessageContext(); - ctx.setCorrelationID("vasia1"); - ctx.setType("response"); - try { - System.out.println("Send response 2"); - coreManager.getProtocolCallback().onResponse("response for request 1 final", ctx); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - Thread.sleep(1000); - - } - - class ICoreSyncResponseHandlerImpl1 implements ICoreSyncResponseHandler{ - - - public T onResponse(String message, String type) { - System.out.println("Received message = " + message) ; - if(message.contains("final")){ - return (T) new String(message); - } - return null; - } - } - - class CoreManagerTest extends CoreManager{ - CoreManagerTest(Properties properties) throws CoreException { - super(properties); - protocol = mock(AsyncProtocol.class); - } - protected void sendRequest2Protocol(String request, String corrId, String rpcName) throws CoreException { - } - - protected void initProtocol(Properties properties, RetrieveMessageCallback protocolCallback) throws ProtocolException{ - - } - } -} diff --git a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/APPCMessageReaderWriterTest.java b/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/APPCMessageReaderWriterTest.java deleted file mode 100644 index 1d41a52f8..000000000 --- a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/APPCMessageReaderWriterTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.client.impl.protocol; - -import org.onap.appc.client.impl.core.MessageContext; -import org.onap.appc.client.impl.protocol.APPCMessageReaderWriter; -import org.onap.appc.client.impl.protocol.ProtocolException; - -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.io.StringWriter; - -public class APPCMessageReaderWriterTest { - - private APPCMessageReaderWriter messageReaderWriter; - private ObjectMapper mapper; - - private static final String VERSION = "2.0"; - private static final String TYPE = "typeTest"; - private static final String CORRELATION_ID = "correlationIdTest"; - private static final String PARTITION = "partitionTest"; - private static final String RPC = "rpcTest"; - private static final String PAYLOAD = "{\"key1\":\"val1\",\"key2\":\"val2\",\"key3\":{\"key3.1\":\"val3.1\"}}"; - - @Before - public void init() throws IOException { - mapper = new ObjectMapper(); - messageReaderWriter = new APPCMessageReaderWriter(); - } - - @Test - public void writeTest() throws IOException, ProtocolException { - MessageContext context = new MessageContext(); - context.setType(TYPE); - context.setCorrelationID(CORRELATION_ID); - context.setPartiton(PARTITION); - context.setRpc(RPC); - String payload = PAYLOAD; - String message = messageReaderWriter.write(payload, context); - - JsonNode messageJson = mapper.readTree(message); - Assert.assertEquals(VERSION, messageJson.get("version").asText()); - Assert.assertEquals(context.getType(), messageJson.get("type").asText()); - Assert.assertEquals(context.getCorrelationID(), messageJson.get("correlation-id").asText()); - Assert.assertEquals(context.getPartiton(), messageJson.get("cambria.partition").asText()); - Assert.assertEquals(context.getRpc(), messageJson.get("rpc-name").asText()); - Assert.assertEquals(payload, messageJson.get("body").toString()); - } - - @Test - public void readTest() throws IOException, ProtocolException { - ObjectNode node = mapper.createObjectNode(); - node.put("version", VERSION); - node.put("type", TYPE); - node.put("correlation-id", CORRELATION_ID); - node.put("cambria.partition", PARTITION); - node.put("rpc-name", RPC); - JsonNode payload = mapper.valueToTree(PAYLOAD); - node.set("body", payload); - String message = node.toString(); - - MessageContext returnContext = new MessageContext(); - String returnPayload = messageReaderWriter.read(message, returnContext); - - Assert.assertEquals(TYPE, returnContext.getType()); - Assert.assertEquals(CORRELATION_ID, returnContext.getCorrelationID()); - Assert.assertEquals(PARTITION, returnContext.getPartiton()); - Assert.assertEquals(RPC, returnContext.getRpc()); - Assert.assertEquals(payload.toString(), returnPayload); - } - -} diff --git a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImpl.java b/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImpl.java deleted file mode 100644 index ceba10b58..000000000 --- a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.client.impl.protocol; - -import org.onap.appc.client.impl.core.MessageContext; -import org.onap.appc.client.impl.protocol.AsyncProtocol; -import org.onap.appc.client.impl.protocol.AsyncProtocolImpl; -import org.onap.appc.client.impl.protocol.ProtocolException; -import org.onap.appc.client.impl.protocol.RetrieveMessageCallback; -import org.onap.appc.client.impl.protocol.UEBPropertiesKeys; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; - -public class TestAsyncProtocolImpl { - - private static AsyncProtocol protocol; - private static AtomicBoolean gotResponse; - private static Properties props; - - private static class TestCallback implements RetrieveMessageCallback{ - - public void onResponse(String payload, MessageContext context) { - Assert.assertNotEquals(null, payload); - Assert.assertNotEquals(null, context); - protocol = null; - gotResponse.set(true); - } - } - - @BeforeClass - public static void setUp() throws IOException, ProtocolException { - - gotResponse = new AtomicBoolean(false); - - props = new Properties(); - String propFileName = "ueb.properties"; - - InputStream input = TestAsyncProtocolImpl.class.getClassLoader().getResourceAsStream(propFileName); - - props.load(input); - - protocol = new AsyncProtocolImpl(); - protocol.init(props, new TestCallback()); - } - - public void testSendRequest() throws ProtocolException { - - MessageContext context = new MessageContext(); - context.setType("Test"); - - protocol.sendRequest("{\"Test\":\"\"}", context); - - try { - Long timeToSleep = Long.parseLong((String)props.get(UEBPropertiesKeys.TOPIC_READ_TIMEOUT))*2; - Thread.sleep(timeToSleep); - } catch (InterruptedException e) { - Assert.assertFalse(e.getMessage(), false); - } - if (gotResponse.get() == false) { - Assert.assertFalse("Message was not read !", true); - } - } -} diff --git a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImplMissingProps.java b/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImplMissingProps.java deleted file mode 100644 index 267282abd..000000000 --- a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImplMissingProps.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.client.impl.protocol; - -import org.onap.appc.client.impl.core.MessageContext; -import org.onap.appc.client.impl.protocol.AsyncProtocol; -import org.onap.appc.client.impl.protocol.AsyncProtocolImpl; -import org.onap.appc.client.impl.protocol.RetrieveMessageCallback; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -public class TestAsyncProtocolImplMissingProps { - - private static AsyncProtocol protocol; - - private static class TestCallback implements RetrieveMessageCallback { - - public void onResponse(String payload, MessageContext context) { - Assert.assertFalse("bad Callback !",false); - } - } - - @Test - /** - * protocol should throw illegal argument exception due to null properties - */ - public void testSetUpMissingProps() { - - Properties props = new Properties(); - String propFileName = "ueb.missing.properties"; - - InputStream input = TestAsyncProtocolImplMissingProps.class.getClassLoader().getResourceAsStream(propFileName); - - try { - props.load(input); - } catch (IOException e) { - Assert.assertFalse(e.getMessage(),false); - } - - protocol = new AsyncProtocolImpl(); - try { - protocol.init(props, new TestCallback()); - } catch (IllegalArgumentException e) { - Assert.assertTrue(true); - } catch (Exception e) { - Assert.assertFalse(e.getMessage(),false); - } - } -} diff --git a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImplNullCallback.java b/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImplNullCallback.java deleted file mode 100644 index 22954cd75..000000000 --- a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestAsyncProtocolImplNullCallback.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.client.impl.protocol; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.client.impl.protocol.AsyncProtocol; -import org.onap.appc.client.impl.protocol.AsyncProtocolImpl; -import org.onap.appc.client.impl.protocol.ProtocolException; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -public class TestAsyncProtocolImplNullCallback { - - private static AsyncProtocol protocol; - - public void testSetUpNoCallback() throws IOException { - - Properties props = new Properties(); - String propFileName = "ueb.properties"; - - InputStream input = TestAsyncProtocolImpl.class.getClassLoader().getResourceAsStream(propFileName); - - props.load(input); - - protocol = new AsyncProtocolImpl(); - - try { - protocol.init(props, null); - } catch (ProtocolException e) { - Assert.assertTrue(true); - } catch (Exception e){ - Assert.assertFalse(e.getMessage(),false); - } - } -} diff --git a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestUEBMessagingService.java b/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestUEBMessagingService.java deleted file mode 100644 index de192ab12..000000000 --- a/appc-client/client-lib/src/test/java/org/openecomp/appc/client/impl/protocol/TestUEBMessagingService.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.client.impl.protocol; - -import org.junit.*; -import org.junit.runners.MethodSorters; -import org.onap.appc.client.impl.protocol.MessagingService; -import org.onap.appc.client.impl.protocol.UEBMessagingService; - -import java.io.IOException; -import java.io.InputStream; -import java.security.GeneralSecurityException; -import java.util.List; -import java.util.Properties; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestUEBMessagingService { - - private static MessagingService ueb; - - public static void setUp() throws IOException, GeneralSecurityException, NoSuchFieldException, IllegalAccessException { - - Properties props = new Properties(); - String propFileName = "ueb.properties"; - - InputStream input = TestUEBMessagingService.class.getClassLoader().getResourceAsStream(propFileName); - - props.load(input); - - ueb = new UEBMessagingService(); - ueb.init(props); - } - - public void test1Send() throws IOException { - System.out.println("Here"); - - String message = "Test Message Service"; - ueb.send(null,message); - } - - public void test2Fetch() throws IOException { - - System.out.println("Here2"); - List messages = ueb.fetch(1); - Assert.assertEquals(1,messages.size()); - } - -} -- cgit 1.2.3-korg