aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-dg-util/appc-dg-util-bundle/pom.xml12
-rw-r--r--appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/AAIServiceFactory.java60
-rw-r--r--appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java53
-rw-r--r--appc-dg-util/appc-dg-util-bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml10
-rw-r--r--appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/AAIServiceFactoryTest.java81
-rw-r--r--appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java208
6 files changed, 243 insertions, 181 deletions
diff --git a/appc-dg-util/appc-dg-util-bundle/pom.xml b/appc-dg-util/appc-dg-util-bundle/pom.xml
index bc032ecb2..32ecd396e 100644
--- a/appc-dg-util/appc-dg-util-bundle/pom.xml
+++ b/appc-dg-util/appc-dg-util-bundle/pom.xml
@@ -6,6 +6,8 @@
Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
Copyright (C) 2017 Amdocs
================================================================================
+ Modifications Copyright (C) 2018 Nokia
+ ================================================================================
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
@@ -189,16 +191,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/AAIServiceFactory.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/AAIServiceFactory.java
new file mode 100644
index 000000000..2584f6268
--- /dev/null
+++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/AAIServiceFactory.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia
+ * ================================================================================
+ * 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.dg.util.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import org.onap.appc.i18n.Msg;
+import org.onap.ccsdk.sli.adaptors.aai.AAIService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+public class AAIServiceFactory {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIServiceFactory.class);
+
+ private FrameworkUtilWrapper frameworkUtilWrapper = new FrameworkUtilWrapper();
+
+ public AAIService getAAIService() {
+ BundleContext bctx = frameworkUtilWrapper.getBundle(AAIService.class).getBundleContext();
+ // Get AAIadapter reference
+ ServiceReference sref = bctx.getServiceReference(AAIService.class.getName());
+ if (sref != null) {
+ logger.info("AAIService from bundlecontext");
+ return (AAIService) bctx.getService(sref);
+
+ } else {
+ logger.info("AAIService error from bundlecontext");
+ logger.error(EELFResourceManager.format(Msg.AAI_CONNECTION_FAILED, "AAIService"));
+ }
+ return null;
+ }
+
+ static class FrameworkUtilWrapper {
+
+ Bundle getBundle(Class<?> clazz) {
+ return FrameworkUtil.getBundle(clazz);
+ }
+ }
+} \ No newline at end of file
diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java
index 9e21d75de..d2aa68a14 100644
--- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java
+++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java
@@ -5,7 +5,9 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
- * =============================================================================
+ * ================================================================================
+ * Modifications Copyright (C) 2018 Nokia
+ * ================================================================================
* 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
@@ -35,14 +37,9 @@ import java.util.concurrent.ConcurrentHashMap;
import org.onap.appc.dg.util.ExecuteNodeAction;
import org.onap.appc.exceptions.APPCException;
import org.onap.appc.i18n.Msg;
-import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
-import org.onap.ccsdk.sli.adaptors.aai.AAIService;
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.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
public class ExecuteNodeActionImpl implements ExecuteNodeAction {
@@ -63,30 +60,10 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
private static final String RELATED_TO_PROPERTY_LEN_PARAM = "related-to-property_length";
public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
- private AAIService aaiService;
- protected AAIClient client;
-
- public ExecuteNodeActionImpl() { /*default constructor*/}
-
- /**
- * initialize the SDNC adapter (AAIService) by building the context.
- */
- private void initialize() {
- getAAIservice();
- }
-
- private void getAAIservice() {
- BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext();
- // Get AAIadapter reference
- ServiceReference sref = bctx.getServiceReference(AAIService.class.getName());
- if (sref != null) {
- logger.info("AAIService from bundlecontext");
- aaiService = (AAIService) bctx.getService(sref);
+ private AAIServiceFactory aaiServiceFactory;
- } else {
- logger.info("AAIService error from bundlecontext");
- logger.error(EELFResourceManager.format(Msg.AAI_CONNECTION_FAILED, "AAIService"));
- }
+ public ExecuteNodeActionImpl(AAIServiceFactory aaiServiceFactory) {
+ this.aaiServiceFactory = aaiServiceFactory;
}
/**
@@ -110,7 +87,6 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
@Override
public void getResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- initialize();
String resourceType = params.get(RESOURCE_TYPE_PARAM);
String ctxPrefix = params.get(PREFIX_PARAM);
String resourceKey = params.get(RESOURCE_KEY_PARAM);
@@ -119,10 +95,10 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
logger.debug("inside getResorce");
logger.debug("Retrieving " + resourceType + " details from A&AI for Key : " + resourceKey);
}
- client = aaiService;
+
try {
SvcLogicResource.QueryStatus response =
- client.query(resourceType, false, null, resourceKey, ctxPrefix, null, ctx);
+ aaiServiceFactory.getAAIService().query(resourceType, false, null, resourceKey, ctxPrefix, null, ctx);
logger.info(AAI_RESPONSE_STR + response.toString());
ctx.setAttribute(GET_RESOURCE_RESULT, response.toString());
} catch (SvcLogicException e) {
@@ -136,7 +112,6 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
@Override
public void postResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- initialize();
String resourceType = params.get(RESOURCE_TYPE_PARAM);
String ctxPrefix = params.get(PREFIX_PARAM);
String resourceKey = params.get(RESOURCE_KEY_PARAM);
@@ -149,10 +124,10 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
}
Map<String, String> data = new HashMap<>();
data.put(attName, attValue);
- client = aaiService;
try {
- SvcLogicResource.QueryStatus response = client.update(resourceType, resourceKey, data, ctxPrefix, ctx);
+ SvcLogicResource.QueryStatus response = aaiServiceFactory.getAAIService()
+ .update(resourceType, resourceKey, data, ctxPrefix, ctx);
logger.info(AAI_RESPONSE_STR + response.toString());
ctx.setAttribute("postResource_result", response.toString());
} catch (SvcLogicException e) {
@@ -166,7 +141,6 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
@Override
public void deleteResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- initialize();
String resourceType = params.get(RESOURCE_TYPE_PARAM);
String resourceKey = params.get(RESOURCE_KEY_PARAM);
@@ -174,9 +148,10 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
logger.debug("inside deleteResource");
logger.debug("Deleting " + resourceType + " details From A&AI for Key : " + resourceKey);
}
- client = aaiService;
+
try {
- SvcLogicResource.QueryStatus response = client.delete(resourceType, resourceKey, ctx);
+ SvcLogicResource.QueryStatus response = aaiServiceFactory.getAAIService()
+ .delete(resourceType, resourceKey, ctx);
logger.info(AAI_RESPONSE_STR + response.toString());
ctx.setAttribute("deleteResource_result", response.toString());
} catch (SvcLogicException e) {
@@ -360,7 +335,7 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
return 0;
}
- private void populateVnfcsDetailsinContext(Map<String, Set<String>> vnfcHierarchyMap, SvcLogicContext ctx)
+ void populateVnfcsDetailsinContext(Map<String, Set<String>> vnfcHierarchyMap, SvcLogicContext ctx)
throws APPCException {
SvcLogicContext vnfcCtx = new SvcLogicContext();
int vnfcCounter = 0;
diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/appc-dg-util/appc-dg-util-bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 824b2ce47..fdb507778 100644
--- a/appc-dg-util/appc-dg-util-bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/appc-dg-util/appc-dg-util-bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -6,7 +6,9 @@
Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
================================================================================
Copyright (C) 2017 Amdocs
- =============================================================================
+ ================================================================================
+ Modifications Copyright (C) 2018 Nokia
+ ================================================================================
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
@@ -34,7 +36,11 @@
<service id="inputParameterValidationService" interface="org.onap.appc.dg.util.InputParameterValidation" ref="inputParameterValidationBean"/>
- <bean id="executeNodeActionBean" class="org.onap.appc.dg.util.impl.ExecuteNodeActionImpl" scope="prototype" >
+ <bean id="aaiServiceFactory" class="org.onap.appc.dg.util.impl.AAIServiceFactory">
+ </bean>
+
+ <bean id="executeNodeActionBean" class="org.onap.appc.dg.util.impl.ExecuteNodeActionImpl" scope="prototype">
+ <argument ref="aaiServiceFactory"/>
</bean>
<service id="executeNodeActionService" interface="org.onap.appc.dg.util.ExecuteNodeAction" ref="executeNodeActionBean"/>
diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/AAIServiceFactoryTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/AAIServiceFactoryTest.java
new file mode 100644
index 000000000..3fb27d729
--- /dev/null
+++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/AAIServiceFactoryTest.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia
+ * ================================================================================
+ * 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.dg.util.impl;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.then;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.sli.adaptors.aai.AAIService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAIServiceFactoryTest {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private AAIServiceFactory.FrameworkUtilWrapper frameworkUtilWrapper = new AAIServiceFactory.FrameworkUtilWrapper();
+
+ @InjectMocks
+ private AAIServiceFactory aaiServiceFactory;
+
+ @Test
+ public void getAAIservice_shouldLookupAAIService_fromBundle() {
+ // GIVEN
+ AAIService expectedAAIService = mock(AAIService.class);
+
+ BundleContext mockedBundleContext = mock(BundleContext.class);
+ ServiceReference mockedServiceReference = mock(ServiceReference.class);
+ given(frameworkUtilWrapper.getBundle(AAIService.class).getBundleContext()).willReturn(mockedBundleContext);
+ given(mockedBundleContext.getServiceReference(AAIService.class.getName())).willReturn(mockedServiceReference);
+ given(mockedBundleContext.getService(mockedServiceReference)).willReturn(expectedAAIService);
+
+ // WHEN
+ AAIService resultAAIService = aaiServiceFactory.getAAIService();
+
+ // THEN
+ assertThat(resultAAIService).isNotNull().isEqualTo(expectedAAIService);
+ }
+
+ @Test
+ public void getAAIservice_shouldNotLookupAAIService_forNullServiceReference() {
+ // GIVEN
+ BundleContext mockedBundleContext = mock(BundleContext.class);
+ given(frameworkUtilWrapper.getBundle(AAIService.class).getBundleContext()).willReturn(mockedBundleContext);
+ given(mockedBundleContext.getServiceReference(AAIService.class.getName())).willReturn(null);
+
+ // WHEN
+ AAIService resultAAIService = aaiServiceFactory.getAAIService();
+
+ // THEN
+ assertThat(resultAAIService).isNull();
+ then(mockedBundleContext).should(never()).getService(any(ServiceReference.class));
+ }
+} \ 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
index 907d89662..c6104297b 100644
--- 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
@@ -5,7 +5,9 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
- * =============================================================================
+ * ================================================================================
+ * Modifications Copyright (C) 2018 Nokia
+ * ================================================================================
* 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
@@ -23,166 +25,129 @@
package org.onap.appc.dg.util.impl;
-import com.att.eelf.configuration.EELFLogger;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.BDDMockito.given;
+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.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.appc.exceptions.APPCException;
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;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({FrameworkUtil.class, Thread.class})
+@RunWith(MockitoJUnitRunner.class)
public class ExecuteNodeActionImplTest {
- private ExecuteNodeActionImpl mockedExecuteNodeActionImpl = PowerMockito.spy(new ExecuteNodeActionImpl());
+
+ private static final String resourceType = "resourceType";
+ private static final String prefix = "prefix";
+ private static final String resourceKey = "resourceKey";
+ private static final String attributeName = "attributeName";
+ private static final String attributeValue = "attributeValue";
+ private static final Map<String, String> params = new HashMap<>();
+ private static final SvcLogicContext SVC_LOGIC_CONTEXT = new SvcLogicContext();
+ private static final SvcLogicResource.QueryStatus SUCCESS_STATUS = SvcLogicResource.QueryStatus.SUCCESS;
+ private static final QueryStatus FAILED_STATUS = SvcLogicResource.QueryStatus.FAILURE;
+
@Mock
- private EELFLogger eelfLogger;
+ private AAIServiceFactory aaiServiceFactory;
@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<String, String> params = new HashMap<>();
- private SvcLogicContext svcLogicContext = new SvcLogicContext();
- private SvcLogicResource.QueryStatus queryStatus = SvcLogicResource.QueryStatus.SUCCESS;
+ private ExecuteNodeActionImpl executeNodeAction;
@Before
- public void setUp() throws Exception {
- Whitebox.setInternalState(mockedExecuteNodeActionImpl, "aaiService", aaiService);
+ public void setUp() {
+ executeNodeAction = new ExecuteNodeActionImpl(aaiServiceFactory);
+ given(aaiServiceFactory.getAAIService()).willReturn(aaiService);
params.put("resourceType", resourceType);
params.put("prefix", prefix);
params.put("resourceKey", resourceKey);
params.put("attributeName", attributeName);
params.put("attributeValue", attributeValue);
- }
-
- @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, "initialize");
- 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);
+ params.put("waitTime", "1");
}
@Test
public void testWaitMethod() throws Exception {
- mockStatic(Thread.class);
- params.put("waitTime", "1");
- mockedExecuteNodeActionImpl.waitMethod(params, svcLogicContext);
- verifyStatic(times(1));
+ executeNodeAction.waitMethod(params, SVC_LOGIC_CONTEXT);
}
@Test
public void testGetResource() throws Exception {
- AAIService aaiService = setupForResourceTests();
- PowerMockito.doReturn(queryStatus).when(aaiService).query(Mockito.<String>any(), Mockito.anyBoolean(),
- Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(),
- Mockito.any(SvcLogicContext.class));
+ given(aaiService.query(any(), Mockito.anyBoolean(),
+ any(), any(), any(), any(),
+ any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
- mockedExecuteNodeActionImpl.getResource(params, svcLogicContext);
+ executeNodeAction.getResource(params, SVC_LOGIC_CONTEXT);
- verify(aaiService, times(1)).query(resourceType, false, null, resourceKey, prefix, null, svcLogicContext);
- assertEquals(queryStatus.toString(), svcLogicContext.getAttribute("getResource_result"));
+ verify(aaiService, times(1)).query(resourceType, false, null, resourceKey, prefix, null, SVC_LOGIC_CONTEXT);
+ assertEquals(SUCCESS_STATUS.toString(), SVC_LOGIC_CONTEXT.getAttribute("getResource_result"));
}
@Test
public void testPostResource() throws Exception {
- AAIService aaiService = setupForResourceTests();
- PowerMockito.doReturn(queryStatus).when(aaiService).update(eq(resourceType), eq(resourceKey), anyMap(),
- eq(prefix), eq(svcLogicContext));
+ given(aaiService.update(eq(resourceType), eq(resourceKey), anyMap(),
+ eq(prefix), eq(SVC_LOGIC_CONTEXT))).willReturn(SUCCESS_STATUS);
- mockedExecuteNodeActionImpl.postResource(params, svcLogicContext);
+ executeNodeAction.postResource(params, SVC_LOGIC_CONTEXT);
verify(aaiService, times(1)).update(eq(resourceType), eq(resourceKey), anyMap(), eq(prefix),
- eq(svcLogicContext));
- assertEquals(svcLogicContext.getAttribute("postResource_result"), queryStatus.toString());
+ eq(SVC_LOGIC_CONTEXT));
+ assertEquals(SUCCESS_STATUS.toString(), SVC_LOGIC_CONTEXT.getAttribute("postResource_result"));
}
@Test
public void testDeleteResource() throws Exception {
- AAIService aaiService = setupForResourceTests();
-
- PowerMockito.doReturn(queryStatus).when(aaiService).delete(eq(resourceType), eq(resourceKey),
- eq(svcLogicContext));
+ given(aaiService.delete(eq(resourceType), eq(resourceKey),
+ eq(SVC_LOGIC_CONTEXT))).willReturn(SUCCESS_STATUS);
- mockedExecuteNodeActionImpl.deleteResource(params, svcLogicContext);
+ executeNodeAction.deleteResource(params, SVC_LOGIC_CONTEXT);
- verify(aaiService, times(1)).delete(eq(resourceType), eq(resourceKey), eq(svcLogicContext));
- assertEquals(svcLogicContext.getAttribute("deleteResource_result"), queryStatus.toString());
+ verify(aaiService, times(1)).delete(eq(resourceType), eq(resourceKey), eq(SVC_LOGIC_CONTEXT));
+ assertEquals(SUCCESS_STATUS.toString(), SVC_LOGIC_CONTEXT.getAttribute("deleteResource_result"));
}
@Test
public void testGetVnfHierarchySuccess() throws Exception {
- AAIService aaiService = setupForResourceTests();
-
- PowerMockito.doReturn(queryStatus).when(aaiService).query(Mockito.<String>any(), Mockito.anyBoolean(),
- Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(),
- Mockito.any(SvcLogicContext.class));
+ given(aaiService.query(any(), Mockito.anyBoolean(),
+ any(), any(), any(), any(),
+ any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
- mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext);
+ executeNodeAction.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
- assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount"));
- assertEquals("SUCCESS", svcLogicContext.getAttribute("getVnfHierarchy_result"));
+ assertEquals("0", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
+ assertEquals("SUCCESS", SVC_LOGIC_CONTEXT.getAttribute("getVnfHierarchy_result"));
}
@Test(expected = APPCException.class)
public void testGetVnfHierarchyFailure() throws Exception {
- queryStatus = SvcLogicResource.QueryStatus.FAILURE;
- AAIService aaiService = setupForResourceTests();
- PowerMockito.doReturn(queryStatus).when(aaiService).query(Mockito.<String>any(), Mockito.anyBoolean(),
- Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(),
- Mockito.any(SvcLogicContext.class));
+ given(aaiService.query(any(), Mockito.anyBoolean(),
+ any(), any(), any(), any(),
+ any(SvcLogicContext.class))).willReturn(FAILED_STATUS);
- mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext);
+ executeNodeAction.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
- assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount"));
- assertEquals("FAILURE", svcLogicContext.getAttribute("getVnfHierarchy_result"));
- assertTrue(svcLogicContext.getAttribute("output.status.message") != null);
+ assertEquals("0", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
+ assertEquals("FAILURE", SVC_LOGIC_CONTEXT.getAttribute("getVnfHierarchy_result"));
+ assertNotNull(SVC_LOGIC_CONTEXT.getAttribute("output.status.message"));
}
@Test
@@ -193,32 +158,15 @@ public class ExecuteNodeActionImplTest {
vServersList.add("smp-0-url");
vServersList.add("smp-1-url");
- AAIService aaiService = setupForResourceTests();
- PowerMockito.when(aaiService.query(eq("vnfc"), eq(false), anyString(), eq("vnfc-name = 'SMP'"),
- eq("vnfcRetrived"), anyString(), any(SvcLogicContext.class))).thenReturn(queryStatus);
+ given(aaiService.query(eq("vnfc"), eq(false), anyString(), eq("vnfc-name = 'SMP'"),
+ eq("vnfcRetrived"), anyString(), any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
- Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", vnfcHierarchyMap,
- svcLogicContext);
-
- verify(mockedExecuteNodeActionImpl, times(1)).getResource(anyMap(), any(SvcLogicContext.class));
- 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")));
- }
+ executeNodeAction.populateVnfcsDetailsinContext(vnfcHierarchyMap, SVC_LOGIC_CONTEXT);
- private AAIService setupForResourceTests() {
- 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());
- AAIService aaiService = PowerMockito.mock(AAIService.class);
- PowerMockito.doReturn(aaiService).when(mockedBundleContext).getService(mockedServiceReference);
- return aaiService;
+ assertNull(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].TYPE"));
+ assertNull(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].NAME"));
+ assertEquals("2", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM_COUNT"));
+ assertTrue(vServersList.contains(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM[0].URL")));
+ assertTrue(vServersList.contains(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM[1].URL")));
}
}