summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-request-handler
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dispatcher/appc-request-handler')
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/pom.xml14
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/messageadapter/impl/MessageAdapterImpl.java67
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/messageadapter/impl/MessageAdapterImplTest.java84
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/RequestHandlerTest.java14
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/LocalRequestHanlderTestHelper.java13
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-features/onap-appc-request-handler/pom.xml4
6 files changed, 40 insertions, 156 deletions
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/pom.xml b/appc-dispatcher/appc-request-handler/appc-request-handler-core/pom.xml
index e61bf1dd5..5bdf34e74 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/pom.xml
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/pom.xml
@@ -49,19 +49,7 @@
</dependency>
<dependency>
<groupId>org.onap.appc</groupId>
- <artifactId>appc-dmaap-adapter-bundle</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.appc</groupId>
- <artifactId>appc-message-adapter-api</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.appc</groupId>
- <artifactId>appc-message-adapter-factory</artifactId>
+ <artifactId>appc-service-communicator-bundle</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/messageadapter/impl/MessageAdapterImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/messageadapter/impl/MessageAdapterImpl.java
index 8c518fec4..65f51552a 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/messageadapter/impl/MessageAdapterImpl.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/messageadapter/impl/MessageAdapterImpl.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
* ================================================================================
@@ -25,12 +25,6 @@
package org.onap.appc.messageadapter.impl;
-
-import org.onap.appc.adapter.factory.MessageService;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
-import org.onap.appc.configuration.Configuration;
-import org.onap.appc.configuration.ConfigurationFactory;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -39,23 +33,12 @@ import org.onap.appc.domainmodel.lcm.ResponseContext;
import org.onap.appc.domainmodel.lcm.VNFOperation;
import org.onap.appc.messageadapter.MessageAdapter;
import org.onap.appc.requesthandler.conv.Converter;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-
-import java.util.HashSet;
-import java.util.Properties;
+import org.onap.appc.srvcomm.messaging.MessagingConnector;
public class MessageAdapterImpl implements MessageAdapter{
- private MessageService messageService;
- private Producer producer;
+ private MessagingConnector messageService;
private String partition ;
- private Configuration configuration;
- private HashSet<String> pool;
- private String writeTopic;
- private String apiKey;
- private String apiSecret;
private static final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapterImpl.class);
@@ -65,44 +48,12 @@ public class MessageAdapterImpl implements MessageAdapter{
@Override
public void init(){
logger.debug("MessageAdapterImpl - init");
- this.producer = getProducer();
- }
-
- private Producer getProducer() {
- configuration = ConfigurationFactory.getConfiguration();
- Properties properties = configuration.getProperties();
- updateProperties(properties);
-
- BundleContext ctx = FrameworkUtil.getBundle(MessageAdapterImpl.class).getBundleContext();
- if (ctx != null) {
- ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
- if (svcRef != null) {
- producer = ((MessageAdapterFactory) ctx.getService(svcRef)).createProducer(pool, writeTopic, apiKey, apiSecret);
- }
- }
- return producer;
+ this.messageService = new MessagingConnector();
}
-
-
- private void updateProperties(Properties props) {
- if (logger.isTraceEnabled()) {
- logger.trace("Entering to updateProperties with Properties = " + ObjectUtils.toString(props));
- }
- pool = new HashSet<>();
- if (props != null) {
- // readTopic = props.getProperty("dmaap.topic.read");
- writeTopic = props.getProperty("appc.LCM.topic.write");
- apiKey = props.getProperty("appc.LCM.client.key");
- apiSecret = props.getProperty("appc.LCM.client.secret");
- messageService = MessageService.parse(props.getProperty("message.service.type"));
- // READ_TIMEOUT = Integer.valueOf(props.getProperty("dmaap.topic.read.timeout", String.valueOf(READ_TIMEOUT)));
- String hostnames = props.getProperty("appc.LCM.poolMembers");
- if (hostnames != null && !hostnames.isEmpty()) {
- for (String name : hostnames.split(",")) {
- pool.add(name);
- }
- }
- }
+
+ public void init(MessagingConnector connector) {
+ logger.debug("MessageAdapterImpl - init");
+ this.messageService = connector;
}
/**
@@ -125,7 +76,7 @@ public class MessageAdapterImpl implements MessageAdapter{
logger.debug("DMaaP Response = " + jsonMessage);
}
logger.debug("Before Invoking producer.post(): jsonMessage is::" + jsonMessage);
- success = producer.post(this.partition, jsonMessage);
+ success = messageService.publishMessage("appc.LCM", this.partition, jsonMessage);
logger.debug("After Invoking producer.post()");
} catch (JsonProcessingException e1) {
logger.error("Error generating Json from DMaaP message " + e1.getMessage());
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/messageadapter/impl/MessageAdapterImplTest.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/messageadapter/impl/MessageAdapterImplTest.java
index d5c3534b3..81c00269a 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/messageadapter/impl/MessageAdapterImplTest.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/messageadapter/impl/MessageAdapterImplTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2019 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
@@ -21,81 +23,47 @@
package org.onap.appc.messageadapter.impl;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+
+import javax.ws.rs.core.Response.Status;
+
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.mockito.internal.util.reflection.Whitebox;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
-import org.onap.appc.configuration.Configuration;
-import org.onap.appc.configuration.ConfigurationFactory;
-import org.onap.appc.requesthandler.conv.Converter;
-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;
+import org.onap.appc.domainmodel.lcm.CommonHeader;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.domainmodel.lcm.VNFOperation;
+import org.onap.appc.srvcomm.messaging.MessagingConnector;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.att.eelf.configuration.EELFLogger.Level;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({FrameworkUtil.class, Converter.class})
public class MessageAdapterImplTest {
- private Configuration mockConfig = ConfigurationFactory.getConfiguration();
- 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 Producer producer = Mockito.mock(Producer.class);
+ private final MessagingConnector connector = Mockito.mock(MessagingConnector.class);
private static final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapterImpl.class);
- private MessageAdapterImpl impl;
-
+ private final MessageAdapterImpl impl = new MessageAdapterImpl();
+
@Before
- public void setUp() throws Exception {
- logger.setLevel(Level.TRACE);
- impl = PowerMockito.spy(new MessageAdapterImpl());
- //originalLogger = (EELFLogger) Whitebox.getInternalState(MessageAdapterImpl.class, "logger");
- Whitebox.setInternalState(impl, "configuration", mockConfig);
- PowerMockito.mockStatic(FrameworkUtil.class);
- PowerMockito.when(FrameworkUtil.getBundle(MessageAdapterImpl.class)).thenReturn(bundleService);
- PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
- PowerMockito.when(bundleContext.getServiceReference(MessageAdapterFactory.class.getName())).thenReturn(sref);
- PowerMockito.when(bundleContext.getService(sref)).thenReturn(producer);
- PowerMockito.mockStatic(Converter.class);
- PowerMockito.when(Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(
- Mockito.any(), Mockito.any(), Mockito.any())).thenReturn("{}");
+ public void setUp() {
+ impl.init(connector);
}
@Test
public void testSuccess() throws JsonProcessingException {
- PowerMockito.when(Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(
- Mockito.any(), Mockito.any(), Mockito.any())).thenReturn("{}");
- Mockito.when(producer.post(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
- Whitebox.setInternalState(impl, "producer", producer);
- Whitebox.setInternalState(impl, "partition", "PARTITION");
- assertTrue(impl.post(null, null, null));
- }
- @Test
- public void testJsonException() throws JsonProcessingException {
- PowerMockito.when(Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(
- Mockito.any(), Mockito.any(), Mockito.any())).thenThrow(new JsonProcessingException("TEST") {});
- Whitebox.setInternalState(impl, "partition", "PARTITION");
- assertFalse(impl.post(null, null, null));
+ ResponseContext context = new ResponseContext();
+ context.setPayload("payload");
+ org.onap.appc.domainmodel.lcm.Status status = new org.onap.appc.domainmodel.lcm.Status();
+ status.setCode(200);
+ status.setMessage("success");
+ context.setStatus(status);
+ CommonHeader commonHeader = new CommonHeader();
+ commonHeader.setRequestId("test123");
+ commonHeader.setSubRequestId("test456");
+ context.setCommonHeader(commonHeader);
+ Mockito.when(connector.publishMessage(Mockito.any(), Mockito.any(),Mockito.any())).thenReturn(true);
+ assertTrue(impl.post(VNFOperation.Start, "test", context));
}
- @Test
- public void testException() throws JsonProcessingException {
- PowerMockito.when(Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(
- Mockito.any(), Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
- Whitebox.setInternalState(impl, "partition", "PARTITION");
- assertFalse(impl.post(null, null, null));
- }
}
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/RequestHandlerTest.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/RequestHandlerTest.java
index 2c410320f..89bb13f7c 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/RequestHandlerTest.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/RequestHandlerTest.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
* =============================================================================
@@ -31,8 +31,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
-import org.onap.appc.adapter.factory.DmaapMessageAdapterFactoryImpl;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
@@ -97,12 +95,6 @@ public class RequestHandlerTest {
private LockManager lockManager;
private Configuration configuration;
- 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 MessageAdapterFactory factory = new DmaapMessageAdapterFactoryImpl();
-
-
@Before
public void init() throws Exception {
configuration = ConfigurationFactory.getConfiguration();
@@ -112,10 +104,6 @@ public class RequestHandlerTest {
configuration.setProperty("appc.LCM.client.secret" , "TEST");
PowerMockito.mockStatic(FrameworkUtil.class);
- PowerMockito.when(FrameworkUtil.getBundle(MessageAdapterImpl.class)).thenReturn(bundleService);
- PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
- PowerMockito.when(bundleContext.getServiceReference(MessageAdapterFactory.class.getName())).thenReturn(sref);
- PowerMockito.when(bundleContext.getService(sref)).thenReturn(factory);
requestHandler = new RequestHandlerImpl();
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/LocalRequestHanlderTestHelper.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/LocalRequestHanlderTestHelper.java
index a6bbe571a..64f9e229b 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/LocalRequestHanlderTestHelper.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/LocalRequestHanlderTestHelper.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
* =============================================================================
@@ -24,8 +24,6 @@
package org.onap.appc.requesthandler.impl;
import org.mockito.Mockito;
-import org.onap.appc.adapter.message.MessageAdapterFactory;
-import org.onap.appc.adapter.message.Producer;
import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
import org.onap.appc.domainmodel.lcm.ActionLevel;
import org.onap.appc.domainmodel.lcm.CommonHeader;
@@ -116,14 +114,5 @@ public interface LocalRequestHanlderTestHelper {
BundleContext myBundleContext = mock(BundleContext.class);
Mockito.when(myBundle.getBundleContext()).thenReturn(myBundleContext);
-
- ServiceReference svcRef = mock(ServiceReference.class);
- Mockito.when(myBundleContext.getServiceReference(MessageAdapterFactory.class.getName())).thenReturn(svcRef);
-
- Producer producer = mock(Producer.class);
- MessageAdapterFactory factory = mock(MessageAdapterFactory.class);
- Mockito.when(myBundleContext.getService(svcRef)).thenReturn(factory);
- Mockito.when(factory.createProducer(anyCollectionOf(String.class), anyString(), anyString(), anyString()))
- .thenReturn(producer);
}
}
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-features/onap-appc-request-handler/pom.xml b/appc-dispatcher/appc-request-handler/appc-request-handler-features/onap-appc-request-handler/pom.xml
index 23334889c..0663bd61c 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-features/onap-appc-request-handler/pom.xml
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-features/onap-appc-request-handler/pom.xml
@@ -3,7 +3,7 @@
============LICENSE_START=======================================================
ONAP : APPC
================================================================================
-Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+Copyright (C) 2018-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.
@@ -67,7 +67,7 @@ limitations under the License.
</dependency>
<dependency>
<groupId>org.onap.appc</groupId>
- <artifactId>appc-message-adapter-api</artifactId>
+ <artifactId>appc-service-communicator-bundle</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>