From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../onap/appc/dg/util/AppcDgUtilActivatorTest.java | 59 ++++++ .../dg/util/impl/ExecuteNodeActionImplTest.java | 235 +++++++++++++++++++++ .../impl/InputParameterValidationImplTest.java | 165 +++++++++++++++ .../appc/dg/util/impl/UpgradeStubNodeImplTest.java | 63 ++++++ .../appc/dg/util/AppcDgUtilActivatorTest.java | 59 ------ .../dg/util/impl/ExecuteNodeActionImplTest.java | 235 --------------------- .../impl/InputParameterValidationImplTest.java | 165 --------------- .../appc/dg/util/impl/UpgradeStubNodeImplTest.java | 63 ------ 8 files changed, 522 insertions(+), 522 deletions(-) create mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/InputParameterValidationImplTest.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/AppcDgUtilActivatorTest.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImplTest.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImplTest.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImplTest.java (limited to 'appc-dg-util/appc-dg-util-bundle/src/test/java') diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java new file mode 100644 index 000000000..066863bb8 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java @@ -0,0 +1,59 @@ +/*- + * ============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.dg.util; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.osgi.framework.BundleContext; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class AppcDgUtilActivatorTest { + + @Mock + private BundleContext bundleContext; + + private AppcDgUtilActivator appcDgUtilActivator; + + @Before + public void setUp() throws Exception { + appcDgUtilActivator = new AppcDgUtilActivator(); + } + + @Test + public void start() { + appcDgUtilActivator.start(bundleContext); + PowerMockito.verifyStatic(); + } + + @Test + public void stop() { + appcDgUtilActivator.stop(bundleContext); + PowerMockito.verifyStatic(); + } +} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java new file mode 100644 index 000000000..3280cb954 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java @@ -0,0 +1,235 @@ +/*- + * ============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.dg.util.impl; + +import com.att.eelf.configuration.EELFLogger; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.appc.exceptions.APPCException; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyMap; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.verifyPrivate; +import static org.powermock.api.mockito.PowerMockito.verifyStatic; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ExecuteNodeActionImpl.class, FrameworkUtil.class, Thread.class}) +public class ExecuteNodeActionImplTest { + @Spy + private ExecuteNodeActionImpl mockedExecuteNodeActionImpl = new ExecuteNodeActionImpl(); + @Mock + private EELFLogger eelfLogger; + @Mock + private AAIService aaiService; + + private final String resourceType = "resourceType"; + private final String prefix = "prefix"; + private final String resourceKey = "resourceKey"; + private final String attributeName = "attributeName"; + private final String attributeValue = "attributeValue"; + + private Map params = new HashMap<>(); + private SvcLogicContext svcLogicContext = new SvcLogicContext(); + private SvcLogicResource.QueryStatus queryStatus = SvcLogicResource.QueryStatus.SUCCESS; + + + @Before + public void setUp() throws Exception { + Whitebox.setInternalState(mockedExecuteNodeActionImpl, "aaiService", aaiService); + + params.put("resourceType", resourceType); + params.put("prefix", prefix); + params.put("resourceKey", resourceKey); + params.put("attributeName", attributeName); + params.put("attributeValue", attributeValue); + } + + @Test + public void testInitialize() throws Exception { + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "getAAIservice"); + Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "initialize"); + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("getAAIservice"); + } + + @Test + public void testGetAAIservice() throws Exception { + // sref is not null + mockStatic(FrameworkUtil.class); + Bundle mockedBundle = mock(Bundle.class); + BundleContext mockedBundleContext = mock(BundleContext.class); + ServiceReference mockedServiceReference = mock(ServiceReference.class); + PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(mockedBundle); + PowerMockito.doReturn(mockedBundleContext).when(mockedBundle).getBundleContext(); + PowerMockito.doReturn(mockedServiceReference).when(mockedBundleContext) + .getServiceReference(AAIService.class.getName()); + + Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "getAAIservice"); + verify(mockedBundleContext, times(1)).getService(mockedServiceReference); + + // sref is null + PowerMockito.doReturn(null).when(mockedBundleContext) + .getServiceReference(AAIService.class.getName()); + Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "getAAIservice"); + verify(mockedBundleContext, times(1)).getService(mockedServiceReference); + } + + @Test + public void testWaitMethod() throws Exception { + mockStatic(Thread.class); + params.put("waitTime", "1"); + mockedExecuteNodeActionImpl.waitMethod(params, svcLogicContext); + verifyStatic(times(1)); + } + + @Test + public void testGetResource() throws Exception { + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.doReturn(queryStatus).when(aaiService).query(resourceType, false, null, + resourceKey, prefix, null, svcLogicContext); + + mockedExecuteNodeActionImpl.getResource(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + verify(aaiService, times(1)).query(resourceType, false, null, + resourceKey, prefix, null, svcLogicContext); + assertEquals(queryStatus.toString(), svcLogicContext.getAttribute("getResource_result")); + } + + @Test + public void testPostResource() throws Exception { + + + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.doReturn(queryStatus).when(aaiService).update(eq(resourceType), eq(resourceKey), anyMap(), + eq(prefix), eq(svcLogicContext)); + + mockedExecuteNodeActionImpl.postResource(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + verify(aaiService, times(1)).update(eq(resourceType), eq(resourceKey), anyMap(), + eq(prefix), eq(svcLogicContext)); + assertEquals(svcLogicContext.getAttribute("postResource_result"), queryStatus.toString()); + } + + @Test + public void testDeleteResource() throws Exception { + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + + PowerMockito.doReturn(queryStatus).when(aaiService).delete(eq(resourceType), eq(resourceKey), + eq(svcLogicContext)); + + mockedExecuteNodeActionImpl.deleteResource(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + verify(aaiService, times(1)).delete(eq(resourceType), eq(resourceKey), + eq(svcLogicContext)); + assertEquals(svcLogicContext.getAttribute("deleteResource_result"), queryStatus.toString()); + } + + @Test + public void testGetVnfHierarchySuccess() throws Exception { + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", anyMap(), eq + (svcLogicContext)); + PowerMockito.when(aaiService.query(any(), eq(false), anyString(), any(), any(), anyString(), + any(SvcLogicContext.class))).thenReturn(queryStatus); + + mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount")); + assertEquals("SUCCESS", svcLogicContext.getAttribute("getVnfHierarchy_result")); + } + + @Test(expected = APPCException.class) + public void testGetVnfHierarchyFailure() throws Exception { + queryStatus = SvcLogicResource.QueryStatus.FAILURE; + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", anyMap(), + eq(svcLogicContext)); + PowerMockito.when(aaiService.query(any(), eq(false), anyString(), any(), any(), anyString(), + any(SvcLogicContext.class))).thenReturn(queryStatus); + + mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount")); + assertEquals("FAILURE", svcLogicContext.getAttribute("getVnfHierarchy_result")); + assertTrue(svcLogicContext.getAttribute("output.status.message") != null); + } + + @Test + public void testPopulateVnfcsDetailsinContext() throws Exception { + Map> vnfcHierarchyMap = new HashMap<>(); + Set vServersList = new HashSet<>(); + vnfcHierarchyMap.put("SMP", vServersList); + vServersList.add("smp-0-url"); + vServersList.add("smp-1-url"); + + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.when(aaiService.query(eq("vnfc"), eq(false), anyString(), + eq("vnfc-name = 'SMP'"), eq("vnfcRetrived"), anyString(), any(SvcLogicContext.class))) + .thenReturn(queryStatus); + + Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", + vnfcHierarchyMap, svcLogicContext); + + verify(mockedExecuteNodeActionImpl, times(1)).getResource(anyMap(), + any(SvcLogicContext.class)); + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + assertEquals(null, svcLogicContext.getAttribute("VNF.VNFC[0].TYPE")); + assertEquals(null, svcLogicContext.getAttribute("VNF.VNFC[0].NAME")); + assertEquals("2", svcLogicContext.getAttribute("VNF.VNFC[0].VM_COUNT")); + assertTrue(vServersList.contains(svcLogicContext.getAttribute("VNF.VNFC[0].VM[0].URL"))); + assertTrue(vServersList.contains(svcLogicContext.getAttribute("VNF.VNFC[0].VM[1].URL"))); + } +} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/InputParameterValidationImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/InputParameterValidationImplTest.java new file mode 100644 index 000000000..405c1d92a --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/InputParameterValidationImplTest.java @@ -0,0 +1,165 @@ +/*- + * ============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.dg.util.impl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; +import org.powermock.reflect.Whitebox; + +import java.util.HashMap; +import java.util.Map; + +public class InputParameterValidationImplTest { + private SvcLogicContext svcLogicContext; + + private InputParameterValidationImpl inputParameterValidation; + + @Before + public void setUp() throws Exception { + inputParameterValidation = new InputParameterValidationImpl(); + svcLogicContext = new SvcLogicContext(); + svcLogicContext.setAttribute("a", "b"); + svcLogicContext.setAttribute("b", "c"); + } + + @Test + public void validateAttributeSuccess() throws Exception { + Map params = new HashMap<>(); + params.put("a", "b"); + params.put("b", "c"); + + inputParameterValidation.validateAttribute(params, svcLogicContext); + + Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttribute")); + } + + @Test + public void validateAttributeFailure() throws Exception { + // wrong value + Map params = new HashMap<>(); + params.put("e", "f"); + + inputParameterValidation.validateAttribute(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); + + // null value + params = new HashMap<>(); + params.put("e", null); + + inputParameterValidation.validateAttribute(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); + } + + @Test + public void validateAttributeNull() throws Exception { + inputParameterValidation.validateAttribute(null, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); + } + + @Test + public void validateAttributeLengthSuccess() throws Exception { + Map params = new HashMap<>(); + params.put("maximum_length_param", "2"); + params.put("a", "1"); + + inputParameterValidation.validateAttributeLength(params, svcLogicContext); + + Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeLength")); + } + + @Test + public void validateAttributeLengthFailure() throws Exception { + // wrong key + Map params = new HashMap<>(); + params.put("maximum_length_param", "2"); + params.put("e", "1"); + + inputParameterValidation.validateAttributeLength(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); + + //over length + params = new HashMap<>(); + params.put("maximum_length_param", "2"); + params.put("c", "3"); + + inputParameterValidation.validateAttributeLength(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); + } + + @Test + public void validateAttributeLengthNull() throws Exception { + inputParameterValidation.validateAttributeLength(null, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); + } + + @Test + public void validateAttributeCharacterSuccess() throws Exception { + Map params = new HashMap<>(); + params.put("special_characters", "z"); + params.put("a", "1"); + + inputParameterValidation.validateAttributeCharacter(params, svcLogicContext); + + Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeCharacter")); + } + + @Test + public void validateAttributeCharacterFailure() throws Exception { + Map params = new HashMap<>(); + params.put("special_characters", "z"); + params.put("d", "1"); + + inputParameterValidation.validateAttributeCharacter(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter")); + } + + @Test + public void validateAttributeCharacterNull() throws Exception { + inputParameterValidation.validateAttributeCharacter(null, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter")); + } + + @Test + public void testGetValueFromContext() throws Exception { + Map result = Whitebox.invokeMethod(inputParameterValidation, "getValueFromContext", + svcLogicContext); + Assert.assertEquals("b", result.get("a")); + Assert.assertEquals("c", result.get("b")); + } +} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java new file mode 100644 index 000000000..6eb732064 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.dg.util.impl; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; + +import java.util.HashMap; +import java.util.Map; + +public class UpgradeStubNodeImplTest { + @Mock + private SvcLogicContext svcLogicContext; + + private UpgradeStubNodeImpl upgradeStubNode; + + @Before + public void setUp() throws Exception { + upgradeStubNode = new UpgradeStubNodeImpl(); + } + + @Test + public void testHandleUpgradeStubSuccess() throws APPCException { + Map params = new HashMap<>(); + upgradeStubNode.handleUpgradeStub(params, svcLogicContext); + } + + @Test(expected = APPCException.class) + public void testHandleUpgradeStubException() throws APPCException { + Map params = new HashMap<>(); + params.put("failureIndicator", "true"); + upgradeStubNode.handleUpgradeStub(params, svcLogicContext); + } +} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/AppcDgUtilActivatorTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/AppcDgUtilActivatorTest.java deleted file mode 100644 index 066863bb8..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/AppcDgUtilActivatorTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.dg.util; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.osgi.framework.BundleContext; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -public class AppcDgUtilActivatorTest { - - @Mock - private BundleContext bundleContext; - - private AppcDgUtilActivator appcDgUtilActivator; - - @Before - public void setUp() throws Exception { - appcDgUtilActivator = new AppcDgUtilActivator(); - } - - @Test - public void start() { - appcDgUtilActivator.start(bundleContext); - PowerMockito.verifyStatic(); - } - - @Test - public void stop() { - appcDgUtilActivator.stop(bundleContext); - PowerMockito.verifyStatic(); - } -} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImplTest.java deleted file mode 100644 index 3280cb954..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImplTest.java +++ /dev/null @@ -1,235 +0,0 @@ -/*- - * ============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.dg.util.impl; - -import com.att.eelf.configuration.EELFLogger; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Spy; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.appc.exceptions.APPCException; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.verifyPrivate; -import static org.powermock.api.mockito.PowerMockito.verifyStatic; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ExecuteNodeActionImpl.class, FrameworkUtil.class, Thread.class}) -public class ExecuteNodeActionImplTest { - @Spy - private ExecuteNodeActionImpl mockedExecuteNodeActionImpl = new ExecuteNodeActionImpl(); - @Mock - private EELFLogger eelfLogger; - @Mock - private AAIService aaiService; - - private final String resourceType = "resourceType"; - private final String prefix = "prefix"; - private final String resourceKey = "resourceKey"; - private final String attributeName = "attributeName"; - private final String attributeValue = "attributeValue"; - - private Map params = new HashMap<>(); - private SvcLogicContext svcLogicContext = new SvcLogicContext(); - private SvcLogicResource.QueryStatus queryStatus = SvcLogicResource.QueryStatus.SUCCESS; - - - @Before - public void setUp() throws Exception { - Whitebox.setInternalState(mockedExecuteNodeActionImpl, "aaiService", aaiService); - - params.put("resourceType", resourceType); - params.put("prefix", prefix); - params.put("resourceKey", resourceKey); - params.put("attributeName", attributeName); - params.put("attributeValue", attributeValue); - } - - @Test - public void testInitialize() throws Exception { - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "getAAIservice"); - Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "initialize"); - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("getAAIservice"); - } - - @Test - public void testGetAAIservice() throws Exception { - // sref is not null - mockStatic(FrameworkUtil.class); - Bundle mockedBundle = mock(Bundle.class); - BundleContext mockedBundleContext = mock(BundleContext.class); - ServiceReference mockedServiceReference = mock(ServiceReference.class); - PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(mockedBundle); - PowerMockito.doReturn(mockedBundleContext).when(mockedBundle).getBundleContext(); - PowerMockito.doReturn(mockedServiceReference).when(mockedBundleContext) - .getServiceReference(AAIService.class.getName()); - - Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "getAAIservice"); - verify(mockedBundleContext, times(1)).getService(mockedServiceReference); - - // sref is null - PowerMockito.doReturn(null).when(mockedBundleContext) - .getServiceReference(AAIService.class.getName()); - Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "getAAIservice"); - verify(mockedBundleContext, times(1)).getService(mockedServiceReference); - } - - @Test - public void testWaitMethod() throws Exception { - mockStatic(Thread.class); - params.put("waitTime", "1"); - mockedExecuteNodeActionImpl.waitMethod(params, svcLogicContext); - verifyStatic(times(1)); - } - - @Test - public void testGetResource() throws Exception { - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.doReturn(queryStatus).when(aaiService).query(resourceType, false, null, - resourceKey, prefix, null, svcLogicContext); - - mockedExecuteNodeActionImpl.getResource(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - verify(aaiService, times(1)).query(resourceType, false, null, - resourceKey, prefix, null, svcLogicContext); - assertEquals(queryStatus.toString(), svcLogicContext.getAttribute("getResource_result")); - } - - @Test - public void testPostResource() throws Exception { - - - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.doReturn(queryStatus).when(aaiService).update(eq(resourceType), eq(resourceKey), anyMap(), - eq(prefix), eq(svcLogicContext)); - - mockedExecuteNodeActionImpl.postResource(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - verify(aaiService, times(1)).update(eq(resourceType), eq(resourceKey), anyMap(), - eq(prefix), eq(svcLogicContext)); - assertEquals(svcLogicContext.getAttribute("postResource_result"), queryStatus.toString()); - } - - @Test - public void testDeleteResource() throws Exception { - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - - PowerMockito.doReturn(queryStatus).when(aaiService).delete(eq(resourceType), eq(resourceKey), - eq(svcLogicContext)); - - mockedExecuteNodeActionImpl.deleteResource(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - verify(aaiService, times(1)).delete(eq(resourceType), eq(resourceKey), - eq(svcLogicContext)); - assertEquals(svcLogicContext.getAttribute("deleteResource_result"), queryStatus.toString()); - } - - @Test - public void testGetVnfHierarchySuccess() throws Exception { - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", anyMap(), eq - (svcLogicContext)); - PowerMockito.when(aaiService.query(any(), eq(false), anyString(), any(), any(), anyString(), - any(SvcLogicContext.class))).thenReturn(queryStatus); - - mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount")); - assertEquals("SUCCESS", svcLogicContext.getAttribute("getVnfHierarchy_result")); - } - - @Test(expected = APPCException.class) - public void testGetVnfHierarchyFailure() throws Exception { - queryStatus = SvcLogicResource.QueryStatus.FAILURE; - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", anyMap(), - eq(svcLogicContext)); - PowerMockito.when(aaiService.query(any(), eq(false), anyString(), any(), any(), anyString(), - any(SvcLogicContext.class))).thenReturn(queryStatus); - - mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount")); - assertEquals("FAILURE", svcLogicContext.getAttribute("getVnfHierarchy_result")); - assertTrue(svcLogicContext.getAttribute("output.status.message") != null); - } - - @Test - public void testPopulateVnfcsDetailsinContext() throws Exception { - Map> vnfcHierarchyMap = new HashMap<>(); - Set vServersList = new HashSet<>(); - vnfcHierarchyMap.put("SMP", vServersList); - vServersList.add("smp-0-url"); - vServersList.add("smp-1-url"); - - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.when(aaiService.query(eq("vnfc"), eq(false), anyString(), - eq("vnfc-name = 'SMP'"), eq("vnfcRetrived"), anyString(), any(SvcLogicContext.class))) - .thenReturn(queryStatus); - - Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", - vnfcHierarchyMap, svcLogicContext); - - verify(mockedExecuteNodeActionImpl, times(1)).getResource(anyMap(), - any(SvcLogicContext.class)); - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - assertEquals(null, svcLogicContext.getAttribute("VNF.VNFC[0].TYPE")); - assertEquals(null, svcLogicContext.getAttribute("VNF.VNFC[0].NAME")); - assertEquals("2", svcLogicContext.getAttribute("VNF.VNFC[0].VM_COUNT")); - assertTrue(vServersList.contains(svcLogicContext.getAttribute("VNF.VNFC[0].VM[0].URL"))); - assertTrue(vServersList.contains(svcLogicContext.getAttribute("VNF.VNFC[0].VM[1].URL"))); - } -} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImplTest.java deleted file mode 100644 index 405c1d92a..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImplTest.java +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * ============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.dg.util.impl; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; -import org.powermock.reflect.Whitebox; - -import java.util.HashMap; -import java.util.Map; - -public class InputParameterValidationImplTest { - private SvcLogicContext svcLogicContext; - - private InputParameterValidationImpl inputParameterValidation; - - @Before - public void setUp() throws Exception { - inputParameterValidation = new InputParameterValidationImpl(); - svcLogicContext = new SvcLogicContext(); - svcLogicContext.setAttribute("a", "b"); - svcLogicContext.setAttribute("b", "c"); - } - - @Test - public void validateAttributeSuccess() throws Exception { - Map params = new HashMap<>(); - params.put("a", "b"); - params.put("b", "c"); - - inputParameterValidation.validateAttribute(params, svcLogicContext); - - Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttribute")); - } - - @Test - public void validateAttributeFailure() throws Exception { - // wrong value - Map params = new HashMap<>(); - params.put("e", "f"); - - inputParameterValidation.validateAttribute(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); - - // null value - params = new HashMap<>(); - params.put("e", null); - - inputParameterValidation.validateAttribute(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); - } - - @Test - public void validateAttributeNull() throws Exception { - inputParameterValidation.validateAttribute(null, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); - } - - @Test - public void validateAttributeLengthSuccess() throws Exception { - Map params = new HashMap<>(); - params.put("maximum_length_param", "2"); - params.put("a", "1"); - - inputParameterValidation.validateAttributeLength(params, svcLogicContext); - - Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeLength")); - } - - @Test - public void validateAttributeLengthFailure() throws Exception { - // wrong key - Map params = new HashMap<>(); - params.put("maximum_length_param", "2"); - params.put("e", "1"); - - inputParameterValidation.validateAttributeLength(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); - - //over length - params = new HashMap<>(); - params.put("maximum_length_param", "2"); - params.put("c", "3"); - - inputParameterValidation.validateAttributeLength(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); - } - - @Test - public void validateAttributeLengthNull() throws Exception { - inputParameterValidation.validateAttributeLength(null, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); - } - - @Test - public void validateAttributeCharacterSuccess() throws Exception { - Map params = new HashMap<>(); - params.put("special_characters", "z"); - params.put("a", "1"); - - inputParameterValidation.validateAttributeCharacter(params, svcLogicContext); - - Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeCharacter")); - } - - @Test - public void validateAttributeCharacterFailure() throws Exception { - Map params = new HashMap<>(); - params.put("special_characters", "z"); - params.put("d", "1"); - - inputParameterValidation.validateAttributeCharacter(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter")); - } - - @Test - public void validateAttributeCharacterNull() throws Exception { - inputParameterValidation.validateAttributeCharacter(null, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter")); - } - - @Test - public void testGetValueFromContext() throws Exception { - Map result = Whitebox.invokeMethod(inputParameterValidation, "getValueFromContext", - svcLogicContext); - Assert.assertEquals("b", result.get("a")); - Assert.assertEquals("c", result.get("b")); - } -} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImplTest.java deleted file mode 100644 index 6eb732064..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImplTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============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.dg.util.impl; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; - -import java.util.HashMap; -import java.util.Map; - -public class UpgradeStubNodeImplTest { - @Mock - private SvcLogicContext svcLogicContext; - - private UpgradeStubNodeImpl upgradeStubNode; - - @Before - public void setUp() throws Exception { - upgradeStubNode = new UpgradeStubNodeImpl(); - } - - @Test - public void testHandleUpgradeStubSuccess() throws APPCException { - Map params = new HashMap<>(); - upgradeStubNode.handleUpgradeStub(params, svcLogicContext); - } - - @Test(expected = APPCException.class) - public void testHandleUpgradeStubException() throws APPCException { - Map params = new HashMap<>(); - params.put("failureIndicator", "true"); - upgradeStubNode.handleUpgradeStub(params, svcLogicContext); - } -} \ No newline at end of file -- cgit 1.2.3-korg