Fix the ssl config
[clamp.git] / src / test / java / org / onap / clamp / clds / util / JsonUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END============================================
22  * Modifications copyright (c) 2019 Nokia
23  * ===================================================================
24  *
25  */
26
27 package org.onap.clamp.clds.util;
28
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertNotNull;
31
32 import java.io.IOException;
33
34 import org.junit.Test;
35
36 public class JsonUtilsTest {
37
38     public static class TestClass extends TestObject {
39
40         String test2;
41         TestObject2 object2;
42
43         TestClass(String value1, String value2) {
44             super(value1);
45             test2 = value2;
46         }
47
48         void setObject2(TestObject2 object2) {
49             this.object2 = object2;
50         }
51     }
52
53     @Test
54     public void testGetObjectMapperInstance() {
55         assertNotNull(JsonUtils.GSON);
56     }
57
58     /**
59      * This method test that the security hole in GSON is not enabled in the default
60      * ObjectMapper.
61      */
62     @Test
63     public void testCreateBeanDeserializer() {
64         TestClass test = new TestClass("value1", "value2");
65         test.setObject2(new TestObject2("test3"));
66         Object testObject = JsonUtils.GSON.fromJson("[\"org.onap.clamp.clds.util.JsonUtilsTest$TestClass\""
67                 + ",{\"test\":\"value1\",\"test2\":\"value2\",\"object2\":[\"org.onap.clamp.clds.util.TestObject2\","
68                 + "{\"test3\":\"test3\"}]}]", Object.class);
69         assertNotNull(testObject);
70         assertFalse(testObject instanceof TestObject);
71     }
72
73     @Test(expected = IllegalArgumentException.class)
74     public void shouldThrowExceptionFileNotExists() throws IOException {
75         ResourceFileUtils.getResourceAsString("example/notExist.json");
76     }
77 }