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