2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
27 package org.onap.clamp.clds.util;
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertNotNull;
32 import java.io.IOException;
34 import org.junit.Test;
36 public class JsonUtilsTest {
38 public static class TestClass extends TestObject {
43 TestClass(String value1, String value2) {
48 void setObject2(TestObject2 object2) {
49 this.object2 = object2;
54 public void testGetObjectMapperInstance() {
55 assertNotNull(JsonUtils.GSON);
59 * This method test that the security hole in GSON is not enabled in the default
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);
73 @Test(expected = IllegalArgumentException.class)
74 public void shouldThrowExceptionFileNotExists() throws IOException {
75 ResourceFileUtil.getResourceAsString("example/notExist.json");