aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeora Barsky <georab@amdocs.com>2017-11-02 00:57:47 -0400
committerGeora Barsky <georab@amdocs.com>2017-11-02 01:01:40 -0400
commit15690ba3b20215498ae05fb77fc9bd113a233f05 (patch)
tree3f8f34ae1f4836464e238c6803ca77f9bcc9f725
parent853f3ea0756f7bf3b685f1decb0101878fdebe1d (diff)
Sniro Emulator - Fix SO CallBack with Resource IDs
Modify SNIRO emulator to pick up serviceResourceId from SO request Change-Id: Ib0bc23cb87ed5e49bb0dde351661527c404199bc JIRA-ID: INT-317 Signed-off-by: Geora Barsky <georab@amdocs.com>
-rw-r--r--test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/WebhookDefinition.java5
-rw-r--r--test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/Webhooks.java45
2 files changed, 41 insertions, 9 deletions
diff --git a/test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/WebhookDefinition.java b/test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/WebhookDefinition.java
index 60592b3f0..304971572 100644
--- a/test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/WebhookDefinition.java
+++ b/test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/WebhookDefinition.java
@@ -74,6 +74,11 @@ public class WebhookDefinition {
return body.isBinary() ? null : body.asString();
}
+ public String getBase64BodyAsString() {
+ return body.asString();
+ }
+
+
@JsonIgnore
public byte[] getBinaryBody() {
return body.asBytes();
diff --git a/test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/Webhooks.java b/test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/Webhooks.java
index e1e172668..78fb735d2 100644
--- a/test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/Webhooks.java
+++ b/test/mocks/sniroemulator/src/main/java/org/onap/integration/test/mocks/sniroemulator/extension/Webhooks.java
@@ -51,6 +51,9 @@ public class Webhooks extends PostServeAction {
private final ScheduledExecutorService scheduler;
private final HttpClient httpClient;
+ private String tunnelResourceId = "NONE";
+ private String brgResourceId = "NONE";
+ private String vgResourceId = "NONE";
public Webhooks() {
scheduler = Executors.newScheduledThreadPool(10);
@@ -73,14 +76,37 @@ public class Webhooks extends PostServeAction {
@Override
public void run() {
JsonNode node = Json.node(serveEvent.getRequest().getBodyAsString());
+ // set callback url from SO request
String callBackUrl = node.get("requestInfo").get("callbackUrl").asText();
notifier.info("!!! Call Back Url : \n" + callBackUrl);
definition.withUrl(callBackUrl);
+
+ // set servicesResourceIds for each resource from SO request placement Demand
+ //System.out.println ("PI: \n" + node.textValue());
+ JsonNode placementDemandList = node.get("placementInfo").get("demandInfo").get("placementDemand");
+ if (placementDemandList !=null && placementDemandList.isArray()){
+ for (int i=0;i<placementDemandList.size();i++){
+ JsonNode resourceInfo = placementDemandList.get(i);
+ String resourceModuleName = resourceInfo.get("resourceModuleName").asText();
+ if (resourceModuleName.toLowerCase().matches("(.*)tunnel(.*)")){
+ tunnelResourceId = resourceInfo.get("serviceResourceId").asText();
+ } else if (resourceModuleName.toLowerCase().matches("(.*)brg(.*)")) {
+ brgResourceId = resourceInfo.get("serviceResourceId").asText();
+ }else {
+ vgResourceId = resourceInfo.get("serviceResourceId").asText();
+ }
+ }
+ }
+
+ String stubbedBodyStr = definition.getBase64BodyAsString();
+ String newBodyStr = stubbedBodyStr.replace("TUNNEL-RESOURCE-ID-REPLACE",tunnelResourceId).replace("VGW-RESOURCE-ID-REPLACE",vgResourceId).replace("BRG-RESOURCE-ID-REPLACE",brgResourceId);
+
+ definition.withBody(newBodyStr);
+ notifier.info("SNIRO Async Callback response:\n" + definition.getBody());
+
HttpUriRequest request = buildRequest(definition);
try {
- // notifier.info("This is a request: \n" + Json.prettyPrint(serveEvent.getRequest().getBodyAsString()));
-
HttpResponse response = httpClient.execute(request);
notifier.info(
String.format("Webhook %s request to %s returned status %s\n\n%s",
@@ -90,13 +116,13 @@ public class Webhooks extends PostServeAction {
EntityUtils.toString(response.getEntity())
)
);
- System.out.println(String.format("Webhook %s request to %s returned status %s\n\n%s",
- definition.getMethod(),
- definition.getUrl(),
- response.getStatusLine(),
- EntityUtils.toString(response.getEntity())
- )
- );
+ //System.out.println(String.format("Webhook %s request to %s returned status %s\n\n%s",
+ // definition.getMethod(),
+ // definition.getUrl(),
+ // response.getStatusLine(),
+ // EntityUtils.toString(response.getEntity())
+ // )
+ //);
} catch (IOException e) {
e.printStackTrace();
throwUnchecked(e);
@@ -114,6 +140,7 @@ public class Webhooks extends PostServeAction {
definition.getUrl().toString()
);
+
for (HttpHeader header: definition.getHeaders().all()) {
request.addHeader(header.key(), header.firstValue());
}