summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main
diff options
context:
space:
mode:
authorwasala <przemyslaw.wasala@nokia.com>2018-05-17 11:10:24 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-05-17 13:32:06 +0200
commitf24307ddd8fd1d8235bcf4e790cdd15bbf9db514 (patch)
treef83edd9061246db6d7a075453de3c71cbf725734 /prh-app-server/src/main
parent797e824f18e784b8ded9a00d2ca7f420a53e6fff (diff)
Added tests for AAIConsumerTask
Change-Id: I958844fb2f0ce0ae19762ff7a9f98e19303191f3 Issue-ID: DCAEGEN2-396 Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-app-server/src/main')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java6
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java39
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java4
3 files changed, 35 insertions, 14 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java
index 5a3afd86..b4b66036 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java
@@ -22,9 +22,9 @@ package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
-public abstract class AAIConsumerTask<T> extends Task {
+public abstract class AAIConsumerTask<T, U, V> extends Task {
- protected abstract void consume() throws AAINotFoundException;
+ protected abstract V consume(U message) throws AAINotFoundException;
- protected abstract T resolveConfiguration();
+ protected abstract T resolveClient();
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java
index cbe3d9aa..31af9c80 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java
@@ -20,24 +20,25 @@
package org.onap.dcaegen2.services.prh.tasks;
+import java.io.IOException;
import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.AAIConsumerClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.Optional;
-
@Component
-public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration> {
+public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIConsumerClient, ConsumerDmaapModel, Object> {
private static final Logger logger = LoggerFactory.getLogger(AAIConsumerTaskImpl.class);
private final Config prhAppConfig;
- private Optional<String> response;
+ private AAIConsumerClient aaiConsumerClient;
@Autowired
public AAIConsumerTaskImpl(AppConfig prhAppConfig) {
@@ -45,13 +46,24 @@ public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration>
}
@Override
- protected void consume() throws AAINotFoundException {
+ protected Object consume(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ logger.trace("Method called with arg {}", consumerDmaapModel);
+ try {
+ return aaiConsumerClient.getHttpResponse(consumerDmaapModel);
+ } catch (IOException e) {
+ logger.warn("Get request not successful", e);
+ throw new AAINotFoundException("Get request not successful");
+ }
}
@Override
public Object execute(Object object) throws AAINotFoundException {
- consume();
- return null;
+ setAAIClientConfig();
+ logger.trace("Method called with arg {}", object);
+ if (object instanceof ConsumerDmaapModel) {
+ return consume((ConsumerDmaapModel) object);
+ }
+ throw new AAINotFoundException("Incorrect object type");
}
@Override
@@ -59,8 +71,17 @@ public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration>
logger.trace("initConfigs for AAIConsumerTaskImpl not needed/supported");
}
- @Override
- protected AAIClientConfiguration resolveConfiguration() {
+
+ protected void setAAIClientConfig() {
+ aaiConsumerClient = resolveClient();
+ }
+
+ AAIClientConfiguration resolveConfiguration() {
return prhAppConfig.getAAIClientConfiguration();
}
+
+ @Override
+ protected AAIConsumerClient resolveClient() {
+ return new AAIConsumerClient(resolveConfiguration());
+ }
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java
index 24de3124..5d022f85 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java
@@ -79,11 +79,11 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIProducerClient, Cons
logger.trace("initConfigs for AAIProducerTaskImpl not needed/supported");
}
- protected void setAAIClientConfig() {
+ void setAAIClientConfig() {
aaiProducerClient = resolveClient();
}
- protected AAIClientConfiguration resolveConfiguration() {
+ AAIClientConfiguration resolveConfiguration() {
return prhAppConfig.getAAIClientConfiguration();
}