diff options
author | Patrick Brady <patrick.brady@att.com> | 2019-10-29 12:50:10 -0700 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2019-11-08 16:39:57 +0000 |
commit | 790ddb83355800cc037ea1ea3ca8610bb78018d5 (patch) | |
tree | 56edf2c12e5c2d7a0955dd3fa791cbe09b670828 /appc-dg/appc-dg-shared/appc-dg-common/src/test/java | |
parent | 1843caa854f58b133e2c97e5d75a4705f2942280 (diff) |
Change code to use dmaap microservice
Change method calls that used to go to the dmaap adapter, to
now go to the appc service communicator, which connects to the
dmaap micro service.
Change-Id: I619fcb408e14fa0b926950192463d9c92ab7dbba
Signed-off-by: Patrick Brady <patrick.brady@att.com>
Issue-ID: APPC-1744
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-common/src/test/java')
4 files changed, 78 insertions, 131 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java index 95f7ba755..1816f52f9 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -30,27 +30,16 @@ import java.util.Map; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mockito; -import org.mockito.Spy; -import org.onap.appc.adapter.message.EventSender; -import org.onap.appc.adapter.message.MessageDestination; -import org.onap.appc.adapter.message.event.EventMessage; import org.onap.appc.exceptions.APPCException; +import org.onap.appc.srvcomm.messaging.MessageDestination; +import org.onap.appc.srvcomm.messaging.event.EventMessage; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest(FrameworkUtil.class) public class DCAEReporterPluginImplTest { private SvcLogicContext ctx; private Map<String, String> params; @@ -59,10 +48,8 @@ public class DCAEReporterPluginImplTest { private final Bundle bundleService = Mockito.mock(Bundle.class); private final ServiceReference sref = Mockito.mock(ServiceReference.class); - @InjectMocks private DCAEReporterPluginImpl dcaeReporterPlugin; - @Spy - private EventSenderMock eventSender = new EventSenderMock(); + private MockEventSender eventSender; private String apiVer = "2.0.0"; private String requestId = "123"; @@ -71,11 +58,10 @@ public class DCAEReporterPluginImplTest { @SuppressWarnings("unchecked") @Before public void setUp() throws NoSuchFieldException, IllegalAccessException { - PowerMockito.mockStatic(FrameworkUtil.class); - PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService); - PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); - PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref); - PowerMockito.when(bundleContext.<EventSender>getService(sref)).thenReturn(eventSender); + eventSender = new MockEventSender(); + dcaeReporterPlugin = new DCAEReporterPluginImpl(); + dcaeReporterPlugin.setEventSender(eventSender); + } @Test @@ -110,7 +96,7 @@ public class DCAEReporterPluginImplTest { ctx.setAttribute("input.common-header.api-ver", apiVer); ctx.setAttribute("input.common-header.request-id", requestId); dcaeReporterPlugin.report(params, ctx); - EventMessage msg = eventSender.getMsg(); + EventMessage msg = eventSender.getMessage(); Assert.assertEquals("ERROR DESCRIPTION", msg.getEventStatus().getReason()); } @@ -120,14 +106,15 @@ public class DCAEReporterPluginImplTest { params = new HashMap<>(); params.put(Constants.DG_ERROR_CODE, "200"); dcaeReporterPlugin.reportSuccess(params, ctx); - EventMessage msg = eventSender.getMsg(); + EventMessage msg = eventSender.getMessage(); Assert.assertEquals(new Integer(500), msg.getEventStatus().getCode()); } private void errorReasonNullAssert() throws APPCException { + eventSender.reset(); dcaeReporterPlugin.report(params, ctx); MessageDestination destination = eventSender.getDestination(); - EventMessage msg = eventSender.getMsg(); + EventMessage msg = eventSender.getMessage(); Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer()); Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId()); Assert.assertEquals("wrong error message", "Unknown", msg.getEventStatus().getReason()); @@ -135,9 +122,10 @@ public class DCAEReporterPluginImplTest { } private void positiveAssert() throws APPCException { + eventSender.reset(); dcaeReporterPlugin.report(params, ctx); MessageDestination destination = eventSender.getDestination(); - EventMessage msg = eventSender.getMsg(); + EventMessage msg = eventSender.getMessage(); Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer()); Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId()); Assert.assertEquals("wrong error message", error, msg.getEventStatus().getReason()); diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java deleted file mode 100644 index 54959958d..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017-2018 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. - * - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import java.util.Map; -import org.onap.appc.adapter.message.EventSender; -import org.onap.appc.adapter.message.MessageDestination; -import org.onap.appc.adapter.message.event.EventMessage; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - - -public class EventSenderMock implements EventSender { - EventMessage msg; - MessageDestination destination; - - @Override - public boolean sendEvent(MessageDestination destination, EventMessage msg) { - if (destination != null && msg != null){ - this.msg = msg; - this.destination = destination; - return true; - } - else{ - return false; - } - } - - @Override - public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) { - return false; - } - - @Override - public boolean sendEvent(MessageDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException { - return false; - } - - public EventMessage getMsg() { - return msg; - } - - public MessageDestination getDestination() { - return destination; - } -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImplTest.java index 74c1ec7a5..33761f9fd 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImplTest.java @@ -3,7 +3,9 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Ericsson - * ============================================================================= + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * 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 @@ -24,58 +26,27 @@ package org.onap.appc.dg.common.impl; import java.util.HashMap; import java.util.Map; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mockito; -import org.mockito.Spy; -import org.onap.appc.adapter.message.MessageAdapterFactory; -import org.onap.appc.adapter.message.Producer; +import org.onap.appc.srvcomm.messaging.MessagingConnector; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest(FrameworkUtil.class) public class IntermediateMessageSenderImplTest { private SvcLogicContext ctx; private Map<String, String> params; - private final BundleContext bundleContext = Mockito.mock(BundleContext.class); - private final Bundle bundleService = Mockito.mock(Bundle.class); - private final ServiceReference sref = Mockito.mock(ServiceReference.class); - private final MessageAdapterFactory mockFactory = Mockito.mock(MessageAdapterFactory.class); - private final Producer mockProducer = Mockito.mock(Producer.class); - @InjectMocks private IntermediateMessageSenderImpl intermediateMessageSenderImpl; - @Spy - private EventSenderMock eventSender = new EventSenderMock(); - @SuppressWarnings("unchecked") - @Before - public void setUp() throws NoSuchFieldException, IllegalAccessException { - PowerMockito.mockStatic(FrameworkUtil.class); - PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService); - PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); - PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref); - PowerMockito.when(bundleContext.<MessageAdapterFactory>getService(sref)).thenReturn(mockFactory); - PowerMockito.when(mockFactory.createProducer(Matchers.anyCollection(), Mockito.anyString(), Mockito.anyString(), - Mockito.anyString())).thenReturn(mockProducer); - } @Test public void testSendEmptyMessage() { - intermediateMessageSenderImpl.init(); + intermediateMessageSenderImpl = new IntermediateMessageSenderImpl(); + MessagingConnector msgConn = Mockito.mock(MessagingConnector.class); + Mockito.when(msgConn.publishMessage(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(false); + intermediateMessageSenderImpl.init(msgConn); ctx = new SvcLogicContext(); params = new HashMap<>(); intermediateMessageSenderImpl.sendMessage(params, ctx); @@ -84,7 +55,10 @@ public class IntermediateMessageSenderImplTest { @Test public void testSendMessage() { - intermediateMessageSenderImpl.init(); + intermediateMessageSenderImpl = new IntermediateMessageSenderImpl(); + MessagingConnector msgConn = Mockito.mock(MessagingConnector.class); + Mockito.when(msgConn.publishMessage(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true); + intermediateMessageSenderImpl.init(msgConn); ctx = new SvcLogicContext(); ctx.setAttribute("input.common-header.request-id", "REQUEST-ID"); params = new HashMap<>(); diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/MockEventSender.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/MockEventSender.java new file mode 100644 index 000000000..2a795e984 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/MockEventSender.java @@ -0,0 +1,52 @@ +package org.onap.appc.dg.common.impl; + +import org.onap.appc.srvcomm.messaging.MessageDestination; +import org.onap.appc.srvcomm.messaging.event.EventMessage; +import org.onap.appc.srvcomm.messaging.event.EventSender; + +public class MockEventSender extends EventSender { + + private EventMessage eventMessage; + private String topic; + private MessageDestination dest; + private boolean success = true; + + @Override + public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) { + eventMessage = msg; + topic = eventTopicName; + dest = destination; + return success; + } + + @Override + public boolean sendEvent(MessageDestination destination, EventMessage msg) { + eventMessage = msg; + topic = null; + dest = destination; + return success; + } + public void reset() { + eventMessage = null; + topic = null; + dest = null; + success = true; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public EventMessage getMessage() { + return eventMessage; + } + + public String getTopic() { + return topic; + } + + public MessageDestination getDestination() { + return dest; + } + +} |