summaryrefslogtreecommitdiffstats
path: root/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/NodeUtilsTest.java
blob: e24d1647d88ae5c5b5ab5f4f6d7a7d9d5abdcc73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
 * Copyright © 2017-2018 Amdocs
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.aai.sparky.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;

public class NodeUtilsTest {


  private NodeUtils nodeUtils;
  private JsonNode jsonNode, jsonNode2;
  private ArrayList<String> lst;
  private Object obj;

  @Before
  public void init() throws Exception {
    nodeUtils = new NodeUtils();
    jsonNode = JsonNodeFactory.instance.objectNode();
    jsonNode2 = jsonNode;
    lst = new ArrayList<String>();
    obj = new Object();
  }

  @SuppressWarnings("static-access")
  @Test
  public void updateValues() throws IOException {


      assertNotNull(nodeUtils.buildDepthPadding(2));
      assertTrue(nodeUtils.isNumeric("234"));
      assertNull(nodeUtils.calculateEditAttributeUri(null));
      assertNotNull(nodeUtils.generateUniqueShaDigest("unique-101"));
      assertNull(nodeUtils.getNodeFieldAsText(jsonNode,""));
      assertNotNull(nodeUtils.getDurationBreakdown(2));
      assertTrue(nodeUtils.isEqual(jsonNode,jsonNode2));
      assertNotNull(nodeUtils.concatArray(lst));
      assertNotNull(nodeUtils.concatArray(lst," "));
      assertNotNull(nodeUtils.getDurationBreakdown(2));
      assertNotNull(nodeUtils.buildEntityResourceKey("vserver","1232342"));
      assertNull(nodeUtils.extractResourceIdFromLink(null));
      assertNotNull(nodeUtils.getXmlStreamConstantAsStr(2));
      assertNotNull(nodeUtils.convertObjectToJson(obj,false));
      assertNull(nodeUtils.convertJsonStrToJsonNode(null));
      assertNull(nodeUtils.extractObjectValueByKey(null,null));
      assertNull(nodeUtils.extractFieldValueFromObject(null,null));


  }

  @Test
  public void extractOxmVersionFromPath() {
    assertEquals("8",NodeUtils.extractOxmVersionFromPath("test_oxm_v8.xml"));
    assertEquals("9",NodeUtils.extractOxmVersionFromPath("test_oxm_v9.xml"));
    assertEquals("11",NodeUtils.extractOxmVersionFromPath("test_oxm_v11.xml"));
    assertEquals("11",NodeUtils.extractOxmVersionFromPath("test_oxm_v11.json"));
    assertEquals("11",NodeUtils.extractOxmVersionFromPath("test_oxm_v11other.json"));
    assertEquals("11",NodeUtils.extractOxmVersionFromPath("/path_v10/test_oxm_v11.xml"));
    assertEquals("11",NodeUtils.extractOxmVersionFromPath("\\pathv10\\test_oxm_v11.xml"));
  }
}