2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2018 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.system.node;
29 import java.util.HashMap;
31 import org.jline.utils.Log;
32 import org.junit.Assert;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.powermock.api.mockito.PowerMockito;
37 import org.mockito.Mockito;
38 import org.onap.appc.aai.utils.AaiClientConstant;
39 import org.onap.appc.instar.interfaceImpl.InstarRestClientImpl;
40 import org.onap.appc.instar.interfaceImpl.InterfaceIpAddressImpl;
41 import org.onap.appc.system.interfaces.RuleHandlerInterface;
42 import org.onap.appc.instar.utils.InstarClientConstant;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
44 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
47 public class SourceSystemNodeTest {
53 public ExpectedException expectedEx = ExpectedException.none();
56 public void testSourceSystemNode() throws Exception {
57 SvcLogicContext ctx = new SvcLogicContext();
58 String key_content = "{\"name\":\"LOCAL_ACCESS_IP_ADDR\",\"description\":\"this is the node0 tacplus server IP address\",\"type\":"
59 + "\"ipv4_address\",\"required\":true,\"source\":\"INSTAR\",\"rule-type\":\"interface-ip-address\",\"default\":null,\"request-keys\":"
60 + "null,\"response-keys\":[{\"unique-key-name\":\"addressfqdn\",\"unique-key-value\":\"00000000000000\",\"field-key-name\":\"ipaddress-v4\"}]}";
61 Map<String, String> inParams = new HashMap<String, String>();
62 inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
63 inParams.put(InstarClientConstant.INSTAR_KEYS, "LOCAL_ACCESS_IP_ADDR");
64 inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
65 ctx.setAttribute("INSTAR.LOCAL_ACCESS_IP_ADDR", key_content);
66 ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
67 ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v");
68 SourceSystemNode icn = PowerMockito.spy(new SourceSystemNode());
69 RuleHandlerInterface mockRuleHandler = Mockito.mock(InterfaceIpAddressImpl.class);
70 Mockito.doReturn(mockRuleHandler).when(icn).createHandler(Mockito.any(), Mockito.any());
71 Mockito.doNothing().when(mockRuleHandler).processRule();
72 icn.getInstarInfo(inParams, ctx);
73 Log.info(ctx.getStatus());
74 Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("" + InstarClientConstant.OUTPUT_PARAM_STATUS));
78 public void testSourceSystemNodeFailure() throws Exception {
79 SvcLogicContext ctx = new SvcLogicContext();
80 String key_content = "{\"name\":\"LOCAL_ACCESS_IP_ADDR\",\"description\":\"this is the node0 tacplus server IP address\",\"type\":"
81 + "\"ipv4_address\",\"required\":true,\"source\":\"INSTAR\",\"rule-type\":\"NON_INTERFACE_IP_ADDRESS\",\"default\":null,\"request-keys\":"
82 + "null,\"response-keys\":[{\"unique-key-name\":\"addressfqdn\",\"unique-key-value\":\"00000000000000\",\"field-key-name\":\"ipaddress-v4\"}]}";
83 Log.info(key_content);
84 Map<String, String> inParams = new HashMap<String, String>();
85 inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST");
86 inParams.put(InstarClientConstant.INSTAR_KEYS, "LOCAL_ACCESS_IP_ADDR");
87 inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
88 ctx.setAttribute("INSTAR.LOCAL_ACCESS_IP_ADDR", key_content);
89 ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST");
90 ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v");
91 SourceSystemNode icn = new SourceSystemNode();
92 expectedEx.expect(SvcLogicException.class);
93 expectedEx.expectMessage("No Rule Defined to process :");
94 icn.getInstarInfo(inParams, ctx);
98 public void testInstarData() throws Exception {
99 SourceSystemNode icn = Mockito.spy(new SourceSystemNode());
100 SvcLogicContext ctx = new SvcLogicContext ();
101 Map<String, String> inParams = new HashMap<String, String>();
102 InstarRestClientImpl mockRestClient = Mockito.mock(InstarRestClientImpl.class);
103 Mockito.doReturn(mockRestClient).when(icn).createRestClientInterface(Mockito.any());
104 Mockito.doReturn("Test-data").when(mockRestClient).sendRequest(Mockito.anyString());
105 inParams.put(InstarClientConstant.VNF_NAME, "basx0003v");
106 inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
107 icn.getInstarData(inParams, ctx);
108 Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("" + InstarClientConstant.OUTPUT_PARAM_STATUS));
109 Assert.assertEquals("Test-data", ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
113 public void testInstarDataFailure() throws Exception {
114 SourceSystemNode icn = new SourceSystemNode();
115 SvcLogicContext ctx = new SvcLogicContext ();
116 Map<String, String> inParams = new HashMap<String, String>();
117 inParams.put(InstarClientConstant.VNF_NAME, "basx0003v");
118 inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
119 expectedEx.expect(SvcLogicException.class);
120 //expectedEx.expectMessage("Cannot find Property file -SDNC_CONFIG_DIR");
121 icn.getInstarData(inParams, ctx);
125 public void TestGetAaiInfo() throws Exception {
126 SourceSystemNode aaiNode=new SourceSystemNode();
127 Map<String, String> inParams=new HashMap<String, String> ();
128 SvcLogicContext ctx=new SvcLogicContext();
129 String keyVals = new String("[\"vnf_name\"]");
130 inParams.put("aaiKeys",keyVals);
131 inParams.put("responsePrefix","test");
132 String parameterString="{\"name\":\"vnf_name\",\"description\":null,\"type\":null,\"required\":false,\"source\":\"A&AI\","
133 + "\"rule-type\":\"vnf-name\",\"default\":null,\"request-keys\":null,\"response-keys\":[{\"unique-key-name\":\"parent-name\","
134 + "\"unique-key-value\":\"vnf\",\"field-key-name\":\"vnf-name\",\"filter-by-field\":null,\"filter-by-value\":null}]}";
135 ctx.setAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + "vnf_name",parameterString);
136 aaiNode.getAaiInfo(inParams, ctx);
137 Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("test." + InstarClientConstant.OUTPUT_PARAM_STATUS));
141 public void TestGetAaiInfoFailure() throws Exception {
142 SourceSystemNode aaiNode=new SourceSystemNode();
143 Map<String, String> inParams= Mockito.spy(new HashMap<String, String> ());
144 inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
145 Mockito.doThrow(new RuntimeException("Test-exception")).when(inParams).get(AaiClientConstant.AAI_KEYS);
146 SvcLogicContext ctx=new SvcLogicContext();
147 expectedEx.expect(SvcLogicException.class);
148 expectedEx.expectMessage("Test-exception");
149 aaiNode.getAaiInfo(inParams, ctx);