summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-simulators/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-05-15 09:52:35 -0400
committerJim Hahn <jrh3@att.com>2020-05-15 11:53:17 -0400
commitafe5abed95c6cbfe239066e267d9c10a71f20623 (patch)
tree89325042e014a2685d54d7cce13f26bb4bfde6b1 /models-interactions/model-simulators/src/test
parent4e50a58565461839df6a1fe65f571a04b2404616 (diff)
Cannot parse finishTime in SO responses
The timestamp in SO responses appears to follow RFC-1123/RFC-822 format instead of ISO format. Added a type adapter for SO. In Guilin, we may want to consider combining the two type adapters for LocalDateTime so that either format is accepted. Also modified the SO simulator to return responses that are actual samples from SO. As part of that work, discovered that the legacy SO actor is not able to parse these timestamps either. However, as that code is now deprecated, left it as is. Issue-ID: POLICY-2570 Change-Id: I322318d1007e36eef47bb8867fd8ed01cb60223a 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.java85
1 files changed, 35 insertions, 50 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 c5f997331..d8613c8b7 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
@@ -21,9 +21,9 @@
package org.onap.policy.simulators;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.HashMap;
@@ -42,7 +42,6 @@ import org.onap.policy.so.SoRequest;
import org.onap.policy.so.SoRequestDetails;
import org.onap.policy.so.SoRequestInfo;
import org.onap.policy.so.SoRequestParameters;
-import org.onap.policy.so.SoResponse;
import org.onap.policy.so.util.Serialization;
public class SoSimulatorTest {
@@ -62,7 +61,7 @@ public class SoSimulatorTest {
@AfterClass
public static void tearDownSimulator() {
HttpServletServerFactoryInstance.getServerFactory().destroy();
- SoSimulatorJaxRs.setYieldIncomplete(false);
+ SoSimulatorJaxRs.setRequirePolling(false);
}
/**
@@ -138,23 +137,19 @@ public class SoSimulatorTest {
@Test
public void testPost() {
- SoSimulatorJaxRs.setYieldIncomplete(false);
+ SoSimulatorJaxRs.setRequirePolling(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);
- SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
- assertNotNull(response);
- assertNotNull(response.getRequestReferences());
- assertNotNull(response.getRequestReferences().getRequestId());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ assertThat(httpDetails.second).contains("\"COMPLETE\"").doesNotContain("requestSelfLink");
/*
* Repeat, but set the flag indicating that the request should yield incomplete.
*/
- SoSimulatorJaxRs.setYieldIncomplete(true);
+ SoSimulatorJaxRs.setRequirePolling(true);
request = Serialization.gsonPretty.toJson(this.createTestRequest());
httpDetails = new RestManager().post(
@@ -162,55 +157,41 @@ public class SoSimulatorTest {
"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());
+ assertThat(httpDetails.second).contains("requestSelfLink").doesNotContain("\"COMPLETE\"");
// now poll for the response
- String reqid = response.getRequestReferences().getRequestId();
+ String uri = extractUri(httpDetails.second);
httpDetails = new RestManager().get(
- "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+ "http://localhost:6667/orchestrationRequests/v5/" + uri,
"username",
"password", new HashMap<>());
assertNotNull(httpDetails);
- response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
- assertNotNull(response);
- assertNull(response.getRequest());
+ assertThat(httpDetails.second).contains("\"IN_PROGRESS\"").doesNotContain("requestSelfLink");
// poll again
httpDetails = new RestManager().get(
- "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+ "http://localhost:6667/orchestrationRequests/v5/" + uri,
"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());
+ assertThat(httpDetails.second).contains("\"COMPLETE\"").doesNotContain("requestSelfLink");
}
@Test
public void testDelete() {
- SoSimulatorJaxRs.setYieldIncomplete(false);
+ SoSimulatorJaxRs.setRequirePolling(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);
- SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
- assertNotNull(response);
- assertNotNull(response.getRequestReferences());
- assertNotNull(response.getRequestReferences().getRequestId());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ assertThat(httpDetails.second).contains("\"COMPLETE\"").doesNotContain("requestSelfLink");
/*
* Repeat, but set the flag indicating that the request should yield incomplete.
*/
- SoSimulatorJaxRs.setYieldIncomplete(true);
+ SoSimulatorJaxRs.setRequirePolling(true);
request = Serialization.gsonPretty.toJson(this.createTestRequest());
httpDetails = new RestManager().delete(
@@ -218,33 +199,37 @@ public class SoSimulatorTest {
"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());
+ assertThat(httpDetails.second).contains("requestSelfLink").doesNotContain("\"COMPLETE\"");
// now poll for the response
- String reqid = response.getRequestReferences().getRequestId();
+ String uri = extractUri(httpDetails.second);
httpDetails = new RestManager().get(
- "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+ "http://localhost:6667/orchestrationRequests/v5/" + uri,
"username",
"password", new HashMap<>());
assertNotNull(httpDetails);
- response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class);
- assertNotNull(response);
- assertNull(response.getRequest());
+ assertThat(httpDetails.second).contains("\"IN_PROGRESS\"").doesNotContain("requestSelfLink");
// poll again
httpDetails = new RestManager().get(
- "http://localhost:6667//orchestrationRequests/v5/" + reqid,
+ "http://localhost:6667/orchestrationRequests/v5/" + uri,
"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());
+ assertThat(httpDetails.second).contains("\"COMPLETE\"").doesNotContain("requestSelfLink");
+ }
+
+ private String extractUri(String response) {
+ final String prefix = "\"requestId\": \"";
+
+ int start = response.indexOf(prefix);
+ assertTrue(start >= 0);
+
+ start += prefix.length();
+
+ int end = response.indexOf('"', start);
+ assertTrue(end >= 0);
+
+ return response.substring(start, end);
}
}