summaryrefslogtreecommitdiffstats
path: root/appc-provider/appc-provider-bundle
diff options
context:
space:
mode:
Diffstat (limited to 'appc-provider/appc-provider-bundle')
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java127
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/GetConfigService.java124
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/LicenseManagementService.java122
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostEvacuateService.java100
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostMigrateService.java104
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PostRebuild.java124
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreConfigure.java124
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreEvacuate.java162
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreMigrateService.java104
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/PreRebuild.java124
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ProvisioningService.java122
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StartTraffic.java122
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StatusTraffic.java122
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/StopTraffic.java162
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/GetConfigServiceTest.java167
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/LicenseManagementServiceTest.java166
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostEvacuateServiceTest.java168
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostMigrateServiceTest.java168
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostRebuildTest.java167
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreConfigureTest.java167
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreEvacuateTest.java208
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreMigrateServiceTest.java168
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreRebuildTest.java167
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ProvisioningServiceTest.java166
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StartTrafficTest.java166
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StatusTrafficTest.java166
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StopTrafficTest.java208
27 files changed, 3995 insertions, 0 deletions
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());
+ }
+ }
+}