summaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors/actor.so/src/test/java/org
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-08-24 14:00:30 -0400
committerJim Hahn <jrh3@att.com>2018-08-24 14:36:49 -0400
commit57ac9eac8ac0f8236ddb52e5226f475368d4de33 (patch)
tree25bd93e9556becc78742c5bfeeb943de99f20d32 /controlloop/common/actors/actor.so/src/test/java/org
parent51e88a932274a3ff8a93996332bb4f1d55d4a773 (diff)
use new vf-walk code in SO request
Methods were added to AaiNqResponseWrapper to extract VF modules and generate the new VF module name. This step modifies the SO code to use those methods. It was also determined that the SO code needs the VF module container object, not just the VF module, itself. As a result, AaiNqResponseWrapper was modified to return a list of the containers instead of a list of the VF modules. Also modified the AAI simulator to return two VF modules in the response to the vserver named query. As part of that, a method was added to the simulator so that JSON responses can be read from files rather than having to convert them to Java Strings. Modified simulator to work even if vnf-id is null. Change-Id: I68fdf07ea80ee0daf9e16403e35b11710315a8a8 Issue-ID: POLICY-1037 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/actors/actor.so/src/test/java/org')
-rw-r--r--controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java55
1 files changed, 23 insertions, 32 deletions
diff --git a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java
index d75d859d8..25bbda0f4 100644
--- a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java
+++ b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java
@@ -26,38 +26,26 @@ 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;
-import java.util.Map;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.UUID;
-import org.junit.AfterClass;
+import org.apache.commons.io.IOUtils;
import org.junit.Test;
-import org.onap.policy.aai.AaiNqInstanceFilters;
-import org.onap.policy.aai.AaiNqRequest;
import org.onap.policy.aai.AaiNqResponse;
import org.onap.policy.aai.AaiNqResponseWrapper;
-import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.simulators.AaiSimulatorJaxRs;
import org.onap.policy.so.SORequest;
import org.onap.policy.so.util.Serialization;
public class TestSOActorServiceProvider {
- /**
- * Tear down after test class.
- */
- @AfterClass
- public static void tearDownSimulator() {
- HttpServletServer.factory.destroy();
- }
-
@Test
- public void testConstructRequest() {
+ public void testConstructRequest() throws Exception {
VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
final ControlLoopOperation operation = new ControlLoopOperation();
- final AaiNqResponseWrapper aaiNqResp = getNqVserverFromAai(onset);
+ final AaiNqResponseWrapper aaiNqResp = loadAaiResponse(onset, "aai/AaiNqResponse-Full.json");
final UUID requestId = UUID.randomUUID();
onset.setRequestId(requestId);
@@ -74,8 +62,20 @@ public class TestSOActorServiceProvider {
SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
assertNotNull(request);
+ assertEquals("my_module_3", request.getRequestDetails().getRequestInfo().getInstanceName());
assertEquals("policy", request.getRequestDetails().getRequestInfo().getRequestorId());
assertEquals("RegionOne", request.getRequestDetails().getCloudConfiguration().getLcpCloudRegionId());
+
+ // null response
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, null));
+
+ // response has no base VF module
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy,
+ loadAaiResponse(onset, "aai/AaiNqResponse-NoBase.json")));
+
+ // response has no non-base VF modules (other than the "dummy")
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy,
+ loadAaiResponse(onset, "aai/AaiNqResponse-NoNonBase.json")));
}
@Test
@@ -98,25 +98,16 @@ public class TestSOActorServiceProvider {
}
/**
- * Queries the AAI simulator directly (i.e., bypassing the REST API) to get the
- * vserver named-query response.
+ * Reads an AAI vserver named-query response from a file.
*
* @param onset the ONSET event
+ * @param fileName name of the file containing the JSON response
* @return output from the AAI vserver named-query
+ * @throws IOException if the file cannot be read
*/
- private AaiNqResponseWrapper getNqVserverFromAai(VirtualControlLoopEvent onset) {
- AaiNqRequest aaiNqRequest = new AaiNqRequest();
- final AaiNqInstanceFilters aaiNqInstanceFilter = new AaiNqInstanceFilters();
-
- Map<String, Map<String, String>> aaiNqInstanceFilterMap = new HashMap<>();
- Map<String, String> aaiNqInstanceFilterMapItem = new HashMap<>();
- aaiNqInstanceFilterMapItem.put("vserver-name", "my-vserver-name");
- aaiNqInstanceFilterMap.put("vserver", aaiNqInstanceFilterMapItem);
- aaiNqInstanceFilter.getInstanceFilter().add(aaiNqInstanceFilterMap);
- aaiNqRequest.setInstanceFilters(aaiNqInstanceFilter);
-
- String req = Serialization.gsonPretty.toJson(aaiNqRequest);
- String resp = new AaiSimulatorJaxRs().aaiPostQuery(req);
+ private AaiNqResponseWrapper loadAaiResponse(VirtualControlLoopEvent onset, String fileName)
+ throws IOException {
+ String resp = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8);
AaiNqResponse aaiNqResponse = Serialization.gsonPretty.fromJson(resp, AaiNqResponse.class);
return new AaiNqResponseWrapper(onset.getRequestId(), aaiNqResponse);