diff options
author | Keighron, Lori (lk2924) <lk2924@att.com> | 2019-11-25 14:17:57 -0500 |
---|---|---|
committer | Keighron, Lori (lk2924) <lk2924@att.com> | 2019-11-26 15:47:49 -0500 |
commit | cea67fafd905f169b8db5c4be0b47959b66c32e3 (patch) | |
tree | 0b9020fc88d106916bb1e4b66667dea74ef6e701 | |
parent | 0f9c0df9e651bbcbdb3e4b8133f57abe2482cbec (diff) |
Add new LCM actions GetConfig, StartTraffic, StopTraffic, etc
New LCM actions
Change-Id: Ic59607f2a7fc515bdd01be162018aaf695668f82
Issue-ID: APPC-1790
Signed-off-by: Keighron, Lori (lk2924) <lk2924@att.com>
33 files changed, 4908 insertions, 111 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java index e08e49630..2f7fbc2b2 100644 --- a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java +++ b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java @@ -39,16 +39,26 @@ public enum VNFOperation { ConfigRestore, ConfigScaleOut, DetachVolume, + DistributeTraffic, + DistributeTrafficCheck, Evacuate, + GetConfig, HealthCheck, + LicenseManagement, LiveUpgrade, Lock(true), Migrate, + PostEvacuate, + PostMigrate, + PostRebuild, + Provisioning, + PreConfigure, + PreEvacuate, + PreMigrate, + PreRebuild, Query, QuiesceTraffic, ResumeTraffic, - DistributeTraffic, - DistributeTrafficCheck, Reboot, Rebuild, Restart, @@ -57,8 +67,11 @@ public enum VNFOperation { SoftwareUpload, Start, StartApplication, + StartTraffic, + StatusTraffic, Stop, StopApplication, + StopTraffic, Sync, Terminate, Test, @@ -73,7 +86,7 @@ public enum VNFOperation { private boolean builtIn; VNFOperation() { - this.builtIn=false; + this.builtIn = false; } /** diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java index 73a2de6db..6d62c107b 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java @@ -69,20 +69,20 @@ public class Converter { public static Builder<?> convAsyncResponseToBuilder(VNFOperation vnfOperation, String rpcName, ResponseContext response) { Builder<?> outObj = null; - if(response == null){ + if (response == null) { throw new IllegalArgumentException("empty asyncResponse"); } - if(vnfOperation == null){ + if (vnfOperation == null) { throw new IllegalArgumentException("empty asyncResponse.action"); } - logger.debug("Entered Converter.convAsyncResponseToBuilder() : Operation Name "+ vnfOperation.name()); + logger.debug("Entered Converter.convAsyncResponseToBuilder(): Operation Name " + vnfOperation.name()); org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action action = org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action.valueOf(vnfOperation.name()); logger.debug("After resolving action"); CommonHeader commonHeader = convAsyncResponseTorev160108CommonHeader(response); Status status = convAsyncResponseTorev160108Status(response); Payload payload = convAsyncResponseTorev160108Payload(response); - logger.debug("Extracted action, status, payload "); - switch (action){ + logger.debug("Extracted action, status, payload"); + switch (action) { case Rollback: outObj = new RollbackOutputBuilder(); ((RollbackOutputBuilder)outObj).setCommonHeader(commonHeader); @@ -93,7 +93,8 @@ public class Converter { ((SnapshotOutputBuilder)outObj).setCommonHeader(commonHeader); ((SnapshotOutputBuilder)outObj).setStatus(status); try { - ((SnapshotOutputBuilder) outObj).setSnapshotId(response.getAdditionalContext().get("output.snapshot-id")); + ((SnapshotOutputBuilder) outObj) + .setSnapshotId(response.getAdditionalContext().get("output.snapshot-id")); } catch (NullPointerException ignored) { // in case of negative response, snapshotID does not populated, so just ignore NPL } @@ -109,7 +110,7 @@ public class Converter { ((HealthCheckOutputBuilder)outObj).setCommonHeader(commonHeader); ((HealthCheckOutputBuilder)outObj).setStatus(status); ((HealthCheckOutputBuilder)outObj).setPayload(payload); - logger.debug("In HealthCheck case- created outObj, returning"); + logger.debug("In HealthCheck case: created outObj, returning"); return outObj; case LiveUpgrade: outObj = new LiveUpgradeOutputBuilder(); @@ -227,26 +228,31 @@ public class Converter { outObj = new StopApplicationOutputBuilder(); ((StopApplicationOutputBuilder)outObj).setCommonHeader(commonHeader); ((StopApplicationOutputBuilder)outObj).setStatus(status); + ((StopApplicationOutputBuilder)outObj).setPayload(payload); return outObj; case StartApplication: outObj = new StartApplicationOutputBuilder(); ((StartApplicationOutputBuilder)outObj).setCommonHeader(commonHeader); ((StartApplicationOutputBuilder)outObj).setStatus(status); + ((StartApplicationOutputBuilder)outObj).setPayload(payload); return outObj; - case QuiesceTraffic: + case QuiesceTraffic: outObj = new QuiesceTrafficOutputBuilder(); ((QuiesceTrafficOutputBuilder)outObj).setCommonHeader(commonHeader); ((QuiesceTrafficOutputBuilder)outObj).setStatus(status); + ((QuiesceTrafficOutputBuilder)outObj).setPayload(payload); return outObj; case ResumeTraffic: outObj = new ResumeTrafficOutputBuilder(); ((ResumeTrafficOutputBuilder)outObj).setCommonHeader(commonHeader); ((ResumeTrafficOutputBuilder)outObj).setStatus(status); + ((ResumeTrafficOutputBuilder)outObj).setPayload(payload); return outObj; case UpgradeSoftware: outObj = new UpgradeSoftwareOutputBuilder(); ((UpgradeSoftwareOutputBuilder)outObj).setCommonHeader(commonHeader); ((UpgradeSoftwareOutputBuilder)outObj).setStatus(status); + ((UpgradeSoftwareOutputBuilder)outObj).setPayload(payload); return outObj; case UpgradePostCheck: outObj = new UpgradePostCheckOutputBuilder(); @@ -258,11 +264,13 @@ public class Converter { outObj = new UpgradeBackupOutputBuilder(); ((UpgradeBackupOutputBuilder)outObj).setCommonHeader(commonHeader); ((UpgradeBackupOutputBuilder)outObj).setStatus(status); + ((UpgradeBackupOutputBuilder)outObj).setPayload(payload); return outObj; case UpgradeBackout: outObj = new UpgradeBackoutOutputBuilder(); ((UpgradeBackoutOutputBuilder)outObj).setCommonHeader(commonHeader); ((UpgradeBackoutOutputBuilder)outObj).setStatus(status); + ((UpgradeBackoutOutputBuilder)outObj).setPayload(payload); return outObj; case UpgradePreCheck: outObj = new UpgradePreCheckOutputBuilder(); @@ -290,28 +298,106 @@ public class Converter { ((DistributeTrafficCheckOutputBuilder) outObj).setCommonHeader(commonHeader); ((DistributeTrafficCheckOutputBuilder)outObj).setStatus(status); return outObj; + case PreConfigure: + outObj = new PreConfigureOutputBuilder(); + ((PreConfigureOutputBuilder)outObj).setCommonHeader(commonHeader); + ((PreConfigureOutputBuilder)outObj).setStatus(status); + ((PreConfigureOutputBuilder)outObj).setPayload(payload); + return outObj; + case GetConfig: + outObj = new GetConfigOutputBuilder(); + ((GetConfigOutputBuilder)outObj).setCommonHeader(commonHeader); + ((GetConfigOutputBuilder)outObj).setStatus(status); + ((GetConfigOutputBuilder)outObj).setPayload(payload); + return outObj; + case PostEvacuate: + outObj = new PostEvacuateOutputBuilder(); + ((PostEvacuateOutputBuilder)outObj).setCommonHeader(commonHeader); + ((PostEvacuateOutputBuilder)outObj).setStatus(status); + ((PostEvacuateOutputBuilder)outObj).setPayload(payload); + return outObj; + case PreMigrate: + outObj = new PreMigrateOutputBuilder(); + ((PreMigrateOutputBuilder)outObj).setCommonHeader(commonHeader); + ((PreMigrateOutputBuilder)outObj).setStatus(status); + ((PreMigrateOutputBuilder)outObj).setPayload(payload); + return outObj; + case PostMigrate: + outObj = new PostMigrateOutputBuilder(); + ((PostMigrateOutputBuilder)outObj).setCommonHeader(commonHeader); + ((PostMigrateOutputBuilder)outObj).setStatus(status); + ((PostMigrateOutputBuilder)outObj).setPayload(payload); + return outObj; + case PreRebuild: + outObj = new PreRebuildOutputBuilder(); + ((PreRebuildOutputBuilder)outObj).setCommonHeader(commonHeader); + ((PreRebuildOutputBuilder)outObj).setStatus(status); + ((PreRebuildOutputBuilder)outObj).setPayload(payload); + return outObj; + case Provisioning: + outObj = new ProvisioningOutputBuilder(); + ((ProvisioningOutputBuilder)outObj).setCommonHeader(commonHeader); + ((ProvisioningOutputBuilder)outObj).setStatus(status); + ((ProvisioningOutputBuilder)outObj).setPayload(payload); + return outObj; + case PostRebuild: + outObj = new PostRebuildOutputBuilder(); + ((PostRebuildOutputBuilder)outObj).setCommonHeader(commonHeader); + ((PostRebuildOutputBuilder)outObj).setStatus(status); + ((PostRebuildOutputBuilder)outObj).setPayload(payload); + return outObj; + case PreEvacuate: + outObj = new PreEvacuateOutputBuilder(); + ((PreEvacuateOutputBuilder)outObj).setCommonHeader(commonHeader); + ((PreEvacuateOutputBuilder)outObj).setStatus(status); + ((PreEvacuateOutputBuilder)outObj).setPayload(payload); + return outObj; + case StartTraffic: + outObj = new StartTrafficOutputBuilder(); + ((StartTrafficOutputBuilder)outObj).setCommonHeader(commonHeader); + ((StartTrafficOutputBuilder)outObj).setStatus(status); + ((StartTrafficOutputBuilder)outObj).setPayload(payload); + return outObj; + case StatusTraffic: + outObj = new StatusTrafficOutputBuilder(); + ((StatusTrafficOutputBuilder)outObj).setCommonHeader(commonHeader); + ((StatusTrafficOutputBuilder)outObj).setStatus(status); + ((StatusTrafficOutputBuilder)outObj).setPayload(payload); + return outObj; + case StopTraffic: + outObj = new StopTrafficOutputBuilder(); + ((StopTrafficOutputBuilder)outObj).setCommonHeader(commonHeader); + ((StopTrafficOutputBuilder)outObj).setStatus(status); + ((StopTrafficOutputBuilder)outObj).setPayload(payload); + return outObj; + case LicenseManagement: + outObj = new LicenseManagementOutputBuilder(); + ((LicenseManagementOutputBuilder)outObj).setCommonHeader(commonHeader); + ((LicenseManagementOutputBuilder)outObj).setStatus(status); + ((LicenseManagementOutputBuilder)outObj).setPayload(payload); + return outObj; default: throw new IllegalArgumentException(action+" action is not supported"); } } public static Payload convAsyncResponseTorev160108Payload(ResponseContext inObj) { - logger.debug("Entering convAsyncResponseTorev160108Payload" ); + logger.debug("Entering convAsyncResponseTorev160108Payload"); Payload payload = null; - if(inObj.getPayload() != null) { + if (inObj.getPayload() != null) { payload = new Payload(inObj.getPayload()); } - logger.debug("Exiting convAsyncResponseTorev160108Payload" ); + logger.debug("Exiting convAsyncResponseTorev160108Payload"); return payload; } public static String convPayloadObjectToJsonString(Object inObj) throws ParseException { String payloadAsString = null; - if(inObj != null) { + if (inObj != null) { - if(inObj instanceof String){ + if (inObj instanceof String) { payloadAsString = (String)inObj; - }else { + } else { try { ObjectMapper objectMapper = new ObjectMapper(); payloadAsString = objectMapper.writeValueAsString(inObj); @@ -336,13 +422,13 @@ public class Converter { public static CommonHeader convAsyncResponseTorev160108CommonHeader(ResponseContext inObj) { logger.debug("Entered into convAsyncResponseTorev160108CommonHeader"); CommonHeader outObj = null; - if(inObj == null){ + if (inObj == null) { throw new IllegalArgumentException("empty asyncResponse"); } CommonHeaderBuilder commonHeaderBuilder = new CommonHeaderBuilder(); org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.common.header.Flags commonHeaderFlags; - if(inObj.getCommonHeader().getFlags() != null){ + if (inObj.getCommonHeader().getFlags() != null) { commonHeaderFlags = Converter.convFlagsMapTorev160108Flags(inObj.getCommonHeader().getFlags()); commonHeaderBuilder.setFlags(commonHeaderFlags); } @@ -350,15 +436,15 @@ public class Converter { logger.debug("Before setApiVer"); commonHeaderBuilder.setApiVer(inObj.getCommonHeader().getApiVer()); commonHeaderBuilder.setRequestId(inObj.getCommonHeader().getRequestId()); - if(inObj.getCommonHeader().getSubRequestId() != null){ + if (inObj.getCommonHeader().getSubRequestId() != null) { commonHeaderBuilder.setSubRequestId(inObj.getCommonHeader().getSubRequestId()); } logger.debug("Before getOriginatorId"); - if(inObj.getCommonHeader().getOriginatorId() != null){ + if (inObj.getCommonHeader().getOriginatorId() != null) { commonHeaderBuilder.setOriginatorId(inObj.getCommonHeader().getOriginatorId()); } logger.debug("Before getTimeStamp"); - if(inObj.getCommonHeader().getTimeStamp() != null){ + if (inObj.getCommonHeader().getTimeStamp() != null) { String zuluTimestampStr = Converter.convDateToZuluString(inObj.getCommonHeader().getTimeStamp()); logger.debug("After invoking convDateToZuluString()"); ZULU zuluTimestamp = new ZULU(zuluTimestampStr); @@ -366,7 +452,7 @@ public class Converter { commonHeaderBuilder.setTimestamp(zuluTimestamp); } outObj = commonHeaderBuilder.build(); - logger.debug("Exiting from convAsyncResponseTorev160108CommonHeader: Returning outObj::"+outObj.toString()); + logger.debug("Exiting from convAsyncResponseTorev160108CommonHeader: Returning outObj::"+ outObj.toString()); return outObj; } @@ -409,7 +495,9 @@ public class Converter { return rev160108flags; } - public static String convAsyncResponseToJsonStringBody(VNFOperation vnfOperation, String rpcName, ResponseContext asyncResponse) throws JsonProcessingException { + public static String convAsyncResponseToJsonStringBody( + VNFOperation vnfOperation, String rpcName, ResponseContext asyncResponse) + throws JsonProcessingException { Builder<?> builder = Converter.convAsyncResponseToBuilder(vnfOperation, rpcName, asyncResponse); Object message = builder.build(); ObjectMapper objectMapper = new ObjectMapper(); @@ -421,14 +509,21 @@ public class Converter { objectMapper.addMixIn(ZULU.class, MixIn.class); // .configure(SerializationConfig.Feature.SORT_PROPERTIES_ALPHABETICALLY,true) - ObjectWriter writer = objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL).configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY,true) - .writer(SerializationFeature.WRAP_ROOT_VALUE).withRootName(DMaaP_ROOT_VALUE).withoutFeatures(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); + ObjectWriter writer = objectMapper + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true) + .writer(SerializationFeature.WRAP_ROOT_VALUE) + .withRootName(DMaaP_ROOT_VALUE) + .withoutFeatures(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); return writer.writeValueAsString(message); } - public static String convAsyncResponseToDmaapOutgoingMessageJsonString(VNFOperation vnfOperation, String rpcName, ResponseContext asyncResponse) throws JsonProcessingException { + public static String convAsyncResponseToDmaapOutgoingMessageJsonString( + VNFOperation vnfOperation, String rpcName, ResponseContext asyncResponse) + throws JsonProcessingException { logger.debug("Entered Converter.convAsyncResponseToDmaapOutgoingMessageJsonString()"); - DmaapOutgoingMessage dmaapOutgoingMessage = convAsyncResponseToDmaapOutgoingMessage(vnfOperation, rpcName, asyncResponse); + DmaapOutgoingMessage dmaapOutgoingMessage = + convAsyncResponseToDmaapOutgoingMessage(vnfOperation, rpcName, asyncResponse); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.addMixIn(dmaapOutgoingMessage.getBody().getOutput().getClass(), MixInFlagsMessage.class); objectMapper.addMixIn(CommonHeader.class, MixInCommonHeader.class); @@ -438,31 +533,37 @@ public class Converter { objectMapper.addMixIn(ZULU.class, MixIn.class); // .configure(SerializationConfig.Feature.SORT_PROPERTIES_ALPHABETICALLY,true) - ObjectWriter writer = objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL).configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY,true).writer(); + ObjectWriter writer = objectMapper + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true) + .writer(); logger.debug("Exiting Converter.convAsyncResponseToDmaapOutgoingMessageJsonString()"); return writer.writeValueAsString(dmaapOutgoingMessage); } - public static DmaapOutgoingMessage convAsyncResponseToDmaapOutgoingMessage(VNFOperation vnfOperation, String rpcName, ResponseContext asyncResponse) throws JsonProcessingException { + public static DmaapOutgoingMessage convAsyncResponseToDmaapOutgoingMessage( + VNFOperation vnfOperation, String rpcName, ResponseContext asyncResponse) + throws JsonProcessingException { logger.debug("Entered Converter.convAsyncResponseToDmaapOutgoingMessage()"); DmaapOutgoingMessage outObj = new DmaapOutgoingMessage(); String correlationID = getCorrelationID(asyncResponse); outObj.setCorrelationID(correlationID); outObj.setType("response"); outObj.setRpcName(rpcName); - logger.debug("In onverter.convAsyncResponseToDmaapOutgoingMessage() before invoking convAsyncResponseToBuilder"); + logger.debug("In Converter.convAsyncResponseToDmaapOutgoingMessage()" + + " before invoking convAsyncResponseToBuilder"); Builder<?> builder = Converter.convAsyncResponseToBuilder(vnfOperation, rpcName, asyncResponse); Object messageBody = builder.build(); DmaapOutgoingMessage.Body body = new DmaapOutgoingMessage.Body(messageBody); outObj.setBody(body); - logger.debug("Exiting Converter.convAsyncResponseToDmaapOutgoingMessage():messageBody is :::"+body.toString()); + logger.debug("Exiting Converter.convAsyncResponseToDmaapOutgoingMessage(): messageBody is:" + body.toString()); return outObj; } private static String getCorrelationID(ResponseContext context) { return context.getCommonHeader().getRequestId() + (context.getCommonHeader().getSubRequestId() == null ? - "":"-" + context.getCommonHeader().getSubRequestId()); + "" : "-" + context.getCommonHeader().getSubRequestId()); } abstract class MixIn { diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java index 0bfd4d6ad..dbba6caa1 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -11,15 +11,14 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -54,16 +53,27 @@ public class ConverterTest { private String expectedDmaapOutgoingMessageJsonStringUnlock ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"unlock\",\"type\":\"response\"}"; private String expectedDmaapOutgoingMessageJsonStringUpgradePreCheck ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgrade-pre-check\",\"type\":\"response\"}"; private String expectedDmaapOutgoingMessageJsonStringUpgradePostCheck ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgrade-post-check\",\"type\":\"response\"}"; - private String expectedDmaapOutgoingMessageJsonStringUpgradeSoftware ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradesoftware\",\"type\":\"response\"}"; - private String expectedDmaapOutgoingMessageJsonStringUpgradeBackout ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradebackout\",\"type\":\"response\"}"; - private String expectedDmaapOutgoingMessageJsonStringUpgradeBackup ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradebackup\",\"type\":\"response\"}"; - - private String expectedJsonBodyStrwithPayload ="{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}}"; + private String expectedDmaapOutgoingMessageJsonStringUpgradeSoftware ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradesoftware\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringUpgradeBackout ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradebackout\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringUpgradeBackup ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradebackup\",\"type\":\"response\"}"; private String expectedDmaapOutgoingMessageJsonStringReboot ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"reboot\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringPreConfigure ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"pre-configure\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringGetConfig ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"get-config\",\"type\":\"response\"}"; + private String expectedJsonBodyStrwithPayload ="{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}}"; private String expectedDmaapOutgoingMessageJsonStringDistributeTraffic = "{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"distribute-traffic\",\"type\":\"response\"}"; private String expectedDmaapOutgoingMessageJsonStringDistributeTrafficCheck = "{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"distribute-traffic-check\",\"type\":\"response\"}"; - - + private String expectedDmaapOutgoingMessageJsonStringPreRebuild ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"pre-rebuild\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringPostRebuild ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"post-rebuild\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringPreEvacuate ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"pre-evacuate\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringPreMigrate ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"pre-migrate\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringPostMigrate ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"post-migrate\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringPostEvacuate ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"post-evacuate\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringLicenseManagement ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"license-management\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringStartTraffic ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"start-traffic\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringStatusTraffic ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"status-traffic\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringStopTraffic ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"stop-traffic\",\"type\":\"response\"}"; + private String expectedDmaapOutgoingMessageJsonStringProvisioning ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"provisioning\",\"type\":\"response\"}"; + @Test public void convDateToZuluStringTest(){ String dateToZuluString = Converter.convDateToZuluString(new Date(0L)); @@ -76,7 +86,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.Test; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -86,7 +96,7 @@ public class ConverterTest { String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringTest,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringTest, jsonStr); } @Test @@ -106,7 +116,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.Rollback; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -116,7 +126,7 @@ public class ConverterTest { String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringRollback,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringRollback, jsonStr); } @Test @@ -125,7 +135,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.Snapshot; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -135,7 +145,7 @@ public class ConverterTest { String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSnapshot,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSnapshot, jsonStr); } @Test public void convAsyncResponseToBuilderAuditTest() throws JsonProcessingException { @@ -143,7 +153,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.Audit; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test @@ -153,7 +163,7 @@ public class ConverterTest { String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringAudit,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringAudit, jsonStr); } @Test public void convAsyncResponseToBuilderHealthCheckTest() throws JsonProcessingException { @@ -161,7 +171,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.HealthCheck; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test @@ -171,7 +181,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringHealthCheck,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringHealthCheck, jsonStr); } @Test public void convAsyncResponseToBuilderLiveUpgradeTest() throws JsonProcessingException { @@ -179,7 +189,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.LiveUpgrade; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -189,7 +199,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLiveUpgrade,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLiveUpgrade, jsonStr); } @Test public void convAsyncResponseToBuilderLockTest() throws JsonProcessingException { @@ -198,7 +208,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -208,7 +218,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLock,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLock, jsonStr); } @Test public void convAsyncResponseToBuilderModifyConfigTest() throws JsonProcessingException { @@ -216,7 +226,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.ConfigModify; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test @@ -226,7 +236,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringModifyConfig,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringModifyConfig, jsonStr); } @Test public void convAsyncResponseToBuilderSoftwareUploadTest() throws JsonProcessingException { @@ -235,7 +245,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -245,15 +255,16 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSoftwareUpload,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSoftwareUpload, jsonStr); } + @Test public void convAsyncResponseToBuilderStopTest() throws JsonProcessingException { ResponseContext asyncResponse = buildAsyncResponse(); VNFOperation action = VNFOperation.Stop; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -263,8 +274,9 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringStop,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringStop, jsonStr); } + @Test public void convAsyncResponseToBuilderSync() throws JsonProcessingException { ResponseContext asyncResponse = buildAsyncResponsewithPayload(); @@ -272,7 +284,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test @@ -282,7 +294,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSync,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSync, jsonStr); } @Test public void convAsyncResponseToBuilderTerminateTest() throws JsonProcessingException { @@ -290,7 +302,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.Sync; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test @@ -300,15 +312,16 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringTerminate,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringTerminate, jsonStr); } + @Test public void convAsyncResponseToBuilderUnlockTest() throws JsonProcessingException { ResponseContext asyncResponse = buildAsyncResponse(); VNFOperation action = VNFOperation.Unlock; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -318,8 +331,9 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUnlock,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUnlock, jsonStr); } + @Test public void convAsyncResponseToBuilderRebootTest() throws JsonProcessingException { ResponseContext asyncResponse = buildAsyncResponse(); @@ -327,7 +341,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -337,15 +351,16 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringReboot,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringReboot, jsonStr); } + @Test public void convAsyncResponseToBuilderUpgradePreCheckTest() throws JsonProcessingException { ResponseContext asyncResponse = buildAsyncResponsewithPayload(); VNFOperation action = VNFOperation.UpgradePreCheck; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test @@ -355,7 +370,7 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradePreCheck,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradePreCheck, jsonStr); } @Test @@ -364,7 +379,7 @@ public class ConverterTest { VNFOperation action = VNFOperation.UpgradePostCheck; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test @@ -374,62 +389,101 @@ public class ConverterTest { String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradePostCheck,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradePostCheck, jsonStr); } + @Test public void convAsyncResponseToBuilderUpgradeSoftwareTest() throws JsonProcessingException { - ResponseContext asyncResponse = buildAsyncResponse(); + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); VNFOperation action = VNFOperation.UpgradeSoftware; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test public void convAsyncResponseToDmaapOutgoingMessageJsonStringUpgradeSoftwareTest() throws JsonProcessingException { - ResponseContext asyncResponse = buildAsyncResponse(); + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); VNFOperation action = VNFOperation.UpgradeSoftware; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeSoftware,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeSoftware, jsonStr); } - @Test public void convAsyncResponseToBuilderUpgradeBackoutTest() throws JsonProcessingException { - ResponseContext asyncResponse = buildAsyncResponse(); + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); VNFOperation action = VNFOperation.UpgradeBackout; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test public void convAsyncResponseToDmaapOutgoingMessageJsonStringUpgradeBackoutTest() throws JsonProcessingException { - ResponseContext asyncResponse = buildAsyncResponse(); + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); VNFOperation action = VNFOperation.UpgradeBackout; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeBackout,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeBackout, jsonStr); } @Test public void convAsyncResponseToBuilderUpgradeBackupTest() throws JsonProcessingException { - ResponseContext asyncResponse = buildAsyncResponse(); + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); VNFOperation action = VNFOperation.UpgradeBackup; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); } @Test public void convAsyncResponseToDmaapOutgoingMessageJsonStringUpgradeBackupTest() throws JsonProcessingException { - ResponseContext asyncResponse = buildAsyncResponse(); + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); VNFOperation action = VNFOperation.UpgradeBackup; String rpcName = action.name().toLowerCase(); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeBackup,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeBackup, jsonStr); + } + @Test + public void convAsyncResponseToBuilderPreConfigureTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PreConfigure; + String rpcName = convertActionNameToUrl(action.name()); + + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringPreConfigureTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PreConfigure; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringPreConfigure, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderGetConfigTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.GetConfig; + String rpcName = convertActionNameToUrl(action.name()); + + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringGetConfigTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.GetConfig; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringGetConfig, jsonStr); } @Test @@ -438,33 +492,259 @@ public class ConverterTest { VNFOperation action = VNFOperation.DistributeTraffic; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test - public void convAsyncResponseToDmaapOutgoingMessageJsonStringDistributeTrafficTest() throws JsonProcessingException { + public void convAsyncResponseToDmaapOutgoingMessageJsonStringDistributeTrafficTest() + throws JsonProcessingException { ResponseContext asyncResponse = buildAsyncResponse(); VNFOperation action = VNFOperation.DistributeTraffic; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTraffic,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTraffic, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderDistributeTrafficCheckTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponse(); + VNFOperation action = VNFOperation.DistributeTrafficCheck; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test - public void convAsyncResponseToDmaapOutgoingMessageJsonStringDistributeTrafficCheckTest() throws JsonProcessingException { + public void convAsyncResponseToDmaapOutgoingMessageJsonStringDistributeTrafficCheckTest() + throws JsonProcessingException { ResponseContext asyncResponse = buildAsyncResponse(); VNFOperation action = VNFOperation.DistributeTrafficCheck; String rpcName = convertActionNameToUrl(action.name()); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTrafficCheck,jsonStr); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTrafficCheck, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderPreRebuildTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PreRebuild; + String rpcName = convertActionNameToUrl(action.name()); + + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringPreRebuildTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PreRebuild; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringPreRebuild, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderPostRebuildTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PostRebuild; + String rpcName = convertActionNameToUrl(action.name()); + + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringPostRebuildTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PostRebuild; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringPostRebuild, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderPreEvacuateTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PreEvacuate; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringPreEvacuateTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PreEvacuate; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringPreEvacuate, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderPreMigrateTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PreMigrate; + String rpcName = convertActionNameToUrl(action.name()); + + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringPreMigrateTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PreMigrate; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringPreMigrate, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderPostMigrateTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PostMigrate; + String rpcName = convertActionNameToUrl(action.name()); + + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringPostMigrateTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PostMigrate; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringPostMigrate, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderPostEvacuateTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PostEvacuate; + String rpcName = convertActionNameToUrl(action.name()); + + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringPostEvacuateTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.PostEvacuate; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringPostEvacuate, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderStartTrafficTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.StartTraffic; + String rpcName = convertActionNameToUrl(action.name()); + + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringStartTrafficTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.StartTraffic; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringStartTraffic, jsonStr); + } + + @Test + public void convAsyncResponseToBuilderStatusTrafficTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.StatusTraffic; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringStatusTrafficTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.StatusTraffic; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringStatusTraffic, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringLicenseManagementTest() + throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.LicenseManagement; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLicenseManagement,jsonStr); + } + + @Test + public void convAsyncResponseToBuilderLicenseManagementTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.LicenseManagement; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + } + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringProvisioningTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.Provisioning; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringProvisioning,jsonStr); + } + + @Test + public void convAsyncResponseToBuilderProvisioningTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.Provisioning; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr); + } + @Test + public void convAsyncResponseToBuilderStopTrafficTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.StopTraffic; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse); + Assert.assertEquals(expectedJsonBodyStrwithPayload, jsonStr); + } + + @Test + public void convAsyncResponseToDmaapOutgoingMessageJsonStringStopTrafficTest() throws JsonProcessingException { + ResponseContext asyncResponse = buildAsyncResponsewithPayload(); + VNFOperation action = VNFOperation.StopTraffic; + String rpcName = convertActionNameToUrl(action.name()); + String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse); + System.out.println("jsonStr = " + jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringStopTraffic, jsonStr); } /*@Test public void convAsyncResponseToBuilderTest() throws JsonProcessingException { AsyncResponse asyncResponse = buildAsyncResponse(); String jsonStr = Converter.convAsyncResponseToJsonStringBody(asyncResponse); - Assert.assertEquals(expectedJsonBodyStr,jsonStr); + Assert.assertEquals(expectedJsonBodyStr, jsonStr); } @Test @@ -472,7 +752,7 @@ public class ConverterTest { AsyncResponse asyncResponse = buildAsyncResponse(); String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(asyncResponse); System.out.println("jsonStr = " + jsonStr); - Assert.assertEquals(expectedDmaapOutgoingMessageJsonString,jsonStr); + Assert.assertEquals(expectedDmaapOutgoingMessageJsonString, jsonStr); }*/ @@ -484,7 +764,8 @@ public class ConverterTest { asyncResponse.getCommonHeader().setApiVer("2.0.0"); asyncResponse.getCommonHeader().setRequestId("reqid"); asyncResponse.getCommonHeader().setTimestamp(new Date(1000L)); - asyncResponse.setPayload("any valid JSON string value. Json escape characters need to be added to make it a valid json string value"); + asyncResponse.setPayload( + "any valid JSON string value. Json escape characters need to be added to make it a valid json string value"); return asyncResponse; } @@ -521,6 +802,3 @@ public class ConverterTest { } - - - diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java index d0b8a834c..b6fd2f599 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java @@ -119,7 +119,14 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { private static final String CONFIGURE_PARAM = "Configure"; private static final String CONFIG_SCALE_OUT_PARAM = "ConfigScaleOut"; private static final String CONFIG_MODIFY_PARAM = "ConfigModify"; - + private static final String GET_CONFIG = "GetConfig"; + private static final String POST_EVACUATE= "PostEvacuate"; + private static final String PRE_EVACUATE = "PreEvacuate"; + private static final String POST_MIGRATE = "PostMigrate"; + private static final String PRE_MIGRATE = "PreMigrate"; + private static final String PRE_REBUILD = "PreRebuild"; + private static final String POST_REBUILD = "PostRebuild"; + private static final String STOP_TRAFFIC = "StopTraffic"; public void processArtifact(Map<String, String> inParams, SvcLogicContext ctx) throws ArtifactProcessorException { if (inParams == null || inParams.isEmpty()) { @@ -155,6 +162,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { } updateStoreArtifacts(requestInfo, documentInfo); + if (artifactName.toLowerCase().startsWith(REFERENCE)) { return storeReferenceData(requestInfo, documentInfo); } else if (artifactName.toLowerCase().startsWith(PD)) { @@ -172,6 +180,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { } public void validateAnsibleAdminArtifact(JSONObject documentInfo) throws ArtifactHandlerInternalException { + String fn = "ArtifactHandlerNode.validateAnsibleAdminArtifact"; String artifactName = documentInfo.getString(ARTIFACT_NAME); log.info(fn + ": Received Admin File Name: " + artifactName + " ArtifactCotent : " @@ -598,7 +607,16 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { public void processConfigTypeActions(JSONObject content, DBService dbservice, SvcLogicContext context) throws ArtifactHandlerInternalException { try { - if (isContentActionConfig(content)) { + if (isContentActionConfig(content) + || contentsActionEquals(content, GET_CONFIG) + || contentsActionEquals(content, POST_EVACUATE) + || contentsActionEquals(content, PRE_EVACUATE) + || contentsActionEquals(content, POST_MIGRATE) + || contentsActionEquals(content, PRE_MIGRATE) + || contentsActionEquals(content, POST_REBUILD) + || contentsActionEquals(content, PRE_REBUILD) + || contentsActionEquals(content, STOP_TRAFFIC) + ) { if (content.has(DOWNLOAD_DG_REFERENCE) && content.getString(DOWNLOAD_DG_REFERENCE).length() > 0) { @@ -763,7 +781,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { private void populateProtocolReference(DBService dbservice, JSONObject content) throws ArtifactHandlerInternalException { - log.info("Begin-->populateProtocolReference "); + log.info("Begin-->populateProtocolReference"); try { SvcLogicContext context = new SvcLogicContext(); JSONObject scope = content.getJSONObject("scope"); @@ -784,7 +802,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { log.error("Error inserting record into protocolReference", e); throw new ArtifactHandlerInternalException("Error inserting record into protocolReference", e); } finally { - log.info("End-->populateProtocolReference "); + log.info("End-->populateProtocolReference"); } } diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java index 7adee0da9..cb3a4625d 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java @@ -97,6 +97,7 @@ public class ArtifactHandlerNodeTest { JSONObject documentInfo = getDocumentInfo("templates/reference_template"); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); requestInfo.put("RequestInfo", "testValue"); + requestInfo.put("request-id","testREQUEST_ID"); input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); postData.put("input", input); @@ -273,6 +274,7 @@ public class ArtifactHandlerNodeTest { JSONObject documentInfo = getDocumentInfo("templates/pd_template"); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "pd_Junit.json"); requestInfo.put("RequestInfo", "testValue"); + requestInfo.put("request-id","testREQUEST_ID"); input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); postData.put("input", input); diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java index 2006b4967..d37da6529 100644 --- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java @@ -46,8 +46,21 @@ import org.onap.appc.provider.lcm.service.ResumeTrafficService; import org.onap.appc.provider.lcm.service.UpgradeService; import org.onap.appc.provider.lcm.service.VolumeService; import org.onap.appc.provider.lcm.service.ConfigScaleOutService; +import org.onap.appc.provider.lcm.service.PreConfigure; +import org.onap.appc.provider.lcm.service.PreRebuild; +import org.onap.appc.provider.lcm.service.GetConfigService; +import org.onap.appc.provider.lcm.service.PostRebuild; +import org.onap.appc.provider.lcm.service.PostEvacuateService; +import org.onap.appc.provider.lcm.service.PreMigrateService; +import org.onap.appc.provider.lcm.service.PostMigrateService; import org.onap.appc.provider.lcm.service.DistributeTrafficService; import org.onap.appc.provider.lcm.service.DistributeTrafficCheckService; +import org.onap.appc.provider.lcm.service.PreEvacuate; +import org.onap.appc.provider.lcm.service.ProvisioningService; +import org.onap.appc.provider.lcm.service.LicenseManagementService; +import org.onap.appc.provider.lcm.service.StartTraffic; +import org.onap.appc.provider.lcm.service.StatusTraffic; +import org.onap.appc.provider.lcm.service.StopTraffic; import org.onap.appc.provider.lcm.util.RequestInputBuilder; import org.onap.appc.provider.lcm.util.ValidationService; import org.onap.appc.requesthandler.objects.RequestHandlerInput; @@ -556,6 +569,96 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable, } @Override + public ListenableFuture<RpcResult<PreConfigureOutput>> preConfigure(PreConfigureInput input) { + logger.debug(String.format("LCM PreConfigure received input: %s", input.toString())); + PreConfigureOutputBuilder outputBuilder = new PreConfigure().process(input); + RpcResult<PreConfigureOutput> result = + RpcResultBuilder.<PreConfigureOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<GetConfigOutput>> getConfig(GetConfigInput input) { + logger.debug(String.format("LCM getConfig received input: %s", input.toString())); + GetConfigOutputBuilder outputBuilder = new GetConfigService().process(input); + RpcResult<GetConfigOutput> result = + RpcResultBuilder.<GetConfigOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<PreRebuildOutput>> preRebuild(PreRebuildInput input) { + logger.debug(String.format("LCM PreRebuild received input: %s", input.toString())); + PreRebuildOutputBuilder outputBuilder = new PreRebuild().process(input); + RpcResult<PreRebuildOutput> result = + RpcResultBuilder.<PreRebuildOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<PostRebuildOutput>> postRebuild(PostRebuildInput input) { + logger.debug(String.format("LCM PostRebuild received input: %s", input.toString())); + PostRebuildOutputBuilder outputBuilder = new PostRebuild().process(input); + RpcResult<PostRebuildOutput> result = + RpcResultBuilder.<PostRebuildOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<PreEvacuateOutput>> preEvacuate(PreEvacuateInput input) { + logger.debug(String.format("LCM PreEvacuate received input: %s", input.toString())); + PreEvacuateOutputBuilder outputBuilder = new PreEvacuate().process(input); + RpcResult<PreEvacuateOutput> result = + RpcResultBuilder.<PreEvacuateOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<ProvisioningOutput>> provisioning(ProvisioningInput input) { + logger.debug(String.format("LCM ProvisioningService received input: %s", input.toString())); + ProvisioningOutputBuilder outputBuilder = new ProvisioningService().process(input); + RpcResult<ProvisioningOutput> result = + RpcResultBuilder.<ProvisioningOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<LicenseManagementOutput>> licenseManagement(LicenseManagementInput input) { + logger.debug(String.format("LCM licensemangementService received input: %s", input.toString())); + LicenseManagementOutputBuilder outputBuilder = new LicenseManagementService().process(input); + RpcResult<LicenseManagementOutput> result = + RpcResultBuilder.<LicenseManagementOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<StartTrafficOutput>> startTraffic(StartTrafficInput input) { + logger.debug(String.format("LCM StartTraffic received input: %s", input.toString())); + StartTrafficOutputBuilder outputBuilder = new StartTraffic().process(input); + RpcResult<StartTrafficOutput> result = + RpcResultBuilder.<StartTrafficOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<StatusTrafficOutput>> statusTraffic(StatusTrafficInput input) { + logger.debug(String.format("LCM StatusTraffic received input: %s", input.toString())); + StatusTrafficOutputBuilder outputBuilder = new StatusTraffic().process(input); + RpcResult<StatusTrafficOutput> result = + RpcResultBuilder.<StatusTrafficOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<StopTrafficOutput>> stopTraffic(StopTrafficInput input) { + logger.debug(String.format("LCM StopTraffic received input: %s", input.toString())); + StopTrafficOutputBuilder outputBuilder = new StopTraffic().process(input); + RpcResult<StopTrafficOutput> result = + RpcResultBuilder.<StopTrafficOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override public ListenableFuture<RpcResult<TerminateOutput>> terminate(TerminateInput input) { logger.debug("Input received : " + input.toString()); TerminateOutputBuilder outputBuilder = new TerminateOutputBuilder(); @@ -674,6 +777,30 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable, } @Override + public ListenableFuture<RpcResult<PostEvacuateOutput>> postEvacuate(PostEvacuateInput input) { + logger.debug("Input received : " + input.toString()); + PostEvacuateOutputBuilder outputBuilder = new PostEvacuateService().process(input); + RpcResult<PostEvacuateOutput> result = RpcResultBuilder.<PostEvacuateOutput> status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<PreMigrateOutput>> preMigrate(PreMigrateInput input) { + logger.debug("Input received : " + input.toString()); + PreMigrateOutputBuilder outputBuilder = new PreMigrateService().process(input); + RpcResult<PreMigrateOutput> result = RpcResultBuilder.<PreMigrateOutput> status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<PostMigrateOutput>> postMigrate(PostMigrateInput input) { + logger.debug("Input received : " + input.toString()); + PostMigrateOutputBuilder outputBuilder = new PostMigrateService().process(input); + RpcResult<PostMigrateOutput> result = RpcResultBuilder.<PostMigrateOutput> status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override public ListenableFuture<RpcResult<ConfigRestoreOutput>> configRestore(ConfigRestoreInput input) { logger.debug("Input received : " + input.toString()); ConfigRestoreOutputBuilder outputBuilder = new ConfigRestoreOutputBuilder(); diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/GetConfigService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/GetConfigService.java new file mode 100644 index 000000000..05b13d15b --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/GetConfigService.java @@ -0,0 +1,124 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018-19 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.GetConfigInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.GetConfigOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.GetConfigOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+/**
+ * Provide LCM command service for GetConfig VNF Service
+ */
+public class GetConfigService extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public GetConfigService() {
+ super(Action.GetConfig);
+ logger.debug("GetConfigService starts");
+ }
+
+ /**
+ * Process the getConfig request
+ * @param input of GetConfigInput from the REST API input
+ * @return GetConfigOutputBuilder which has the process results
+ */
+ public GetConfigOutputBuilder process(GetConfigInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader,actionIdentifiers,payload);
+ }
+
+ GetConfigOutputBuilder outputBuilder = new GetConfigOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of GetConfigInput from the REST API input
+ */
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("GetConfigService (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ /**
+ * Proceed to action for the getConfig VNF action.
+ *
+ * @param input of GetConfigInput from the REST API input
+ */
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,
+ this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/LicenseManagementService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/LicenseManagementService.java new file mode 100644 index 000000000..3583f636d --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/LicenseManagementService.java @@ -0,0 +1,122 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LicenseManagementInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LicenseManagementOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LicenseManagementOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+/**
+ * Provide LCM command service for LicenseManagement VNF Service
+ */
+public class LicenseManagementService extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public LicenseManagementService() {
+ super(Action.LicenseManagement);
+ logger.debug("LicenseManagementService starts");
+ }
+
+ /**
+ * Process the LicenseManagement request
+ * @param input of LicenseManagementInput from the REST API input
+ * @return LicenseManagementOutputBuilder which has the process results
+ */
+ public LicenseManagementOutputBuilder process(LicenseManagementInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader,actionIdentifiers,payload);
+ }
+
+ LicenseManagementOutputBuilder outputBuilder = new LicenseManagementOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of LicenseManagementInput from the REST API input
+ */
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("LicenseManagementService (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ /**
+ * Proceed to action for the LicenseManagement VNF action.
+ *
+ * @param input of LicenseManagementInput from the REST API input
+ */
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,
+ this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
\ No newline at end of file diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostEvacuateService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostEvacuateService.java new file mode 100644 index 000000000..b63d7e840 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostEvacuateService.java @@ -0,0 +1,100 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PostEvacuateInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PostEvacuateOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.onap.appc.util.JsonUtil; +import java.io.IOException; +import java.util.Map; + +public class PostEvacuateService extends AbstractBaseService { + + public PostEvacuateService() { + super(Action.PostEvacuate); + logger.debug("PostEvacuateService starts"); + } + public PostEvacuateOutputBuilder process(PostEvacuateInput input) { + CommonHeader commonHeader = input.getCommonHeader(); + ActionIdentifiers actionIdentifiers = input.getActionIdentifiers(); + Payload payload = input.getPayload(); + + validate(commonHeader, input.getAction(), actionIdentifiers, payload); + if (status == null) { + proceedAction(commonHeader,actionIdentifiers,payload); + } + + PostEvacuateOutputBuilder outputBuilder = new PostEvacuateOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(input.getCommonHeader()); + return outputBuilder; + } + + + void validate(CommonHeader commonHeader, + Action action, + ActionIdentifiers actionIdentifiers, + Payload payload) { + status = validateVnfId(commonHeader, action, actionIdentifiers); + if (status != null) { + return; + } + + + String keyName = "payload"; + if (payload !=null) { + String payloadString = payload.getValue(); + status = validateMustHaveParamValue( + payloadString == null ? payloadString : payloadString.trim(), "payload"); + if (status != null) { + return; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + validateMustHaveParamValue(payloadMap.get(keyName), keyName); + } catch (IOException e) { + logger.error(String.format("PostEvacuateServiceService (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + } + + void proceedAction(CommonHeader commonHeader, + ActionIdentifiers actionIdentifiers, + Payload payload) { + RequestHandlerInput requestHandlerInput = + getRequestHandlerInput(commonHeader, actionIdentifiers, payload, this.getClass().getName()); + if (requestHandlerInput != null) { + executeAction(requestHandlerInput); + } + } +} + diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostMigrateService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostMigrateService.java new file mode 100644 index 000000000..002235933 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostMigrateService.java @@ -0,0 +1,104 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PostMigrateInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PostMigrateOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.onap.appc.util.JsonUtil; +import java.io.IOException; +import java.util.Map; + +public class PostMigrateService extends AbstractBaseService { + + public PostMigrateService() { + super(Action.PostMigrate); + logger.debug("PostMigrateService starts"); + } + public PostMigrateOutputBuilder process(PostMigrateInput input) { + CommonHeader commonHeader = input.getCommonHeader(); + ActionIdentifiers actionIdentifiers = input.getActionIdentifiers(); + Payload payload = input.getPayload(); + + validate(commonHeader, input.getAction(), actionIdentifiers, payload); + if (status == null) { + proceedAction(commonHeader,actionIdentifiers,payload); + } + + PostMigrateOutputBuilder outputBuilder = new PostMigrateOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(input.getCommonHeader()); + return outputBuilder; + } + + + void validate(CommonHeader commonHeader, + Action action, + ActionIdentifiers actionIdentifiers, + Payload payload) { + status = validateVnfId(commonHeader, action, actionIdentifiers); + if (status != null) { + return; + } + + // validate payload + String keyName = "payload"; +// if (payload == null) { +// status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); +// return; +// } + if (payload !=null) { + String payloadString = payload.getValue(); + status = validateMustHaveParamValue( + payloadString == null ? payloadString : payloadString.trim(), "payload"); + if (status != null) { + return; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + validateMustHaveParamValue(payloadMap.get(keyName), keyName); + } catch (IOException e) { + logger.error(String.format("PostMigrateService (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + } + + void proceedAction(CommonHeader commonHeader, + ActionIdentifiers actionIdentifiers, + Payload payload) { + RequestHandlerInput requestHandlerInput = + getRequestHandlerInput(commonHeader, actionIdentifiers, payload, this.getClass().getName()); + if (requestHandlerInput != null) { + executeAction(requestHandlerInput); + } + } +} + diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostRebuild.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostRebuild.java new file mode 100644 index 000000000..27a1e158e --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostRebuild.java @@ -0,0 +1,124 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PostRebuildInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PostRebuildOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PostRebuildOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+/**
+ * Provide LCM command service for PostRebuild VNF
+ */
+public class PostRebuild extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public PostRebuild() {
+ super(Action.PostRebuild);
+ logger.debug("PostRebuild starts");
+ }
+
+ /**
+ * Process the PostRebuild request
+ * @param input of PostRebuildInput from the REST API input
+ * @return PostRebuildOutputBuilder which has the process results
+ */
+ public PostRebuildOutputBuilder process(PostRebuildInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader,actionIdentifiers,payload);
+ }
+
+ PostRebuildOutputBuilder outputBuilder = new PostRebuildOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of PostRebuildInput from the REST API input
+ */
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("PostRebuild (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ /**
+ * Proceed to action for the PostRebuild VNF traffic.
+ *
+ * @param input of PostRebuildInput from the REST API input
+ */
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,
+ this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreConfigure.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreConfigure.java new file mode 100644 index 000000000..81be549dd --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreConfigure.java @@ -0,0 +1,124 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreConfigureInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreConfigureOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreConfigureOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+/**
+ * Provide LCM command service for PreConfigure VNF
+ */
+public class PreConfigure extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public PreConfigure() {
+ super(Action.PreConfigure);
+ logger.debug("PreConfigure starts");
+ }
+
+ /**
+ * Process the PreConfigure request
+ * @param input of PreConfigureInput from the REST API input
+ * @return PreConfigureOutputBuilder which has the process results
+ */
+ public PreConfigureOutputBuilder process(PreConfigureInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader,actionIdentifiers,payload);
+ }
+
+ PreConfigureOutputBuilder outputBuilder = new PreConfigureOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of PreConfigureInput from the REST API input
+ */
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("PreConfigure (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ /**
+ * Proceed to action for the PreConfigure VNF traffic.
+ *
+ * @param input of PreConfigureInput from the REST API input
+ */
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,
+ this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreEvacuate.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreEvacuate.java new file mode 100644 index 000000000..4a19e6be8 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreEvacuate.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.apache.commons.lang.StringUtils; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreEvacuateInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreEvacuateOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreEvacuateOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.util.JsonUtil; + +import java.io.IOException; +import java.util.Map; +/** + * Provide LCM command service for PreEvacuate VNF + */ +public class PreEvacuate extends AbstractBaseService { + + /** + * Constructor + */ + public PreEvacuate() { + super(Action.PreEvacuate); + logger.debug("PreEvacuate starts"); + } + + /** + * Constants for characterizing payload handling + */ + static final byte PAYLOAD_ACCEPT_NULL = 1; + static final byte PAYLOAD_AUTO_TRIM = 2; + static final byte PAYLOAD_TREAT_EMPTY_AS_NULL = 4; + + /** + * Payload handling configuration for all object instances + */ + static final byte payloadConfig = PAYLOAD_ACCEPT_NULL | PAYLOAD_AUTO_TRIM | PAYLOAD_TREAT_EMPTY_AS_NULL; + + /** + * Process the PreEvacuate request + * @param input of PreEvacuateInput from the REST API input + * @return PreEvacuateOutputBuilder which has the process results + */ + public PreEvacuateOutputBuilder process(PreEvacuateInput input) { + CommonHeader commonHeader = input.getCommonHeader(); + ActionIdentifiers actionIdentifiers = input.getActionIdentifiers(); + Payload payload = input.getPayload(); + + validate(commonHeader, input.getAction(), actionIdentifiers, payload); + if (status == null) { + if (payload != null) { + String payloadStr = payload.getValue(); + if (StringUtils.isEmpty(payloadStr)) { + if ((payloadConfig & PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + payload = null; + } + } else if ((payloadConfig & PAYLOAD_AUTO_TRIM) != 0) { + payloadStr = payloadStr.trim(); + if (StringUtils.isEmpty(payloadStr) && (payloadConfig & PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + payload = null; + } else { + payload = new Payload(payloadStr); + } + } + } + proceedAction(commonHeader, actionIdentifiers, payload); + } + + PreEvacuateOutputBuilder outputBuilder = new PreEvacuateOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(commonHeader); + return outputBuilder; + } + + /** + * Validate the input. + * Set Status if any error occurs. + * + * @param input of PreEvacuateInput from the REST API input + */ + void validate(CommonHeader commonHeader, + Action action, + ActionIdentifiers actionIdentifiers, + Payload payload) { + status = validateVnfId(commonHeader, action, actionIdentifiers); + if (status != null) { + return; + } + + // validate payload + String keyName = "payload"; + if (payload == null) { + if ((payloadConfig & PAYLOAD_ACCEPT_NULL) == 0) { + status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); + } + return; + } + String payloadString = payload.getValue(); + if (payloadString != null && (payloadConfig & PAYLOAD_AUTO_TRIM) != 0) { + payloadString = payloadString.trim(); + } + if ((payloadConfig & PAYLOAD_TREAT_EMPTY_AS_NULL) == 0) { + status = validateMustHaveParamValue(payloadString, "payload"); + if (status != null) { + return; + } + } else if (StringUtils.isEmpty(payloadString)) { + if ((payloadConfig & PAYLOAD_ACCEPT_NULL) == 0) { + status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); + } + return; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + // validateMustHaveParamValue(payloadMap.get(keyName), keyName); + } catch (IOException e) { + logger.error(String.format("PreEvacuate (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + + /** + * Proceed to action for the PreEvacuate VNF traffic. + * + * @param input of PreEvacuateInput from the REST API input + */ + void proceedAction(CommonHeader commonHeader, + ActionIdentifiers actionIdentifiers, + Payload payload) { + RequestHandlerInput requestHandlerInput = + getRequestHandlerInput(commonHeader, actionIdentifiers, payload, this.getClass().getName()); + if (requestHandlerInput != null) { + executeAction(requestHandlerInput); + } + } +} diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreMigrateService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreMigrateService.java new file mode 100644 index 000000000..661374a05 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreMigrateService.java @@ -0,0 +1,104 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreMigrateInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreMigrateOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.onap.appc.util.JsonUtil; +import java.io.IOException; +import java.util.Map; + +public class PreMigrateService extends AbstractBaseService { + + public PreMigrateService() { + super(Action.PreMigrate); + logger.debug("PreMigrateService starts"); + } + public PreMigrateOutputBuilder process(PreMigrateInput input) { + CommonHeader commonHeader = input.getCommonHeader(); + ActionIdentifiers actionIdentifiers = input.getActionIdentifiers(); + Payload payload = input.getPayload(); + + validate(commonHeader, input.getAction(), actionIdentifiers, payload); + if (status == null) { + proceedAction(commonHeader,actionIdentifiers,payload); + } + + PreMigrateOutputBuilder outputBuilder = new PreMigrateOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(input.getCommonHeader()); + return outputBuilder; + } + + + void validate(CommonHeader commonHeader, + Action action, + ActionIdentifiers actionIdentifiers, + Payload payload) { + status = validateVnfId(commonHeader, action, actionIdentifiers); + if (status != null) { + return; + } + + // validate payload + String keyName = "payload"; +// if (payload == null) { +// status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); +// return; +// } + if (payload !=null) { + String payloadString = payload.getValue(); + status = validateMustHaveParamValue( + payloadString == null ? payloadString : payloadString.trim(), "payload"); + if (status != null) { + return; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + validateMustHaveParamValue(payloadMap.get(keyName), keyName); + } catch (IOException e) { + logger.error(String.format("PreMigrateService (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + } + + void proceedAction(CommonHeader commonHeader, + ActionIdentifiers actionIdentifiers, + Payload payload) { + RequestHandlerInput requestHandlerInput = + getRequestHandlerInput(commonHeader, actionIdentifiers, payload, this.getClass().getName()); + if (requestHandlerInput != null) { + executeAction(requestHandlerInput); + } + } +} + diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreRebuild.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreRebuild.java new file mode 100644 index 000000000..cbcd61077 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreRebuild.java @@ -0,0 +1,124 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreRebuildInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreRebuildOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreRebuildOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+/**
+ * Provide LCM command service for PreRebuild VNF
+ */
+public class PreRebuild extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public PreRebuild() {
+ super(Action.PreRebuild);
+ logger.debug("PreRebuild starts");
+ }
+
+ /**
+ * Process the PreRebuild request
+ * @param input of PreRebuildInput from the REST API input
+ * @return PreRebuildOutputBuilder which has the process results
+ */
+ public PreRebuildOutputBuilder process(PreRebuildInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader,actionIdentifiers,payload);
+ }
+
+ PreRebuildOutputBuilder outputBuilder = new PreRebuildOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of PreRebuildInput from the REST API input
+ */
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("PreRebuild (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ /**
+ * Proceed to action for the PreRebuild VNF traffic.
+ *
+ * @param input of PreRebuildInput from the REST API input
+ */
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,
+ this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ProvisioningService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ProvisioningService.java new file mode 100644 index 000000000..f9fc8eb55 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ProvisioningService.java @@ -0,0 +1,122 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ProvisioningInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ProvisioningOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ProvisioningOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+/**
+ * Provide LCM command service for Provisioning VNF Service
+ */
+public class ProvisioningService extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public ProvisioningService() {
+ super(Action.Provisioning);
+ logger.debug("ProvisioningService starts");
+ }
+
+ /**
+ * Process the Provisioning request
+ * @param input of ProvisioningInput from the REST API input
+ * @return ProvisioningOutputBuilder which has the process results
+ */
+ public ProvisioningOutputBuilder process(ProvisioningInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader,actionIdentifiers,payload);
+ }
+
+ ProvisioningOutputBuilder outputBuilder = new ProvisioningOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of ProvisioningInput from the REST API input
+ */
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("ProvisioningService (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ /**
+ * Proceed to action for the Provisioning VNF action.
+ *
+ * @param input of ProvisioningInput from the REST API input
+ */
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,
+ this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
\ No newline at end of file diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StartTraffic.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StartTraffic.java new file mode 100644 index 000000000..9d9886cfc --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StartTraffic.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartTrafficInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartTrafficOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartTrafficOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.util.JsonUtil; + +import java.io.IOException; +import java.util.Map; +/** + * Provide LCM command service for StartTraffic VNF + */ +public class StartTraffic extends AbstractBaseService { + + /** + * Constructor + */ + public StartTraffic() { + super(Action.StartTraffic); + logger.debug("StartTraffic starts"); + } + + /** + * Process the StartTraffic request + * @param input of StartTrafficInput from the REST API input + * @return StartTrafficOutputBuilder which has the process results + */ + public StartTrafficOutputBuilder process(StartTrafficInput input) { + CommonHeader commonHeader = input.getCommonHeader(); + ActionIdentifiers actionIdentifiers = input.getActionIdentifiers(); + Payload payload = input.getPayload(); + + validate(commonHeader, input.getAction(), actionIdentifiers, payload); + if (status == null) { + proceedAction(commonHeader,actionIdentifiers,payload); + } + + StartTrafficOutputBuilder outputBuilder = new StartTrafficOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(input.getCommonHeader()); + return outputBuilder; + } + + /** + * Validate the input. + * Set Status if any error occurs. + * + * @param input of StartTrafficInput from the REST API input + */ + void validate(CommonHeader commonHeader, + Action action, + ActionIdentifiers actionIdentifiers, + Payload payload) { + status = validateVnfId(commonHeader, action, actionIdentifiers); + if (status != null) { + return; + } + + // validate payload + String keyName = "payload"; + if (payload == null) { + status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); + return; + } + String payloadString = payload.getValue(); + status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload"); + if (status != null) { + return; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + validateMustHaveParamValue(payloadMap.get(keyName), keyName); + } catch (IOException e) { + logger.error(String.format("StartTraffic (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + + /** + * Proceed to action for the StartTraffic VNF traffic. + * + * @param input of StartTrafficInput from the REST API input + */ + void proceedAction(CommonHeader commonHeader, + ActionIdentifiers actionIdentifiers, + Payload payload) { + RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload, + this.getClass().getName()); + if (requestHandlerInput != null) { + executeAction(requestHandlerInput); + } + } +}
\ No newline at end of file diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StatusTraffic.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StatusTraffic.java new file mode 100644 index 000000000..19898805e --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StatusTraffic.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StatusTrafficInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StatusTrafficOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StatusTrafficOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.util.JsonUtil; + +import java.io.IOException; +import java.util.Map; +/** + * Provide LCM command service for StatusTraffic VNF + */ +public class StatusTraffic extends AbstractBaseService { + + /** + * Constructor + */ + public StatusTraffic() { + super(Action.StatusTraffic); + logger.debug("StatusTraffic starts"); + } + + /** + * Process the StatusTraffic request + * @param input of StatusTrafficInput from the REST API input + * @return StatusTrafficOutputBuilder which has the process results + */ + public StatusTrafficOutputBuilder process(StatusTrafficInput input) { + CommonHeader commonHeader = input.getCommonHeader(); + ActionIdentifiers actionIdentifiers = input.getActionIdentifiers(); + Payload payload = input.getPayload(); + + validate(commonHeader, input.getAction(), actionIdentifiers, payload); + if (status == null) { + proceedAction(commonHeader,actionIdentifiers,payload); + } + + StatusTrafficOutputBuilder outputBuilder = new StatusTrafficOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(input.getCommonHeader()); + return outputBuilder; + } + + /** + * Validate the input. + * Set Status if any error occurs. + * + * @param input of StatusTrafficInput from the REST API input + */ + void validate(CommonHeader commonHeader, + Action action, + ActionIdentifiers actionIdentifiers, + Payload payload) { + status = validateVnfId(commonHeader, action, actionIdentifiers); + if (status != null) { + return; + } + + // validate payload + String keyName = "payload"; + if (payload == null) { + status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); + return; + } + String payloadString = payload.getValue(); + status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload"); + if (status != null) { + return; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + validateMustHaveParamValue(payloadMap.get(keyName), keyName); + } catch (IOException e) { + logger.error(String.format("StatusTraffic (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + + /** + * Proceed to action for the StatusTraffic VNF traffic. + * + * @param input of StatusTrafficInput from the REST API input + */ + void proceedAction(CommonHeader commonHeader, + ActionIdentifiers actionIdentifiers, + Payload payload) { + RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload, + this.getClass().getName()); + if (requestHandlerInput != null) { + executeAction(requestHandlerInput); + } + } +}
\ No newline at end of file diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StopTraffic.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StopTraffic.java new file mode 100644 index 000000000..f2c211e2d --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StopTraffic.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.apache.commons.lang.StringUtils; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopTrafficInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopTrafficOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopTrafficOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.util.JsonUtil; + +import java.io.IOException; +import java.util.Map; +/** + * Provide LCM command service for StopTraffic VNF + */ +public class StopTraffic extends AbstractBaseService { + + /** + * Constructor + */ + public StopTraffic() { + super(Action.StopTraffic); + logger.debug("StopTraffic starts"); + } + + /** + * Constants for characterizing payload handling + */ + static final byte PAYLOAD_ACCEPT_NULL = 1; + static final byte PAYLOAD_AUTO_TRIM = 2; + static final byte PAYLOAD_TREAT_EMPTY_AS_NULL = 4; + + /** + * Payload handling configuration for all object instances + */ + static final byte payloadConfig = PAYLOAD_ACCEPT_NULL | PAYLOAD_AUTO_TRIM | PAYLOAD_TREAT_EMPTY_AS_NULL; + + /** + * Process the StopTraffic request + * @param input of StopTrafficInput from the REST API input + * @return StopTrafficOutputBuilder which has the process results + */ + public StopTrafficOutputBuilder process(StopTrafficInput input) { + CommonHeader commonHeader = input.getCommonHeader(); + ActionIdentifiers actionIdentifiers = input.getActionIdentifiers(); + Payload payload = input.getPayload(); + + validate(commonHeader, input.getAction(), actionIdentifiers, payload); + if (status == null) { + if (payload != null) { + String payloadStr = payload.getValue(); + if (StringUtils.isEmpty(payloadStr)) { + if ((payloadConfig & PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + payload = null; + } + } else if ((payloadConfig & PAYLOAD_AUTO_TRIM) != 0) { + payloadStr = payloadStr.trim(); + if (StringUtils.isEmpty(payloadStr) && (payloadConfig & PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + payload = null; + } else { + payload = new Payload(payloadStr); + } + } + } + proceedAction(commonHeader, actionIdentifiers, payload); + } + + StopTrafficOutputBuilder outputBuilder = new StopTrafficOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(commonHeader); + return outputBuilder; + } + + /** + * Validate the input. + * Set Status if any error occurs. + * + * @param input of StopTrafficInput from the REST API input + */ + void validate(CommonHeader commonHeader, + Action action, + ActionIdentifiers actionIdentifiers, + Payload payload) { + status = validateVnfId(commonHeader, action, actionIdentifiers); + if (status != null) { + return; + } + + // validate payload + String keyName = "payload"; + if (payload == null) { + if ((payloadConfig & PAYLOAD_ACCEPT_NULL) == 0) { + status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); + } + return; + } + String payloadString = payload.getValue(); + if (payloadString != null && (payloadConfig & PAYLOAD_AUTO_TRIM) != 0) { + payloadString = payloadString.trim(); + } + if ((payloadConfig & PAYLOAD_TREAT_EMPTY_AS_NULL) == 0) { + status = validateMustHaveParamValue(payloadString, "payload"); + if (status != null) { + return; + } + } else if (StringUtils.isEmpty(payloadString)) { + if ((payloadConfig & PAYLOAD_ACCEPT_NULL) == 0) { + status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); + } + return; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + // validateMustHaveParamValue(payloadMap.get(keyName), keyName); + } catch (IOException e) { + logger.error(String.format("StopTraffic (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + + /** + * Proceed to action for the StopTraffic VNF traffic. + * + * @param input of StopTrafficInput from the REST API input + */ + void proceedAction(CommonHeader commonHeader, + ActionIdentifiers actionIdentifiers, + Payload payload) { + RequestHandlerInput requestHandlerInput = + getRequestHandlerInput(commonHeader, actionIdentifiers, payload, this.getClass().getName()); + if (requestHandlerInput != null) { + executeAction(requestHandlerInput); + } + } +} diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/GetConfigServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/GetConfigServiceTest.java new file mode 100644 index 000000000..b258b7609 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/GetConfigServiceTest.java @@ -0,0 +1,167 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+
+@RunWith(MockitoJUnitRunner.class)
+public class GetConfigServiceTest {
+ private final Action myAction = Action.GetConfig;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private GetConfigInput mockInput = mock(GetConfigInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private GetConfigService getConfigureAction;
+ @Before
+ public void setUp() throws Exception {
+ getConfigureAction = spy(new GetConfigService());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ GetConfigOutputBuilder outputBuilder = getConfigureAction.process(mockInput);
+ Mockito.verify(getConfigureAction, times(0)).proceedAction(any(),any(),any());
+ Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return missing parameter status",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ outputBuilder.getStatus().getCode());
+
+ // make validation pass
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+ Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+ // to make validation pass
+ ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+ Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+
+ // test processAction return without error
+ RequestExecutor mockExecutor = mock(RequestExecutor.class);
+ // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+
+ ResponseContext mockResponseContext = mock(ResponseContext.class);
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+
+ org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+ Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+ Mockito.doReturn(successCode).when(mockStatus).getCode();
+ Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+ RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class);
+ AbstractBaseService abstractBaseService = mock(AbstractBaseService.class);
+ Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput);
+ try {
+ outputBuilder = getConfigureAction.process(mockInput);
+ }catch(Exception e){
+ Assert.assertTrue(true);
+ }
+ Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(getConfigureAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(getConfigureAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty action
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test Invalid VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test null payload
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI, null);
+ Mockito.verify(getConfigureAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
+
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/LicenseManagementServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/LicenseManagementServiceTest.java new file mode 100644 index 000000000..a7cc37193 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/LicenseManagementServiceTest.java @@ -0,0 +1,166 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+
+@RunWith(MockitoJUnitRunner.class)
+public class LicenseManagementServiceTest {
+ private final Action myAction = Action.LicenseManagement;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private LicenseManagementInput mockInput = mock(LicenseManagementInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private LicenseManagementService licenseManagementAction;
+ @Before
+ public void setUp() throws Exception {
+ licenseManagementAction = spy(new LicenseManagementService());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ LicenseManagementOutputBuilder outputBuilder = licenseManagementAction.process(mockInput);
+ Mockito.verify(licenseManagementAction, times(0)).proceedAction(any(),any(),any());
+ Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return missing parameter status",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ outputBuilder.getStatus().getCode());
+
+ // make validation pass
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+ Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+ // to make validation pass
+ ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+ Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+
+ // test processAction return without error
+ RequestExecutor mockExecutor = mock(RequestExecutor.class);
+ // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+
+ ResponseContext mockResponseContext = mock(ResponseContext.class);
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+
+ org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+ Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+ Mockito.doReturn(successCode).when(mockStatus).getCode();
+ Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+ RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class);
+ AbstractBaseService abstractBaseService = mock(AbstractBaseService.class);
+ Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput);
+ try {
+ outputBuilder = licenseManagementAction.process(mockInput);
+ }catch(Exception e){
+ Assert.assertTrue(true);
+ }
+ Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(licenseManagementAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(licenseManagementAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty action
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test Invalid VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test null payload
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI, null);
+ Mockito.verify(licenseManagementAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
\ No newline at end of file diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostEvacuateServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostEvacuateServiceTest.java new file mode 100644 index 000000000..7f229ebfa --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostEvacuateServiceTest.java @@ -0,0 +1,168 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerOutput; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; + +@RunWith(MockitoJUnitRunner.class) +public class PostEvacuateServiceTest { + private final Action myAction = Action.PostEvacuate; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private PostEvacuateInput mockInput = mock(PostEvacuateInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private PostEvacuateService postevacuateServiceAction; + @Before + public void setUp() throws Exception { + postevacuateServiceAction = spy(new PostEvacuateService()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + PostEvacuateOutputBuilder outputBuilder = postevacuateServiceAction.process(mockInput); + Mockito.verify(postevacuateServiceAction, times(0)).proceedAction(any(),any(),any()); + Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return missing parameter status", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + outputBuilder.getStatus().getCode()); + + // make validation pass + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + // to make validation pass + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + Mockito.doReturn(myAction).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test processAction return without error + RequestExecutor mockExecutor = mock(RequestExecutor.class); + // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor); + + RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class); + Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any()); + + ResponseContext mockResponseContext = mock(ResponseContext.class); + Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext(); + + org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class); + Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode()); + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class); + AbstractBaseService abstractBaseService = mock(AbstractBaseService.class); + Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput); + try { + outputBuilder = postevacuateServiceAction.process(mockInput); + }catch(Exception e){ + Assert.assertTrue(true); + } + Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(postevacuateServiceAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(postevacuateServiceAction, times(0)).buildStatusForErrorMsg(any(), any()); + + ZULU mockTimeStamp = mock(ZULU.class); + Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test Invalid VNF_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + + // test null payload + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI, null); + Mockito.verify(postevacuateServiceAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} + diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostMigrateServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostMigrateServiceTest.java new file mode 100644 index 000000000..5752a3088 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostMigrateServiceTest.java @@ -0,0 +1,168 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerOutput; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; + +@RunWith(MockitoJUnitRunner.class) +public class PostMigrateServiceTest { + private final Action myAction = Action.PostMigrate; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private PostMigrateInput mockInput = mock(PostMigrateInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private PostMigrateService postmigrateServiceAction; + @Before + public void setUp() throws Exception { + postmigrateServiceAction = spy(new PostMigrateService()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + PostMigrateOutputBuilder outputBuilder = postmigrateServiceAction.process(mockInput); + Mockito.verify(postmigrateServiceAction, times(0)).proceedAction(any(),any(),any()); + Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return missing parameter status", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + outputBuilder.getStatus().getCode()); + + // make validation pass + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + // to make validation pass + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + Mockito.doReturn(myAction).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test processAction return without error + RequestExecutor mockExecutor = mock(RequestExecutor.class); + // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor); + + RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class); + Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any()); + + ResponseContext mockResponseContext = mock(ResponseContext.class); + Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext(); + + org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class); + Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode()); + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class); + AbstractBaseService abstractBaseService = mock(AbstractBaseService.class); + Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput); + try { + outputBuilder = postmigrateServiceAction.process(mockInput); + }catch(Exception e){ + Assert.assertTrue(true); + } + Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(postmigrateServiceAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(postmigrateServiceAction, times(0)).buildStatusForErrorMsg(any(), any()); + + ZULU mockTimeStamp = mock(ZULU.class); + Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test Invalid VNF_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + + // test null payload + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI, null); + Mockito.verify(postmigrateServiceAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} + diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostRebuildTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostRebuildTest.java new file mode 100644 index 000000000..693cba823 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostRebuildTest.java @@ -0,0 +1,167 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PostRebuildTest {
+ private final Action myAction = Action.PostRebuild;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private PostRebuildInput mockInput = mock(PostRebuildInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private PostRebuild postRebuildAction;
+ @Before
+ public void setUp() throws Exception {
+ postRebuildAction = spy(new PostRebuild());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ PostRebuildOutputBuilder outputBuilder = postRebuildAction.process(mockInput);
+ Mockito.verify(postRebuildAction, times(0)).proceedAction(any(),any(),any());
+ Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return missing parameter status",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ outputBuilder.getStatus().getCode());
+
+ // make validation pass
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+ Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+ // to make validation pass
+ ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+ Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+
+ // test processAction return without error
+ RequestExecutor mockExecutor = mock(RequestExecutor.class);
+ // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+
+ ResponseContext mockResponseContext = mock(ResponseContext.class);
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+
+ org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+ Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+ Mockito.doReturn(successCode).when(mockStatus).getCode();
+ Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+ RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class);
+ AbstractBaseService abstractBaseService = mock(AbstractBaseService.class);
+ Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput);
+ try {
+ outputBuilder = postRebuildAction.process(mockInput);
+ }catch(Exception e){
+ Assert.assertTrue(true);
+ }
+ Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(postRebuildAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(postRebuildAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty action
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test Invalid VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test null payload
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI, null);
+ Mockito.verify(postRebuildAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
+
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreConfigureTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreConfigureTest.java new file mode 100644 index 000000000..e5fb6741e --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreConfigureTest.java @@ -0,0 +1,167 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PreConfigureTest {
+ private final Action myAction = Action.PreConfigure;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private PreConfigureInput mockInput = mock(PreConfigureInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private PreConfigure preConfigureAction;
+ @Before
+ public void setUp() throws Exception {
+ preConfigureAction = spy(new PreConfigure());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ PreConfigureOutputBuilder outputBuilder = preConfigureAction.process(mockInput);
+ Mockito.verify(preConfigureAction, times(0)).proceedAction(any(),any(),any());
+ Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return missing parameter status",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ outputBuilder.getStatus().getCode());
+
+ // make validation pass
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+ Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+ // to make validation pass
+ ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+ Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+
+ // test processAction return without error
+ RequestExecutor mockExecutor = mock(RequestExecutor.class);
+ // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+
+ ResponseContext mockResponseContext = mock(ResponseContext.class);
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+
+ org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+ Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+ Mockito.doReturn(successCode).when(mockStatus).getCode();
+ Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+ RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class);
+ AbstractBaseService abstractBaseService = mock(AbstractBaseService.class);
+ Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput);
+ try {
+ outputBuilder = preConfigureAction.process(mockInput);
+ }catch(Exception e){
+ Assert.assertTrue(true);
+ }
+ Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(preConfigureAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(preConfigureAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty action
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test Invalid VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test null payload
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI, null);
+ Mockito.verify(preConfigureAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
+
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreEvacuateTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreEvacuateTest.java new file mode 100644 index 000000000..e023745b4 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreEvacuateTest.java @@ -0,0 +1,208 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerOutput; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({PreEvacuate.class, RequestExecutor.class}) +public class PreEvacuateTest { + private final Action myAction = Action.PreEvacuate; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private PreEvacuateInput mockInput = mock(PreEvacuateInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private PreEvacuate preEvacuateAction; + + @Before + public void setUp() throws Exception { + preEvacuateAction = spy(new PreEvacuate()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + PreEvacuateOutputBuilder outputBuilder = preEvacuateAction.process(mockInput); + Mockito.verify(preEvacuateAction, times(0)).proceedAction(any(), any(), any()); + Assert.assertTrue("Should not have commonHeader as we did not mock it", + outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return missing parameter status", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + outputBuilder.getStatus().getCode()); + + // make validation pass + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + // to make validation pass + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("2.34").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("originator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + Mockito.doReturn(myAction).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test processAction return without error + RequestExecutor mockExecutor = mock(RequestExecutor.class); + whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor); + + RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class); + Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any()); + + ResponseContext mockResponseContext = mock(ResponseContext.class); + Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext(); + org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class); + Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode()); + String successMsg = "Simulated SUCCESS"; + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(successMsg).when(mockStatus).getMessage(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + + try { + outputBuilder = preEvacuateAction.process(mockInput); + } catch(Exception e) { + Assert.assertTrue("Encountered Exception " + e.toString() + " processing action", false); + } + Assert.assertTrue("Should have commonHeader", + outputBuilder != null && outputBuilder.getCommonHeader() != null); + Assert.assertEquals("should return success status", successCode, outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + Status status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(preEvacuateAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(preEvacuateAction, times(0)).buildStatusForErrorMsg(any(), any()); + + Mockito.doReturn("mocked AI").when(mockAI).toString(); + Mockito.doReturn("mocked CommonHeader").when(mockCommonHeader).toString(); + Mockito.doReturn("mocked Input").when(mockInput).toString(); + Mockito.doReturn("mocked Payload").when(mockPayload).toString(); + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("2.34").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("originator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + + // test empty ActionIdentifier + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + + // test Invalid VNF_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + + // test null payload + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, null); + Mockito.verify(preEvacuateAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_ACCEPT_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept null Payload", status == null); + } else { + Assert.assertEquals("Configuration indicates should reject null Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } + + // test empty payload + Mockito.doReturn("").when(mockPayload).getValue(); + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_ACCEPT_NULL) != 0 + && (PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept empty Payload", status == null); + } else if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertEquals("Configuration indicates should reject empty Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } else { + Assert.assertEquals("Configuration indicates should reject empty Payload", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + } + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_ACCEPT_NULL) != 0 + && (PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_AUTO_TRIM) != 0 + && (PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept blank Payload", status == null); + } else if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_AUTO_TRIM) != 0 + && (PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertEquals("Configuration indicates should reject blank Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } else { + Assert.assertEquals("Configuration indicates should reject blank Payload", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + } + } +} diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreMigrateServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreMigrateServiceTest.java new file mode 100644 index 000000000..c9e944acf --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreMigrateServiceTest.java @@ -0,0 +1,168 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerOutput; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; + +@RunWith(MockitoJUnitRunner.class) +public class PreMigrateServiceTest { + private final Action myAction = Action.PreMigrate; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private PreMigrateInput mockInput = mock(PreMigrateInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private PreMigrateService premigrateServiceAction; + @Before + public void setUp() throws Exception { + premigrateServiceAction = spy(new PreMigrateService()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + PreMigrateOutputBuilder outputBuilder = premigrateServiceAction.process(mockInput); + Mockito.verify(premigrateServiceAction, times(0)).proceedAction(any(),any(),any()); + Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return missing parameter status", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + outputBuilder.getStatus().getCode()); + + // make validation pass + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + // to make validation pass + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + Mockito.doReturn(myAction).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test processAction return without error + RequestExecutor mockExecutor = mock(RequestExecutor.class); + // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor); + + RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class); + Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any()); + + ResponseContext mockResponseContext = mock(ResponseContext.class); + Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext(); + + org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class); + Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode()); + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class); + AbstractBaseService abstractBaseService = mock(AbstractBaseService.class); + Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput); + try { + outputBuilder = premigrateServiceAction.process(mockInput); + }catch(Exception e){ + Assert.assertTrue(true); + } + Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(premigrateServiceAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(premigrateServiceAction, times(0)).buildStatusForErrorMsg(any(), any()); + + ZULU mockTimeStamp = mock(ZULU.class); + Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test Invalid VNF_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + + // test null payload + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI, null); + Mockito.verify(premigrateServiceAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} + diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreRebuildTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreRebuildTest.java new file mode 100644 index 000000000..7ffbeecc1 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreRebuildTest.java @@ -0,0 +1,167 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PreRebuildTest {
+ private final Action myAction = Action.PreRebuild;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private PreRebuildInput mockInput = mock(PreRebuildInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private PreRebuild preRebuildAction;
+ @Before
+ public void setUp() throws Exception {
+ preRebuildAction = spy(new PreRebuild());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ PreRebuildOutputBuilder outputBuilder = preRebuildAction.process(mockInput);
+ Mockito.verify(preRebuildAction, times(0)).proceedAction(any(),any(),any());
+ Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return missing parameter status",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ outputBuilder.getStatus().getCode());
+
+ // make validation pass
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+ Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+ // to make validation pass
+ ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+ Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+
+ // test processAction return without error
+ RequestExecutor mockExecutor = mock(RequestExecutor.class);
+ // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+
+ ResponseContext mockResponseContext = mock(ResponseContext.class);
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+
+ org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+ Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+ Mockito.doReturn(successCode).when(mockStatus).getCode();
+ Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+ RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class);
+ AbstractBaseService abstractBaseService = mock(AbstractBaseService.class);
+ Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput);
+ try {
+ outputBuilder = preRebuildAction.process(mockInput);
+ }catch(Exception e){
+ Assert.assertTrue(true);
+ }
+ Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(preRebuildAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(preRebuildAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty action
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test Invalid VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test null payload
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI, null);
+ Mockito.verify(preRebuildAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
+
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ProvisioningServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ProvisioningServiceTest.java new file mode 100644 index 000000000..ef94e18fa --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ProvisioningServiceTest.java @@ -0,0 +1,166 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ProvisioningServiceTest {
+ private final Action myAction = Action.Provisioning;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private ProvisioningInput mockInput = mock(ProvisioningInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private ProvisioningService provisioningAction;
+ @Before
+ public void setUp() throws Exception {
+ provisioningAction = spy(new ProvisioningService());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ ProvisioningOutputBuilder outputBuilder = provisioningAction.process(mockInput);
+ Mockito.verify(provisioningAction, times(0)).proceedAction(any(),any(),any());
+ Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return missing parameter status",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ outputBuilder.getStatus().getCode());
+
+ // make validation pass
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+ Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+ // to make validation pass
+ ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+ Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+
+ // test processAction return without error
+ RequestExecutor mockExecutor = mock(RequestExecutor.class);
+ // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+
+ ResponseContext mockResponseContext = mock(ResponseContext.class);
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+
+ org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+ Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+ Mockito.doReturn(successCode).when(mockStatus).getCode();
+ Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+ RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class);
+ AbstractBaseService abstractBaseService = mock(AbstractBaseService.class);
+ Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput);
+ try {
+ outputBuilder = provisioningAction.process(mockInput);
+ }catch(Exception e){
+ Assert.assertTrue(true);
+ }
+ Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null);
+ Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(provisioningAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(provisioningAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty action
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test Invalid VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test null payload
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI, null);
+ Mockito.verify(provisioningAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StartTrafficTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StartTrafficTest.java new file mode 100644 index 000000000..83919bde5 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StartTrafficTest.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerOutput; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; + +@RunWith(MockitoJUnitRunner.class) +public class StartTrafficTest { + private final Action myAction = Action.StartTraffic; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private StartTrafficInput mockInput = mock(StartTrafficInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private StartTraffic startTrafficAction; + @Before + public void setUp() throws Exception { + startTrafficAction = spy(new StartTraffic()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + StartTrafficOutputBuilder outputBuilder = startTrafficAction.process(mockInput); + Mockito.verify(startTrafficAction, times(0)).proceedAction(any(),any(),any()); + Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return missing parameter status", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + outputBuilder.getStatus().getCode()); + + // make validation pass + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + // to make validation pass + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + Mockito.doReturn(myAction).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test processAction return without error + RequestExecutor mockExecutor = mock(RequestExecutor.class); + // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor); + + RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class); + Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any()); + + ResponseContext mockResponseContext = mock(ResponseContext.class); + Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext(); + + org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class); + Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode()); + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class); + AbstractBaseService abstractBaseService = mock(AbstractBaseService.class); + Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput); + try { + outputBuilder = startTrafficAction.process(mockInput); + }catch(Exception e){ + Assert.assertTrue(true); + } + Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(startTrafficAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(startTrafficAction, times(0)).buildStatusForErrorMsg(any(), any()); + + ZULU mockTimeStamp = mock(ZULU.class); + Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test Invalid VNF_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + + // test null payload + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI, null); + Mockito.verify(startTrafficAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StatusTrafficTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StatusTrafficTest.java new file mode 100644 index 000000000..c84a81292 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StatusTrafficTest.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerOutput; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; + +@RunWith(MockitoJUnitRunner.class) +public class StatusTrafficTest { + private final Action myAction = Action.StatusTraffic; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private StatusTrafficInput mockInput = mock(StatusTrafficInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private StatusTraffic statusTrafficAction; + @Before + public void setUp() throws Exception { + statusTrafficAction = spy(new StatusTraffic()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + StatusTrafficOutputBuilder outputBuilder = statusTrafficAction.process(mockInput); + Mockito.verify(statusTrafficAction, times(0)).proceedAction(any(),any(),any()); + Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return missing parameter status", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + outputBuilder.getStatus().getCode()); + + // make validation pass + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + // to make validation pass + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + Mockito.doReturn(myAction).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test processAction return without error + RequestExecutor mockExecutor = mock(RequestExecutor.class); + // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor); + + RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class); + Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any()); + + ResponseContext mockResponseContext = mock(ResponseContext.class); + Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext(); + + org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class); + Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode()); + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class); + AbstractBaseService abstractBaseService = mock(AbstractBaseService.class); + Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput); + try { + outputBuilder = statusTrafficAction.process(mockInput); + }catch(Exception e){ + Assert.assertTrue(true); + } + Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(statusTrafficAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(statusTrafficAction, times(0)).buildStatusForErrorMsg(any(), any()); + + ZULU mockTimeStamp = mock(ZULU.class); + Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test Invalid VNF_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + + // test null payload + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI, null); + Mockito.verify(statusTrafficAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StopTrafficTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StopTrafficTest.java new file mode 100644 index 000000000..c7d627914 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StopTrafficTest.java @@ -0,0 +1,208 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerOutput; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({StopTraffic.class, RequestExecutor.class}) +public class StopTrafficTest { + private final Action myAction = Action.StopTraffic; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private StopTrafficInput mockInput = mock(StopTrafficInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private StopTraffic stopTrafficAction; + + @Before + public void setUp() throws Exception { + stopTrafficAction = spy(new StopTraffic()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + StopTrafficOutputBuilder outputBuilder = stopTrafficAction.process(mockInput); + Mockito.verify(stopTrafficAction, times(0)).proceedAction(any(), any(), any()); + Assert.assertTrue("Should not have commonHeader as we did not mock it", + outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return missing parameter status", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + outputBuilder.getStatus().getCode()); + + // make validation pass + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + // to make validation pass + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("2.34").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("originator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + Mockito.doReturn(myAction).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test processAction return without error + RequestExecutor mockExecutor = mock(RequestExecutor.class); + whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor); + + RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class); + Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any()); + + ResponseContext mockResponseContext = mock(ResponseContext.class); + Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext(); + org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class); + Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode()); + String successMsg = "Simulated SUCCESS"; + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(successMsg).when(mockStatus).getMessage(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + + try { + outputBuilder = stopTrafficAction.process(mockInput); + } catch(Exception e) { + Assert.assertTrue("Encountered Exception " + e.toString() + " processing action", false); + } + Assert.assertTrue("Should have commonHeader", + outputBuilder != null && outputBuilder.getCommonHeader() != null); + Assert.assertEquals("should return success status", successCode, outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + Status status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(stopTrafficAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(stopTrafficAction, times(0)).buildStatusForErrorMsg(any(), any()); + + Mockito.doReturn("mocked AI").when(mockAI).toString(); + Mockito.doReturn("mocked CommonHeader").when(mockCommonHeader).toString(); + Mockito.doReturn("mocked Input").when(mockInput).toString(); + Mockito.doReturn("mocked Payload").when(mockPayload).toString(); + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("2.34").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("originator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + + // test empty ActionIdentifier + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + + // test Invalid VNF_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + + // test null payload + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, null); + Mockito.verify(stopTrafficAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_ACCEPT_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept null Payload", status == null); + } else { + Assert.assertEquals("Configuration indicates should reject null Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } + + // test empty payload + Mockito.doReturn("").when(mockPayload).getValue(); + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_ACCEPT_NULL) != 0 + && (StopTraffic.payloadConfig & StopTraffic.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept empty Payload", status == null); + } else if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertEquals("Configuration indicates should reject empty Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } else { + Assert.assertEquals("Configuration indicates should reject empty Payload", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + } + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_ACCEPT_NULL) != 0 + && (StopTraffic.payloadConfig & StopTraffic.PAYLOAD_AUTO_TRIM) != 0 + && (StopTraffic.payloadConfig & StopTraffic.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept blank Payload", status == null); + } else if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_AUTO_TRIM) != 0 + && (StopTraffic.payloadConfig & StopTraffic.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertEquals("Configuration indicates should reject blank Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } else { + Assert.assertEquals("Configuration indicates should reject blank Payload", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + } + } +} diff --git a/appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang b/appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang index 2b8521a61..c060582fa 100644 --- a/appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang +++ b/appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang @@ -73,7 +73,7 @@ module appc-provider-lcm { string) as follows yyyy-MM-ddTHH:mm:ss.SSSSSSSSZ"; type string { length "16..28"; - pattern "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}T[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}.[0-9]{1,6}Z"; + pattern "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}T[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}[.][0-9]{1,6}Z"; } } @@ -97,6 +97,7 @@ module appc-provider-lcm { enum "Terminate"; enum "SoftwareUpload"; enum "HealthCheck"; + enum "LicenseManagement"; enum "LiveUpgrade"; enum "Lock"; enum "Unlock"; @@ -123,8 +124,20 @@ module appc-provider-lcm { enum "Reboot"; enum "AttachVolume"; enum "DetachVolume"; + enum "PreConfigure"; + enum "GetConfig"; enum "DistributeTraffic"; enum "DistributeTrafficCheck"; + enum "PostRebuild"; + enum "PreRebuild"; + enum "PreEvacuate"; + enum "PostEvacuate"; + enum "PreMigrate"; + enum "PostMigrate"; + enum "Provisioning"; + enum "StartTraffic"; + enum "StatusTraffic"; + enum "StopTraffic"; } description "The action to be taken by APP-C, e.g. Restart, Rebuild, Migrate"; } @@ -492,6 +505,10 @@ module appc-provider-lcm { output { uses common-header; uses status; + leaf payload { + type payload; + mandatory false; + } } } @@ -516,6 +533,10 @@ module appc-provider-lcm { output { uses common-header; uses status; + leaf payload { + type payload; + mandatory false; + } } } @@ -566,6 +587,10 @@ module appc-provider-lcm { output { uses common-header; uses status; + leaf payload { + type payload; + mandatory false; + } } } @@ -616,6 +641,10 @@ module appc-provider-lcm { output { uses common-header; uses status; + leaf payload { + type payload; + mandatory false; + } } } @@ -639,6 +668,10 @@ module appc-provider-lcm { output { uses common-header; uses status; + leaf payload { + type payload; + mandatory false; + } } } @@ -797,7 +830,7 @@ module appc-provider-lcm { uses action-identifiers; leaf payload { type payload; - mandatory true; + mandatory false; } } output { @@ -973,9 +1006,8 @@ module appc-provider-lcm { uses status; leaf payload { type payload; - mandatory true; - } - + mandatory false; + } } } @@ -1157,6 +1189,10 @@ module appc-provider-lcm { output { uses common-header; uses status; + leaf payload { + type payload; + mandatory false; + } } } @@ -1180,6 +1216,10 @@ module appc-provider-lcm { output { uses common-header; uses status; + leaf payload { + type payload; + mandatory false; + } } } @@ -1318,6 +1358,60 @@ module appc-provider-lcm { } /********************************************************************************** + * Define the PreConfigure service + **********************************************************************************/ + rpc pre-configure { + description "An operation to retrieve the current config"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory true; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the VNF GetConfig service + **********************************************************************************/ + rpc get-config { + description "An operation to retrieve the current running config"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory true; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** * Define the traffic distribution service **********************************************************************************/ rpc distribute-traffic { @@ -1363,8 +1457,304 @@ module appc-provider-lcm { } } + /********************************************************************************** + * Define the PreRebuild service + **********************************************************************************/ + rpc pre-rebuild { + description "An operation to perform prerequisite steps before a rebuild action"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory true; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the PostRebuild service + **********************************************************************************/ + rpc post-rebuild { + description "An operation to perform subsequent steps after a rebuild action"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory true; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the PreEvacuate service + **********************************************************************************/ + rpc pre-evacuate { + description "An operation to perform prerequisite steps before an evacuate action"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory false; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } - /********************************************************************************** + /********************************************************************************** + * Define the PostEvacuate service + **********************************************************************************/ + rpc post-evacuate { + description "An operation to perform postevacuate on specified Ansible virtual machine (VM)"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory false; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the PreMigrate service + **********************************************************************************/ + rpc pre-migrate { + description "An operation to perform premigrate on specified Ansible virtual machine (VM)"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory false; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the PostMigrate service + **********************************************************************************/ + rpc post-migrate { + description "An operation to perform postmigrate on specified Ansible virtual machine (VM)"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory false; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the StartTraffic service + **********************************************************************************/ + rpc start-traffic { + description "An operation to start a traffic action on specified Ansible virtual machine (VM)"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory false; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the StatusTraffic service + **********************************************************************************/ + rpc status-traffic { + description "An operation to perform status-traffic on specified Ansible virtual machine (VM)"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory false; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the StopTraffic service + **********************************************************************************/ + rpc stop-traffic { + description "An operation to stop an in-process traffic action"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory false; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the VNF provisioning service + **********************************************************************************/ + rpc provisioning { + description "An vnf operation for provisioning"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory true; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** + * Define the VNF LicenseManagement service + **********************************************************************************/ + rpc license-management { + description "An vnf operation for provisioning"; + input { + uses common-header; + leaf action { + type action; + mandatory true; + } + uses action-identifiers; + leaf payload { + type payload; + mandatory true; + } + } + output { + uses common-header; + uses status; + leaf payload { + type payload; + mandatory false; + } + } + } + + /********************************************************************************** * Additional RPCs added here... - **********************************************************************************/ + **********************************************************************************/ } |