summaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors/actor.so
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/actors/actor.so')
-rw-r--r--controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java31
-rw-r--r--controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java52
2 files changed, 65 insertions, 18 deletions
diff --git a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
index 8775e68a6..7c0214bfb 100644
--- a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
+++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
@@ -272,10 +272,10 @@ public class SOActorServiceProvider implements Actor {
request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2);
// Request Parameters
- request.getRequestDetails().setRequestParameters(buildRequestParameters(policy));
+ buildRequestParameters(policy, request.getRequestDetails());
// Configuration Parameters
- request.getRequestDetails().setConfigurationParameters(buildConfigurationParameters(policy));
+ buildConfigurationParameters(policy, request.getRequestDetails());
// Save the instance IDs for the VNF and service to static fields
// vfModuleId is not required for the create vf-module
preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance()
@@ -400,39 +400,44 @@ public class SOActorServiceProvider implements Actor {
* Builds the request parameters from the policy payload.
*
* @param policy the policy
- * @return the request parameters, or {@code null} if the payload is {@code null}
+ * @param request request into which to stick the request parameters
*/
- private SORequestParameters buildRequestParameters(Policy policy) {
+ private void buildRequestParameters(Policy policy, SORequestDetails request) {
+ // assume null until proven otherwise
+ request.setRequestParameters(null);
+
if (policy.getPayload() == null) {
- return null;
+ return;
}
String json = policy.getPayload().get(REQ_PARAM_NM);
if (json == null) {
- return null;
+ return;
}
- return Serialization.gsonPretty.fromJson(json, SORequestParameters.class);
+ request.setRequestParameters(Serialization.gsonPretty.fromJson(json, SORequestParameters.class));
}
/**
* Builds the configuration parameters from the policy payload.
*
* @param policy the policy
- * @return the configuration parameters, or {@code null} if the payload is
- * {@code null}
+ * @param request request into which to stick the configuration parameters
*/
- private List<Map<String, String>> buildConfigurationParameters(Policy policy) {
+ private void buildConfigurationParameters(Policy policy, SORequestDetails request) {
+ // assume null until proven otherwise
+ request.setConfigurationParameters(null);
+
if (policy.getPayload() == null) {
- return null;
+ return;
}
String json = policy.getPayload().get(CONFIG_PARAM_NM);
if (json == null) {
- return null;
+ return;
}
- return Serialization.gsonPretty.fromJson(json, CONFIG_TYPE);
+ request.setConfigurationParameters(Serialization.gsonPretty.fromJson(json, CONFIG_TYPE));
}
/**
diff --git a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
index 6de451d0c..9c1d87888 100644
--- a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
+++ b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
@@ -47,6 +47,9 @@ import org.onap.policy.so.util.Serialization;
public class SoActorServiceProviderTest {
+ private static final String VF_MODULE_CREATE = "VF Module Create";
+ private static final String VF_MODULE_DELETE = "VF Module Delete";
+
@Test
public void testConstructRequest() throws Exception {
VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
@@ -59,12 +62,13 @@ public class SoActorServiceProviderTest {
Policy policy = new Policy();
policy.setActor("Dorothy");
policy.setRecipe("GoToOz");
+
assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
policy.setActor("SO");
assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
- policy.setRecipe("VF Module Create");
+ policy.setRecipe(VF_MODULE_CREATE);
// empty policy payload
SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
@@ -82,6 +86,22 @@ public class SoActorServiceProviderTest {
assertEquals("avalue", request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey"));
assertEquals(1, request.getRequestDetails().getConfigurationParameters().size());
assertEquals("cvalue", request.getRequestDetails().getConfigurationParameters().get(0).get("ckey"));
+
+ // payload with config, but no request params
+ policy.setPayload(makePayload());
+ policy.getPayload().remove(SOActorServiceProvider.REQ_PARAM_NM);
+ request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
+ assertNotNull(request);
+ assertNull(request.getRequestDetails().getRequestParameters());
+ assertNotNull(request.getRequestDetails().getConfigurationParameters());
+
+ // payload with request, but no config params
+ policy.setPayload(makePayload());
+ policy.getPayload().remove(SOActorServiceProvider.CONFIG_PARAM_NM);
+ request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
+ assertNotNull(request);
+ assertNotNull(request.getRequestDetails().getRequestParameters());
+ assertNull(request.getRequestDetails().getConfigurationParameters());
// null response
assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, null));
@@ -94,10 +114,30 @@ public class SoActorServiceProviderTest {
assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy,
loadAaiResponse(onset, "aai/AaiNqResponse-NoNonBase.json")));
- policy.setRecipe("VF Module Delete");
+ policy.setRecipe(VF_MODULE_DELETE);
SORequest deleteRequest = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
assertNotNull(deleteRequest);
assertEquals(SoOperationType.DELETE_VF_MODULE, deleteRequest.getOperationType());
+
+ /*
+ * NOTE: The remaining tests must be done in order
+ */
+
+ policy.setRecipe(VF_MODULE_CREATE);
+
+ // null tenant
+ aaiNqResp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems()
+ .remove(1);
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
+
+ // null service item
+ aaiNqResp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0)
+ .setItems(null);
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
+
+ // null response
+ aaiNqResp.setAaiNqResponse(null);
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
}
@Test
@@ -115,9 +155,11 @@ public class SoActorServiceProviderTest {
assertEquals("SO", sp.actor());
assertEquals(2, sp.recipes().size());
- assertEquals("VF Module Create", sp.recipes().get(0));
- assertEquals("VF Module Delete", sp.recipes().get(1));
- assertEquals(0, sp.recipePayloads("VF Module Create").size());
+ assertEquals(VF_MODULE_CREATE, sp.recipes().get(0));
+ assertEquals(VF_MODULE_DELETE, sp.recipes().get(1));
+ assertEquals(0, sp.recipePayloads(VF_MODULE_CREATE).size());
+ assertEquals(0, sp.recipeTargets("unknown recipe").size());
+ assertEquals(1, sp.recipeTargets(VF_MODULE_CREATE).size());
}
/**