From 86755a65c526dfd8c8bab1235ddf273b7eb64c1f Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Thu, 28 Feb 2019 08:10:55 +0000 Subject: Test coverage in MockQueryHelper Increased coverage from 17% to 91% Fixed Sonar major issue for branch coverage Issue-ID: APPC-1509 Change-Id: I822053c74db8f16875448206a22048032d30ad45 Signed-off-by: Joss Armstrong --- .../provider/lcm/mock/query/MockQueryHelper.java | 4 +- .../lcm/mock/query/MockQueryHelperTest.java | 61 +++++++++++++++++++ .../appc-provider-bundle/src/test/resources/query | 70 ++++++++++++++++++++++ 3 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelperTest.java create mode 100644 appc-provider/appc-provider-bundle/src/test/resources/query (limited to 'appc-provider') diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelper.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelper.java index 8276c690c..39d962f63 100644 --- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelper.java +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelper.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +52,7 @@ import java.util.Map; * When backend is implemented, this file should be removed. */ public class MockQueryHelper extends AbstractMockHelper { - private final String MOCK_QUERY_FILENAME = "/tmp/lcm/query"; + private String MOCK_QUERY_FILENAME = "/tmp/lcm/query"; /** VF_STATE value are listed at https://wiki.openstack.org/wiki/VMState#vm_state */ private final Map> VF_STATE_MAP = new HashMap>() { diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelperTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelperTest.java new file mode 100644 index 000000000..17bde75af --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelperTest.java @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.mock.query; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.onap.appc.domainmodel.lcm.ActionIdentifiers; +import org.onap.appc.domainmodel.lcm.RequestContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; +import org.powermock.reflect.Whitebox; + +public class MockQueryHelperTest { + + @Test + public void testVnfIdFound() { + MockQueryHelper mockQueryHelper = new MockQueryHelper(); + Whitebox.setInternalState(mockQueryHelper, "MOCK_QUERY_FILENAME", "./src/test/resources/query"); + RequestHandlerInput requestHandlerInput = new RequestHandlerInput(); + RequestContext requestContext = new RequestContext(); + ActionIdentifiers actionIdentifiers = new ActionIdentifiers(); + actionIdentifiers.setVnfId("vSCP"); + requestContext.setActionIdentifiers(actionIdentifiers); + requestHandlerInput.setRequestContext(requestContext); + assertEquals(LCMCommandStatus.SUCCESS.getResponseCode(), + mockQueryHelper.query(requestHandlerInput).getResponseContext().getStatus().getCode()); + } + + @Test + public void testVnfIdNotFound() { + MockQueryHelper mockQueryHelper = new MockQueryHelper(); + Whitebox.setInternalState(mockQueryHelper, "MOCK_QUERY_FILENAME", "./src/test/resources/query"); + RequestHandlerInput requestHandlerInput = new RequestHandlerInput(); + RequestContext requestContext = new RequestContext(); + ActionIdentifiers actionIdentifiers = new ActionIdentifiers(); + actionIdentifiers.setVnfId("OTHER_VNF_ID"); + requestContext.setActionIdentifiers(actionIdentifiers); + requestHandlerInput.setRequestContext(requestContext); + assertEquals(LCMCommandStatus.VNF_NOT_FOUND.getResponseCode(), + mockQueryHelper.query(requestHandlerInput).getResponseContext().getStatus().getCode()); + } +} diff --git a/appc-provider/appc-provider-bundle/src/test/resources/query b/appc-provider/appc-provider-bundle/src/test/resources/query new file mode 100644 index 000000000..461713c54 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/resources/query @@ -0,0 +1,70 @@ +# ============LICENSE_START========================================== +# ONAP : APPC +# =================================================================== +# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# Modifications Copyright (C) 2019 Ericsson +# =================================================================== +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the License); +# you may not use this software 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============================================ + +################################################################################################## +# +# Mock data file for LCM command Query +# +# To use me when the backend implementation is not available, +# copy me to /tmp/lcm directory on the APPC server +# +# Mock data structure: +# VNF_IDS: stores all the mocked vnfIds, separated by comma. +# for per vnfId: +# VMS_: stores all the mocked vmIds of the specific vnfId, spearated by comma. +# for each vmId: +# STATE_: stores VM state of the specific vmId. +# VM state found at https://wiki.openstack.org/wiki/VMState#vm_state +# STATUS_: stores VM sattus of the specific vmId. +# +################################################################################################## +VNF_IDS=vSCP,vSBG + +VMS_vSCP=smp001,smp002,fex001,fex002,bex001,bex002,bex003,bex004,bex005,nee001 +STATE_smp001=ACTIVE +STATE_smp002=RESCUED +STATE_fex001=PAUSED +STATE_fex002=SUSPENDED +STATE_bex001=STOPPED +STATE_bex002=HARD_DELETED +STATE_bex003=RESIZED +STATE_bex004=ERROR +STATE_bex005=SOFT_DELETED +# left out for UNKNOWN value +#STATE_nee001 + +STATUS_smp001=healthy +STATUS_smp002=unhealthy +STATUS_fex001=healthy +STATUS_fex002=healthy +STATUS_bex001=unhealthy +STATUS_bex002=unhealthy +STATUS_bex003=unhealthy +STATUS_bex004=unhealthy +STATUS_bex005=unhealthy +# left out for UNKNOWN value +#STATUS_nee001 + +VMS_vSBG=vm001 +STATE_vm001=STANDBY +STATUS_vm001=healthy -- cgit 1.2.3-korg