2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.utils;
23 import static org.junit.Assert.assertEquals;
25 import org.junit.Test;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import com.fasterxml.jackson.annotation.JsonRootName;
29 import com.fasterxml.jackson.databind.ObjectMapper;
31 public class RootIgnoringObjectMapperTest {
34 public void someObjectWithoutRootTest() throws Exception {
35 ObjectMapper mapper = new RootIgnoringObjectMapper<SomeObject>(SomeObject.class);
38 + "\"attribute\":\"charm\""
41 SomeObject response = mapper.readValue(content, SomeObject.class);
42 assertEquals("SomeObject[attribute=charm]", response.toString());
46 public void someObjectWithRootTest() throws Exception {
47 ObjectMapper mapper = new RootIgnoringObjectMapper<SomeObject>(SomeObject.class);
49 String content = "{\"SomeObject\":{"
50 + "\"attribute\":\"charm\""
53 SomeObject response = mapper.readValue(content, SomeObject.class);
54 assertEquals("SomeObject[attribute=charm]", response.toString());
58 public void annotatedObjectWithoutRootTest() throws Exception {
59 ObjectMapper mapper = new RootIgnoringObjectMapper<AnnotatedObject>(AnnotatedObject.class);
62 + "\"attribute\":\"charm\""
65 AnnotatedObject response = mapper.readValue(content, AnnotatedObject.class);
66 assertEquals("AnnotatedObject[attribute=charm]", response.toString());
70 public void annotatedObjectWithRootTest() throws Exception {
71 ObjectMapper mapper = new RootIgnoringObjectMapper<AnnotatedObject>(AnnotatedObject.class);
73 String content = "{\"annotated-object\":{"
74 + "\"attribute\":\"charm\""
77 AnnotatedObject response = mapper.readValue(content, AnnotatedObject.class);
78 assertEquals("AnnotatedObject[attribute=charm]", response.toString());
81 public static class SomeObject {
83 @JsonProperty("attribute")
84 private String attribute;
86 public String toString() {
87 return getClass().getSimpleName() + "[attribute=" + attribute + "]";
91 @JsonRootName(value = "annotated-object")
92 public static class AnnotatedObject extends SomeObject {