e98278288baa02115105e62e93d7b2da25103946
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / test / ResTest.java
1 import java.io.IOException;
2 import java.util.List;
3
4 import org.apache.log4j.Level;
5 import org.json.JSONException;
6 import org.json.JSONObject;
7 import org.opendaylight.mwtn.base.internalTypes.Resources;
8 import org.opendaylight.mwtn.config.impl.HtLogger;
9
10 public class ResTest {
11
12         private static void testDuplicateKeyJSON()
13         {
14                 try
15                 {
16                         String str=Resources.getFileContent("/elasticsearch/index/mwtn/modelDescription/CoreModel-ForMicrowave.json");
17
18                         JSONObject o=new JSONObject(str) {
19
20                                 @Override
21                                 public JSONObject putOnce(String key, Object value) throws JSONException {
22
23
24                                                 Object storedValue;
25                                                 if (key != null && value != null) {
26                                                         if ((storedValue = this.opt(key)) != null ) {
27                                                                 if(!storedValue.equals(value)) {                         //Only through Exception for different values with same key
28                                                                         //Replace
29                                                                         System.out.println("duplicate found");
30                                                                         this.remove(key);
31                                                                         this.put(key, value);
32
33                                                                 } else
34                                                                         return this;
35                                                         }
36                                                         else
37                                                                 this.put(key, value);
38                                                 }
39                                                 return this;
40                                 }
41                         };
42                         System.out.println(o.toString());
43                 }
44                 catch(IOException err)
45                 {
46                                 err.printStackTrace();
47                 }
48         }
49         public static void main(String[] args)
50         {
51                 HtLogger.initConsole(Level.DEBUG);
52                 JSONObject o=Resources.getJSONFile("/elasticsearch/index/sdnevents/sdneventsMapping.json");
53                 System.out.println(o==null?"null":o.toString());
54
55                 List<JSONObject> list=Resources.getJSONFiles("/elasticsearch/index", true);
56                 System.out.println("found "+list.size()+" valid json files");
57
58                 testDuplicateKeyJSON();
59
60         }
61 }