2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli.SliPluginUtils;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
27 import java.util.HashMap;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.openecomp.sdnc.sli.SvcLogicContext;
33 import org.openecomp.sdnc.sli.SvcLogicException;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class SliPluginUtils_StaticFunctions {
38 private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtils_StaticFunctions.class);
39 SliPluginUtils utils = new SliPluginUtils();
40 private SvcLogicContext ctx;
41 private HashMap<String,String> parameters;
45 public void setUp() throws Exception {
46 this.ctx = new SvcLogicContext();
47 parameters = new HashMap<>();
52 public final void testCtxGetBeginsWith() {
53 ctx.setAttribute("service-data.oper-status.order-status", "InProgress");
54 ctx.setAttribute("service-data.service-information.service-instance-id", "USOSTCDALTX0101UJZZ01");
55 ctx.setAttribute("service-data.service-information.service-type", "VMS");
57 Map<String, String> entries = SliPluginUtils.ctxGetBeginsWith(ctx, "service-data.service-information");
59 assertEquals( "USOSTCDALTX0101UJZZ01", entries.get("service-data.service-information.service-instance-id") );
60 assertEquals( "VMS", entries.get("service-data.service-information.service-type") );
61 assertFalse( entries.containsKey("service-data.oper-status.order-status") );
66 public final void testCtxListRemove_index() throws SvcLogicException {
67 LOG.trace("=== testCtxListRemove_index ===");
68 ctx.setAttribute("service-data.vnf-l3[0].vnf-host-name", "vnf-host-name_0");
69 ctx.setAttribute("service-data.vnf-l3[0].device-host-name", "device-host-name_0");
70 ctx.setAttribute("service-data.vnf-l3[1].vnf-host-name", "vnf-host-name_1");
71 ctx.setAttribute("service-data.vnf-l3[1].device-host-name", "device-host-name_1");
72 ctx.setAttribute("service-data.vnf-l3[2].vnf-host-name", "vnf-host-name_2");
73 ctx.setAttribute("service-data.vnf-l3[2].device-host-name", "device-host-name_2");
74 ctx.setAttribute("service-data.vnf-l3_length", "3");
76 parameters.put("index", "1");
77 parameters.put("list_pfx", "service-data.vnf-l3");
79 utils.ctxListRemove( parameters, ctx );
80 SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE);
82 assertEquals("2", ctx.getAttribute("service-data.vnf-l3_length"));
83 assertEquals("vnf-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].vnf-host-name"));
84 assertEquals("device-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].device-host-name"));
85 assertEquals("vnf-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].vnf-host-name"));
86 assertEquals("device-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].device-host-name"));
91 public final void textCtxListRemove_keyValue() throws SvcLogicException {
92 LOG.trace("=== textCtxListRemove_keyValue ===");
93 ctx.setAttribute("service-data.vnf-l3[0].vnf-host-name", "vnf-host-name_0");
94 ctx.setAttribute("service-data.vnf-l3[0].device-host-name", "device-host-name_0");
95 ctx.setAttribute("service-data.vnf-l3[1].vnf-host-name", "vnf-host-name_1");
96 ctx.setAttribute("service-data.vnf-l3[1].device-host-name", "device-host-name_1");
97 ctx.setAttribute("service-data.vnf-l3[2].vnf-host-name", "vnf-host-name_2");
98 ctx.setAttribute("service-data.vnf-l3[2].device-host-name", "device-host-name_2");
100 ctx.setAttribute("service-data.vnf-l3[3].vnf-host-name", "vnf-host-name_1");
101 ctx.setAttribute("service-data.vnf-l3[3].device-host-name", "device-host-name_1");
102 ctx.setAttribute("service-data.vnf-l3_length", "4");
104 parameters.put("list_pfx", "service-data.vnf-l3");
105 parameters.put("key", "vnf-host-name");
106 parameters.put("value", "vnf-host-name_1");
108 utils.ctxListRemove( parameters, ctx );
109 SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE);
111 assertEquals("2", ctx.getAttribute("service-data.vnf-l3_length"));
112 assertEquals("vnf-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].vnf-host-name"));
113 assertEquals("device-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].device-host-name"));
114 assertEquals("vnf-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].vnf-host-name"));
115 assertEquals("device-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].device-host-name"));
120 public final void textCtxListRemove_keyValue_nullkey() throws SvcLogicException {
121 LOG.trace("=== textCtxListRemove_keyValue_nullkey ===");
122 ctx.setAttribute("service-data.vnf-l3[0]", "vnf-host-name_0");
123 ctx.setAttribute("service-data.vnf-l3[1]", "vnf-host-name_1");
124 ctx.setAttribute("service-data.vnf-l3[2]", "vnf-host-name_2");
125 ctx.setAttribute("service-data.vnf-l3_length", "3");
127 parameters.put("list_pfx", "service-data.vnf-l3");
128 parameters.put("value", "vnf-host-name_1");
130 utils.ctxListRemove( parameters, ctx );
131 SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE);
133 assertEquals("2", ctx.getAttribute("service-data.vnf-l3_length"));
134 assertEquals("vnf-host-name_0", ctx.getAttribute("service-data.vnf-l3[0]"));
135 assertEquals("vnf-host-name_2", ctx.getAttribute("service-data.vnf-l3[1]"));
140 public final void textCtxListRemove_keyValueList() throws SvcLogicException {
141 LOG.trace("=== textCtxListRemove_keyValueList ===");
142 ctx.setAttribute("service-data.vnf-l3[0].vnf-host-name", "vnf-host-name_0");
143 ctx.setAttribute("service-data.vnf-l3[0].device-host-name", "device-host-name_0");
144 ctx.setAttribute("service-data.vnf-l3[1].vnf-host-name", "vnf-host-name_1");
145 ctx.setAttribute("service-data.vnf-l3[1].device-host-name", "device-host-name_1");
146 ctx.setAttribute("service-data.vnf-l3[2].vnf-host-name", "vnf-host-name_2");
147 ctx.setAttribute("service-data.vnf-l3[2].device-host-name", "device-host-name_2");
149 ctx.setAttribute("service-data.vnf-l3[3].vnf-host-name", "vnf-host-name_1");
150 ctx.setAttribute("service-data.vnf-l3[3].device-host-name", "device-host-name_1");
151 // entries with only 1 of 2 key-value pairs matching
152 ctx.setAttribute("service-data.vnf-l3[4].vnf-host-name", "vnf-host-name_1");
153 ctx.setAttribute("service-data.vnf-l3[4].device-host-name", "device-host-name_4");
154 ctx.setAttribute("service-data.vnf-l3[5].vnf-host-name", "vnf-host-name_5");
155 ctx.setAttribute("service-data.vnf-l3[5].device-host-name", "device-host-name_1");
156 ctx.setAttribute("service-data.vnf-l3_length", "6");
158 parameters.put("list_pfx", "service-data.vnf-l3");
159 parameters.put("keys_length", "2");
160 parameters.put("keys[0].key", "vnf-host-name");
161 parameters.put("keys[0].value", "vnf-host-name_1");
162 parameters.put("keys[1].key", "device-host-name");
163 parameters.put("keys[1].value", "device-host-name_1");
165 utils.ctxListRemove( parameters, ctx );
166 SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE);
168 assertEquals("4", ctx.getAttribute("service-data.vnf-l3_length"));
169 assertEquals("vnf-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].vnf-host-name"));
170 assertEquals("device-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].device-host-name"));
171 assertEquals("vnf-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].vnf-host-name"));
172 assertEquals("device-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].device-host-name"));
173 assertEquals("vnf-host-name_1", ctx.getAttribute("service-data.vnf-l3[2].vnf-host-name"));
174 assertEquals("device-host-name_4", ctx.getAttribute("service-data.vnf-l3[2].device-host-name"));
175 assertEquals("vnf-host-name_5", ctx.getAttribute("service-data.vnf-l3[3].vnf-host-name"));
176 assertEquals("device-host-name_1", ctx.getAttribute("service-data.vnf-l3[3].device-host-name"));
180 @Test(expected=SvcLogicException.class)
181 public final void testCtxListRemove_nullListLength() throws SvcLogicException {
182 LOG.trace("=== testCtxListRemove_nullListLength ===");
183 ctx.setAttribute("service-data.vnf-l3[0].vnf-host-name", "vnf-host-name_0");
184 ctx.setAttribute("service-data.vnf-l3[0].device-host-name", "device-host-name_0");
185 ctx.setAttribute("service-data.vnf-l3[1].vnf-host-name", "vnf-host-name_1");
186 ctx.setAttribute("service-data.vnf-l3[1].device-host-name", "device-host-name_1");
187 ctx.setAttribute("service-data.vnf-l3[2].vnf-host-name", "vnf-host-name_2");
188 ctx.setAttribute("service-data.vnf-l3[2].device-host-name", "device-host-name_2");
191 parameters.put("index", "1");
192 parameters.put("list_pfx", "service-data.vnf-l3");
194 utils.ctxListRemove( parameters, ctx );
199 public final void testCtxPutAll() {
200 HashMap<String, Object> entries = new HashMap<>();
201 entries.put("service-data.oper-status.order-status", "InProgress");
202 entries.put("service-data.service-information.service-instance-id", "USOSTCDALTX0101UJZZ01");
203 entries.put("service-data.request-information.order-number", 1234);
204 entries.put("service-data.request-information.request-id", null);
206 SliPluginUtils.ctxPutAll(ctx, entries);
208 assertEquals( "InProgress", ctx.getAttribute("service-data.oper-status.order-status") );
209 assertEquals( "USOSTCDALTX0101UJZZ01", ctx.getAttribute("service-data.service-information.service-instance-id") );
210 assertEquals( "1234", ctx.getAttribute("service-data.request-information.order-number") );
211 assertFalse( ctx.getAttributeKeySet().contains("service-data.request-information.request-id") );
216 public final void testCtxSetAttribute_LOG() {
217 LOG.debug("=== testCtxSetAttribute_LOG ===");
218 Integer i = new Integer(3);
219 SliPluginUtils.ctxSetAttribute(ctx, "test", i, LOG, SliPluginUtils.LogLevel.TRACE);