diff options
author | 2018-07-23 18:05:35 +0200 | |
---|---|---|
committer | 2018-08-10 14:04:47 +0000 | |
commit | ed13e1b0270932ba8bbfa7b51c84b4b88894e061 (patch) | |
tree | 7286b56c38e3c265a348efc1003c093585a648a2 /appc-dg-util/appc-dg-util-bundle/src/main/java | |
parent | e35c3a0387e68bbeb3df8c5d614e0b99f5c4f743 (diff) |
Remove all powermock(ito) usages in appc-dg-util
- Replace powermock usage with mockito.
- Introduce AAIServiceFactory for fetching AAIService from bundle
- Using blueprint.xml DI to pass factory into ExecuteNodeActionImpl
during construction
- removed powermock(ito) deps from pom
Change-Id: I54450580c68c7d4992cb412192ca6dd4741398fc
Issue-ID: APPC-1008
Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
Diffstat (limited to 'appc-dg-util/appc-dg-util-bundle/src/main/java')
2 files changed, 74 insertions, 39 deletions
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; |