2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
15 * SPDX-License-Identifier: Apache-2.0
16 * ============LICENSE_END=========================================================
19 package org.onap.appc.dg.common.impl;
21 import static org.junit.Assert.assertEquals;
22 import static org.mockito.Matchers.anyString;
23 import java.util.HashMap;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.Mockito;
29 import org.onap.appc.exceptions.APPCException;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.powermock.api.mockito.PowerMockito;
32 import org.powermock.core.classloader.annotations.PrepareForTest;
33 import org.powermock.modules.junit4.PowerMockRunner;
35 @RunWith(PowerMockRunner.class)
36 @PrepareForTest(ResolverFactory.class)
37 public class TestDgResolverPluginImpl {
39 private DgResolverPluginImpl dgResolverPluginImpl;
40 private Map<String, String> params;
41 private SvcLogicContext ctx;
42 private AbstractResolver abstractResolver;
43 private FlowKey flowKey;
47 params = new HashMap<>();
48 ctx = new SvcLogicContext();
49 PowerMockito.mockStatic(ResolverFactory.class);
50 flowKey = Mockito.mock(FlowKey.class);
51 abstractResolver = Mockito.mock(AbstractResolver.class);
52 PowerMockito.when(ResolverFactory.createResolver(anyString())).thenReturn(abstractResolver);
53 dgResolverPluginImpl = new DgResolverPluginImpl();
54 PowerMockito.when(flowKey.name()).thenReturn("flowName");
58 public void testResolveDgVNF() throws APPCException {
59 params.put("action", "healthcheck");
60 params.put("vnfVersion", "1");
61 params.put("api-ver", "1.0");
62 params.put("DGResolutionType", "VNF");
63 params.put("vnfType", "vnfType");
64 PowerMockito.when(abstractResolver.resolve("healthcheck", "vnfType", "1", "1.0"))
66 dgResolverPluginImpl.resolveDg(params, ctx);
67 assertEquals("flowName", ctx.getAttribute("dg_name"));
71 public void testResolveDgVNFC() throws APPCException {
72 params.put("action", "healthcheck");
73 params.put("vnfcType", "vnfcType");
74 params.put("api-ver", "1.0");
75 params.put("DGResolutionType", "VNFC");
76 params.put("vnfType", "vnfType");
77 PowerMockito.when(abstractResolver.resolve("healthcheck", "vnfType", "vnfcType", "1.0"))
79 dgResolverPluginImpl.resolveDg(params, ctx);
80 assertEquals("flowName", ctx.getAttribute("dg_name"));
83 @Test(expected = DgResolverException.class)
84 public void testResolveDgWithException() throws APPCException {
85 params.put("action", "healthcheck");
86 params.put("vnfcType", "vnfcType");
87 params.put("api-ver", "1.0");
88 params.put("DGResolutionType", "VNFC");
89 params.put("vnfType", "vnfType1");
90 PowerMockito.when(abstractResolver.resolve("healthcheck", "vnfType", "vnfcType", "1.0"))
92 dgResolverPluginImpl.resolveDg(params, ctx);
95 @Test(expected = DgResolverException.class)
96 public void testResolveDgResolverNull() throws APPCException {
97 PowerMockito.when(ResolverFactory.createResolver(anyString())).thenReturn(null);
98 dgResolverPluginImpl.resolveDg(params, ctx);