summaryrefslogtreecommitdiffstats
path: root/appc-dg
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dg')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java28
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml57
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java53
3 files changed, 76 insertions, 62 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java
index 0f99f8314..dd667c270 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java
@@ -33,9 +33,6 @@ import org.openecomp.appc.adapter.message.event.EventStatus;
import org.openecomp.appc.dg.common.DCAEReporterPlugin;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
import java.util.Map;
@@ -44,9 +41,16 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
private EventSender eventSender;
public DCAEReporterPluginImpl() {
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
- ServiceReference sref = bctx.getServiceReference(EventSender.class);
- eventSender = (EventSender) bctx.getService(sref);
+ // do nothing
+ }
+
+ /**
+ * Injected by blueprint
+ *
+ * @param eventSender to be set
+ */
+ public void setEventSender(EventSender eventSender) {
+ this.eventSender = eventSender;
}
@Override
@@ -62,7 +66,9 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
apiVersion = ctx.getAttribute("input.common-header.api-ver");
eventId = ctx.getAttribute("input.common-header.request-id");
- EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(errorCode, errorDescription));
+ EventMessage eventMessage = new EventMessage(new EventHeader(
+ (new java.util.Date()).toString(), apiVersion, eventId),
+ new EventStatus(errorCode, errorDescription));
String eventWriteTopic = params.get("event-topic-name");
if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){
eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic);
@@ -102,7 +108,9 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
if (null == successDescription) {
successDescription = "Success";
}
- EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(successReportCode, successDescription));
+ EventMessage eventMessage = new EventMessage(new EventHeader(
+ (new java.util.Date()).toString(), apiVersion, eventId),
+ new EventStatus(successReportCode, successDescription));
String eventWriteTopic = params.get("event-topic-name");
if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){
eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic);
@@ -120,7 +128,9 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
apiVersion = ctx.getAttribute("input.common-header.api-ver");
eventId = ctx.getAttribute("input.common-header.request-id");
- EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(errorCode, errorDescription));
+ EventMessage eventMessage = new EventMessage(new EventHeader(
+ (new java.util.Date()).toString(), apiVersion, eventId),
+ new EventStatus(errorCode, errorDescription));
String eventWriteTopic = params.get("event-topic-name");
if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){
eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic);
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 9c282f0ee..9014d9f9d 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -27,41 +27,54 @@
Starter Blueprint Camel Definition appc-aai-adapter-blueprint
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
- <bean id="JsonDgUtilBean" class="org.openecomp.appc.dg.common.impl.JsonDgUtilImpl"/>
+ <bean id="JsonDgUtilBean" class="org.openecomp.appc.dg.common.impl.JsonDgUtilImpl"/>
<service id="JsonDgUtil" interface="org.openecomp.appc.dg.common.JsonDgUtil" ref="JsonDgUtilBean"/>
- <!-- <reference id="eventSenderRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.adapter.message.EventSender" /> -->
+ <reference id="eventSenderReference" availability="mandatory" activation="eager"
+ interface="org.openecomp.appc.adapter.message.EventSender"/>
- <bean id="DCAEReporterPluginBean" class="org.openecomp.appc.dg.common.impl.DCAEReporterPluginImpl" scope="singleton"/>
- <service id="DCAEReporterPlugin" interface="org.openecomp.appc.dg.common.DCAEReporterPlugin" ref="DCAEReporterPluginBean"/>
+ <bean id="DCAEReporterPluginBean" class="org.openecomp.appc.dg.common.impl.DCAEReporterPluginImpl"
+ scope="singleton">
+ <property name="eventSender" ref="eventSenderReference"/>
+ </bean>
- <bean id="OutputMessagePluginBean" class="org.openecomp.appc.dg.common.impl.OutputMessagePluginImpl" scope="singleton"/>
- <service id="OutputMessagePlugin" interface="org.openecomp.appc.dg.common.OutputMessagePlugin" ref="OutputMessagePluginBean"/>
+ <service id="DCAEReporterPlugin" interface="org.openecomp.appc.dg.common.DCAEReporterPlugin"
+ ref="DCAEReporterPluginBean"/>
- <bean id="legacyUtilBean" class="org.openecomp.appc.dg.common.impl.LegacyUtilImpl" scope="singleton"/>
- <service id="legacyUtil" interface="org.openecomp.appc.dg.common.LegacyUtil" ref="legacyUtilBean"/>
+ <bean id="OutputMessagePluginBean" class="org.openecomp.appc.dg.common.impl.OutputMessagePluginImpl"
+ scope="singleton"/>
+ <service id="OutputMessagePlugin" interface="org.openecomp.appc.dg.common.OutputMessagePlugin"
+ ref="OutputMessagePluginBean"/>
- <bean id="DgResolverPluginBean" class="org.openecomp.appc.dg.common.impl.DgResolverPluginImpl" scope="singleton">
- </bean>
+ <bean id="legacyUtilBean" class="org.openecomp.appc.dg.common.impl.LegacyUtilImpl" scope="singleton"/>
+ <service id="legacyUtil" interface="org.openecomp.appc.dg.common.LegacyUtil" ref="legacyUtilBean"/>
- <service id="DgResolverPlugin" interface="org.openecomp.appc.dg.common.DgResolverPlugin" ref="DgResolverPluginBean"/>
+ <bean id="DgResolverPluginBean" class="org.openecomp.appc.dg.common.impl.DgResolverPluginImpl" scope="singleton"/>
- <bean id="vnfExecutionFlowBean" class="org.openecomp.appc.dg.common.impl.VnfExecutionFlowImpl" scope="singleton"/>
- <service id="vnfExecutionFlowService" interface="org.openecomp.appc.dg.common.VnfExecutionFlow" ref="vnfExecutionFlowBean"/>
+ <service id="DgResolverPlugin" interface="org.openecomp.appc.dg.common.DgResolverPlugin"
+ ref="DgResolverPluginBean"/>
- <bean id="VNFCDgResolverPluginBean" class="org.openecomp.appc.dg.common.impl.VNFCDgResolverPluginImpl" scope="singleton">
- </bean>
+ <bean id="vnfExecutionFlowBean" class="org.openecomp.appc.dg.common.impl.VnfExecutionFlowImpl" scope="singleton"/>
+ <service id="vnfExecutionFlowService" interface="org.openecomp.appc.dg.common.VnfExecutionFlow"
+ ref="vnfExecutionFlowBean"/>
- <service id="VNFCDgResolverPlugin" interface="org.openecomp.appc.dg.common.VNFCDgResolverPlugin" ref="VNFCDgResolverPluginBean"/>
+ <bean id="VNFCDgResolverPluginBean" class="org.openecomp.appc.dg.common.impl.VNFCDgResolverPluginImpl"
+ scope="singleton"/>
- <bean id="vnfConfiguratorBean" class="org.openecomp.appc.dg.common.impl.VNFConfiguratorImpl" scope="singleton"/>
+ <service id="VNFCDgResolverPlugin" interface="org.openecomp.appc.dg.common.VNFCDgResolverPlugin"
+ ref="VNFCDgResolverPluginBean"/>
- <service id="vnfConfigurationService" interface="org.openecomp.appc.dg.common.VNFConfigurator" ref="vnfConfiguratorBean"/>
+ <bean id="vnfConfiguratorBean" class="org.openecomp.appc.dg.common.impl.VNFConfiguratorImpl" scope="singleton"/>
- <bean id="interimMessageSender" class="org.openecomp.appc.dg.common.impl.IntermediateMessageSenderImpl" init-method="init" scope="singleton"/>
- <service id="interimMessageSenderService" ref="interimMessageSender" interface="org.openecomp.appc.dg.common.IntermediateMessageSender"/>
+ <service id="vnfConfigurationService" interface="org.openecomp.appc.dg.common.VNFConfigurator"
+ ref="vnfConfiguratorBean"/>
+
+ <bean id="interimMessageSender" class="org.openecomp.appc.dg.common.impl.IntermediateMessageSenderImpl"
+ init-method="init" scope="singleton"/>
+ <service id="interimMessageSenderService" ref="interimMessageSender"
+ interface="org.openecomp.appc.dg.common.IntermediateMessageSender"/>
</blueprint>
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java
index 4534f8521..78a11fb48 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java
@@ -24,13 +24,14 @@
package org.openecomp.appc.dg.common.impl;
-import org.junit.*;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.*;
import org.openecomp.appc.adapter.message.EventSender;
import org.openecomp.appc.adapter.message.MessageDestination;
import org.openecomp.appc.adapter.message.event.EventMessage;
-import org.openecomp.appc.dg.common.impl.DCAEReporterPluginImpl;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.sdnc.sli.SvcLogicContext;
import org.osgi.framework.Bundle;
@@ -50,35 +51,31 @@ public class DCAEReporterPluginImplTest {
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 BundleContext bundleContext = Mockito.mock(BundleContext.class);
+ private final Bundle bundleService = Mockito.mock(Bundle.class);
+ private final ServiceReference sref = Mockito.mock(ServiceReference.class);
+ @InjectMocks
private DCAEReporterPluginImpl dcaeReporterPlugin;
- private EventSenderMock eventSender;
+ @Spy
+ private EventSenderMock eventSender = new EventSenderMock();
private String apiVer = "2.0.0";
private String requestId = "123";
private String error = "test-error";
+ @SuppressWarnings("unchecked")
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
- eventSender = new EventSenderMock();
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);
- dcaeReporterPlugin = new DCAEReporterPluginImpl();
-
}
-
-
@Test
public void testReportErrorDescriptionNullBwcModeFalse() throws Exception {
-
ctx = new SvcLogicContext();
params = new HashMap<>();
params.put("output.status.message", null);
@@ -88,6 +85,17 @@ public class DCAEReporterPluginImplTest {
errorReasonNullAssert();
}
+ @Test
+ public void testReportBwcFalse() throws Exception {
+ ctx = new SvcLogicContext();
+ params = new HashMap<>();
+ ctx.setAttribute("isBwcMode", "false");
+ params.put("output.status.message", error);
+ ctx.setAttribute("input.common-header.api-ver", apiVer);
+ ctx.setAttribute("input.common-header.request-id", requestId);
+
+ positiveAssert();
+ }
private void errorReasonNullAssert() throws APPCException {
dcaeReporterPlugin.report(params, ctx);
@@ -97,10 +105,8 @@ public class DCAEReporterPluginImplTest {
Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId());
Assert.assertEquals("wrong error message", "Unknown", msg.getEventStatus().getReason());
Assert.assertEquals("wrong destination", destination.name(), "DCAE");
-
}
-
private void positiveAssert() throws APPCException {
dcaeReporterPlugin.report(params, ctx);
MessageDestination destination = eventSender.getDestination();
@@ -109,20 +115,5 @@ public class DCAEReporterPluginImplTest {
Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId());
Assert.assertEquals("wrong error message", error, msg.getEventStatus().getReason());
Assert.assertEquals("wrong destination", destination.name(), "DCAE");
-
}
-
-
- @Test
- public void testReportBwcFalse() throws Exception {
- ctx = new SvcLogicContext();
- params = new HashMap<>();
- ctx.setAttribute("isBwcMode", "false");
- params.put("output.status.message", error);
- ctx.setAttribute("input.common-header.api-ver", apiVer);
- ctx.setAttribute("input.common-header.request-id", requestId);
-
- positiveAssert();
-
- }
- }
+}