Remove ECOMP in headers
[clamp.git] / src / test / java / org / onap / clamp / clds / util / JacksonUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * 
22  */
23
24 package org.onap.clamp.clds.util;
25
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28
29 import com.fasterxml.jackson.core.JsonParseException;
30 import com.fasterxml.jackson.databind.JsonMappingException;
31
32 import java.io.IOException;
33
34 import org.junit.Test;
35
36 public class JacksonUtilsTest {
37
38     public static class TestClass extends TestObject {
39
40         String test2;
41         TestObject2 object2;
42
43         public TestClass(String value1, String value2) {
44             super(value1);
45             test2 = value2;
46         }
47
48         public TestClass() {
49         }
50
51         public String getTest2() {
52             return test2;
53         }
54
55         public void setTest2(String test2) {
56             this.test2 = test2;
57         }
58
59         public TestObject2 getObject2() {
60             return object2;
61         }
62
63         public void setObject2(TestObject2 object2) {
64             this.object2 = object2;
65         }
66     }
67
68     @Test
69     public void testGetObjectMapperInstance() {
70         assertNotNull(JacksonUtils.getObjectMapperInstance());
71     }
72
73     /**
74      * This method test that the security hole in Jackson is not enabled in the
75      * default ObjectMapper.
76      * 
77      * @throws JsonParseException
78      *             In case of issues
79      * @throws JsonMappingException
80      *             In case of issues
81      * @throws IOException
82      *             In case of issues
83      */
84     @Test
85     public void testCreateBeanDeserializer() throws JsonParseException, JsonMappingException, IOException {
86         TestClass test = new TestClass("value1", "value2");
87         test.setObject2(new TestObject2("test3"));
88         Object testObject = JacksonUtils.getObjectMapperInstance().readValue(
89                 "[\"org.onap.clamp.clds.util.JacksonUtilsTest$TestClass\",{\"test\":\"value1\",\"test2\":\"value2\",\"object2\":[\"org.onap.clamp.clds.util.TestObject2\",{\"test3\":\"test3\"}]}]",
90                 Object.class);
91         assertNotNull(testObject);
92         assertFalse(testObject instanceof TestObject);
93         assertFalse(testObject instanceof TestClass);
94     }
95 }