2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
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.onap.aai.sparky.util;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
29 import java.io.IOException;
30 import java.util.ArrayList;
32 import org.junit.Before;
33 import org.junit.Test;
35 import com.fasterxml.jackson.core.JsonProcessingException;
36 import com.fasterxml.jackson.databind.JsonNode;
37 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
39 public class NodeUtilsTest {
42 private NodeUtils nodeUtils;
43 private JsonNode jsonNode, jsonNode2;
44 private ArrayList<String> lst;
48 public void init() throws Exception {
49 nodeUtils = new NodeUtils();
50 jsonNode = JsonNodeFactory.instance.objectNode();
52 lst = new ArrayList<String>();
56 @SuppressWarnings("static-access")
58 public void updateValues() throws IOException {
61 assertNotNull(nodeUtils.buildDepthPadding(2));
62 assertTrue(nodeUtils.isNumeric("234"));
63 assertNull(nodeUtils.calculateEditAttributeUri(null));
64 assertNotNull(nodeUtils.generateUniqueShaDigest("unique-101"));
65 assertNull(nodeUtils.getNodeFieldAsText(jsonNode,""));
66 assertNotNull(nodeUtils.getDurationBreakdown(2));
67 assertTrue(nodeUtils.isEqual(jsonNode,jsonNode2));
68 assertNotNull(nodeUtils.concatArray(lst));
69 assertNotNull(nodeUtils.concatArray(lst," "));
70 assertNotNull(nodeUtils.getDurationBreakdown(2));
71 assertNotNull(nodeUtils.buildEntityResourceKey("vserver","1232342"));
72 assertNull(nodeUtils.extractResourceIdFromLink(null));
73 assertNotNull(nodeUtils.getXmlStreamConstantAsStr(2));
74 assertNotNull(nodeUtils.convertObjectToJson(obj,false));
75 assertNull(nodeUtils.convertJsonStrToJsonNode(null));
76 assertNull(nodeUtils.extractObjectValueByKey(null,null));
77 assertNull(nodeUtils.extractFieldValueFromObject(null,null));
83 public void extractOxmVersionFromPath() {
84 assertEquals("8",NodeUtils.extractOxmVersionFromPath("test_oxm_v8.xml"));
85 assertEquals("9",NodeUtils.extractOxmVersionFromPath("test_oxm_v9.xml"));
86 assertEquals("11",NodeUtils.extractOxmVersionFromPath("test_oxm_v11.xml"));
87 assertEquals("11",NodeUtils.extractOxmVersionFromPath("test_oxm_v11.json"));
88 assertEquals("11",NodeUtils.extractOxmVersionFromPath("test_oxm_v11other.json"));
89 assertEquals("11",NodeUtils.extractOxmVersionFromPath("/path_v10/test_oxm_v11.xml"));
90 assertEquals("11",NodeUtils.extractOxmVersionFromPath("\\pathv10\\test_oxm_v11.xml"));