aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-simulators/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-05-14 19:08:02 -0400
committerJim Hahn <jrh3@att.com>2020-05-14 19:48:51 -0400
commit4e50a58565461839df6a1fe65f571a04b2404616 (patch)
tree16f93af216097fa427f1c94d73245726f46829a0 /models-interactions/model-simulators/src/test
parent56564f91a91e496cac03ba7cae5a7d935140a574 (diff)
SO poll should not require request ID
When SO is polled for the result of a previous request, it does not necessarily include the originally returned request ID in the response. This causes the SO actor to generate a "missing request ID in response" exception. Modified the actor to only extract the request ID from the first response and cache it for subsequeent responses. Testing this required the SO simulator to be modified so that it would return an INCOMPLETE on the initial request, forcing the actor to poll until it returns a COMPLETE. Made this a settable flag so that it could be enabled just to test the SO actor without impacting other components (e.g., drools-apps, CSITs). Also fixed a couple of checkstyle issues in the simulators. Issue-ID: POLICY-2568 Change-Id: Ifad8b3c0c2c0b03cb82da693c2cf5ced44ede105 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-simulators/src/test')
-rw-r--r--models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java105
1 files changed, 98 insertions, 7 deletions
diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java
index 723619e1c..c5f997331 100644
--- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java
+++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* simulators
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,9 @@
package org.onap.policy.simulators;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.HashMap;
@@ -60,6 +62,7 @@ public class SoSimulatorTest {
@AfterClass
public static void tearDownSimulator() {
HttpServletServerFactoryInstance.getServerFactory().destroy();
+ SoSimulatorJaxRs.setYieldIncomplete(false);
}
/**
@@ -135,25 +138,113 @@ public class SoSimulatorTest {
@Test
public void testPost() {
- final String request = Serialization.gsonPretty.toJson(this.createTestRequest());
- final Pair<Integer, String> httpDetails = new RestManager().post(
+ SoSimulatorJaxRs.setYieldIncomplete(false);
+ String request = Serialization.gsonPretty.toJson(this.createTestRequest());
+ Pair<Integer, String> httpDetails = new RestManager().post(
"http://localhost:6667/serviceInstantiation/v7/serviceInstances/12345/vnfs/12345/vfModules/scaleOut",
"username",
"password", new HashMap<>(), "application/json", request);
assertNotNull(httpDetails);
- final SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
+ SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
assertNotNull(response);
+ assertNotNull(response.getRequestReferences());
+ assertNotNull(response.getRequestReferences().getRequestId());
+ assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+
+ /*
+ * Repeat, but set the flag indicating that the request should yield incomplete.
+ */
+ SoSimulatorJaxRs.setYieldIncomplete(true);
+
+ request = Serialization.gsonPretty.toJson(this.createTestRequest());
+ httpDetails = new RestManager().post(
+ "http://localhost:6667/serviceInstantiation/v7/serviceInstances/12345/vnfs/12345/vfModules/scaleOut",
+ "username",
+ "password", new HashMap<>(), "application/json", request);
+ assertNotNull(httpDetails);
+ response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
+ assertNotNull(response);
+ assertNotNull(response.getRequestReferences());
+ assertNotNull(response.getRequestReferences().getRequestId());
+ assertEquals("INCOMPLETE", response.getRequest().getRequestStatus().getRequestState());
+
+ // now poll for the response
+ String reqid = response.getRequestReferences().getRequestId();
+ httpDetails = new RestManager().get(
+ "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+ "username",
+ "password", new HashMap<>());
+ assertNotNull(httpDetails);
+ response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
+ assertNotNull(response);
+ assertNull(response.getRequest());
+
+ // poll again
+ httpDetails = new RestManager().get(
+ "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+ "username",
+ "password", new HashMap<>());
+ assertNotNull(httpDetails);
+ response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
+ assertNotNull(response);
+ assertNotNull(response.getRequest());
+ assertNotNull(response.getRequest().getRequestStatus());
+ assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
}
@Test
public void testDelete() {
- final String request = Serialization.gsonPretty.toJson(this.createTestRequest());
- final Pair<Integer, String> httpDetails = new RestManager().delete(
+ SoSimulatorJaxRs.setYieldIncomplete(false);
+ String request = Serialization.gsonPretty.toJson(this.createTestRequest());
+ Pair<Integer, String> httpDetails = new RestManager().delete(
"http://localhost:6667/serviceInstances/v7/12345/vnfs/12345/vfModules/12345",
"username",
"password", new HashMap<>(), "application/json", request);
assertNotNull(httpDetails);
- final SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
+ SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
+ assertNotNull(response);
+ assertNotNull(response.getRequestReferences());
+ assertNotNull(response.getRequestReferences().getRequestId());
+ assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+
+ /*
+ * Repeat, but set the flag indicating that the request should yield incomplete.
+ */
+ SoSimulatorJaxRs.setYieldIncomplete(true);
+
+ request = Serialization.gsonPretty.toJson(this.createTestRequest());
+ httpDetails = new RestManager().delete(
+ "http://localhost:6667/serviceInstances/v7/12345/vnfs/12345/vfModules/12345",
+ "username",
+ "password", new HashMap<>(), "application/json", request);
+ assertNotNull(httpDetails);
+ response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
+ assertNotNull(response);
+ assertNotNull(response.getRequestReferences());
+ assertNotNull(response.getRequestReferences().getRequestId());
+ assertEquals("INCOMPLETE", response.getRequest().getRequestStatus().getRequestState());
+
+ // now poll for the response
+ String reqid = response.getRequestReferences().getRequestId();
+ httpDetails = new RestManager().get(
+ "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+ "username",
+ "password", new HashMap<>());
+ assertNotNull(httpDetails);
+ response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
+ assertNotNull(response);
+ assertNull(response.getRequest());
+
+ // poll again
+ httpDetails = new RestManager().get(
+ "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+ "username",
+ "password", new HashMap<>());
+ assertNotNull(httpDetails);
+ response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
assertNotNull(response);
+ assertNotNull(response.getRequest());
+ assertNotNull(response.getRequest().getRequestStatus());
+ assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
}
}