e3b77604a9b5e907c6e757efc0351f05007d466a
[aai/traversal.git] / aai-traversal / src / test / java / org / openecomp / aai / transforms / MapTraverserTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.aai.transforms;
22
23 import org.openecomp.aai.transforms.LowerCamelToLowerHyphenConverter;
24 import org.openecomp.aai.transforms.MapTraverser;
25 import com.bazaarvoice.jolt.JsonUtils;
26 import org.junit.Test;
27
28 import java.io.IOException;
29 import java.util.Map;
30
31 public class MapTraverserTest {
32
33     private final String testResources = "src/test/resources/maputils/testcases/";
34
35     private String[] testCases = { "TestCase1.json", "TestCase2.json" };
36     private MapTraverser traverser = new MapTraverser(new LowerCamelToLowerHyphenConverter());
37
38     @Test(expected = NullPointerException.class)
39     public void testIfMapIsNullThrowNullPointerException(){
40         Map<String, Object> map = null;
41         traverser.convertKeys(map);
42     }
43
44     @Test
45     public void runTestCases() throws IOException {
46
47         for(String testCase : testCases){
48             Map<String, Object> values = JsonUtils.filepathToMap(testResources + testCase);
49
50             Object input = values.get("input");
51             Object actual = traverser.convertKeys((Map<String, Object>)input);
52             Object output = values.get("output");
53             JoltTestUtil.runArrayOrderObliviousDiffy( "failed case " + testCase, output, actual );
54         }
55     }
56 }