-
- @Test
- public void testConstructModifyConfigRequest() {
- policy.setPayload(new HashMap<>());
- policy.getPayload().put(KEY1, VALUE1);
- policy.getPayload().put(KEY2, VALUE2);
-
- Request appcRequest;
- appcRequest = AppcActor.constructRequest(onsetEvent, operation, policy, "vnf01");
-
- /* The service provider must return a non null APPC request */
- assertNotNull(appcRequest);
-
- /* A common header is required and cannot be null */
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals(appcRequest.getCommonHeader().getRequestId(), onsetEvent.getRequestId());
-
- /* An action is required and cannot be null */
- assertNotNull(appcRequest.getAction());
- assertEquals(MODIFY_CONFIG, appcRequest.getAction());
-
- /* A payload is required and cannot be null */
- assertNotNull(appcRequest.getPayload());
- assertTrue(appcRequest.getPayload().containsKey(GENERIC_VNF_ID));
- assertNotNull(appcRequest.getPayload().get(GENERIC_VNF_ID));
- assertTrue(appcRequest.getPayload().containsKey(KEY1));
- assertTrue(appcRequest.getPayload().containsKey(KEY2));
-
- logger.debug("APPC Request: \n" + appcRequest.toString());
-
- /* Print out request as json to make sure serialization works */
- String jsonRequest = Serialization.gsonPretty.toJson(appcRequest);
- logger.debug(JSON_OUTPUT + jsonRequest);
-
- /* The JSON string must contain the following fields */
- assertTrue(jsonRequest.contains("CommonHeader"));
- assertTrue(jsonRequest.contains("Action"));
- assertTrue(jsonRequest.contains(MODIFY_CONFIG));
- assertTrue(jsonRequest.contains("Payload"));
- assertTrue(jsonRequest.contains(GENERIC_VNF_ID));
- assertTrue(jsonRequest.contains(KEY1));
- assertTrue(jsonRequest.contains(KEY2));
- assertTrue(jsonRequest.contains(SUBKEY));
- assertTrue(jsonRequest.contains(SUBVALUE));
- assertFalse(jsonRequest.contains(SUBVALUE + ".0"));
-
- Response appcResponse = new Response(appcRequest);
- appcResponse.setStatus(new ResponseStatus());
- appcResponse.getStatus().setCode(ResponseCode.SUCCESS.getValue());
- appcResponse.getStatus().setDescription("AppC success");
- /* Print out request as json to make sure serialization works */
- String jsonResponse = Serialization.gsonPretty.toJson(appcResponse);
- logger.debug(JSON_OUTPUT + jsonResponse);
- }
-
- @Test
- public void testConstructModifyConfigRequest_NullPayload() {
-
- Request appcRequest;
- appcRequest = AppcActor.constructRequest(onsetEvent, operation, policy, "vnf01");
-
- /* The service provider must return a non null APPC request */
- assertNotNull(appcRequest);
-
- /* A common header is required and cannot be null */
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals(appcRequest.getCommonHeader().getRequestId(), onsetEvent.getRequestId());
-
- /* An action is required and cannot be null */
- assertNotNull(appcRequest.getAction());
- assertEquals(MODIFY_CONFIG, appcRequest.getAction());
-
- /* A payload is required and cannot be null */
- assertNotNull(appcRequest.getPayload());
- assertTrue(appcRequest.getPayload().containsKey(GENERIC_VNF_ID));
- assertNotNull(appcRequest.getPayload().get(GENERIC_VNF_ID));
-
- logger.debug("APPC Request: \n" + appcRequest.toString());
-
- /* Print out request as json to make sure serialization works */
- String jsonRequest = Serialization.gsonPretty.toJson(appcRequest);
- logger.debug(JSON_OUTPUT + jsonRequest);
-
- /* The JSON string must contain the following fields */
- assertTrue(jsonRequest.contains("CommonHeader"));
- assertTrue(jsonRequest.contains("Action"));
- assertTrue(jsonRequest.contains(MODIFY_CONFIG));
- assertTrue(jsonRequest.contains("Payload"));
- assertTrue(jsonRequest.contains(GENERIC_VNF_ID));
-
- Response appcResponse = new Response(appcRequest);
- appcResponse.setStatus(new ResponseStatus());
- appcResponse.getStatus().setCode(ResponseCode.SUCCESS.getValue());
- appcResponse.getStatus().setDescription("AppC success");
- /* Print out request as json to make sure serialization works */
- String jsonResponse = Serialization.gsonPretty.toJson(appcResponse);
- logger.debug(JSON_OUTPUT + jsonResponse);
- }
-
- @Test
- public void testMethods() {
- AppcActor sp = new AppcActor();
-
- assertEquals("APPC", sp.actor());
- assertEquals(4, sp.recipes().size());
- assertEquals("VM", sp.recipeTargets("Restart").get(0));
- assertEquals(0, sp.recipePayloads("Restart").size());
- }