2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.listener.util;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
30 import java.io.Serializable;
31 import java.util.ArrayList;
32 import java.util.List;
34 import org.json.JSONObject;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.openecomp.appc.listener.util.Mapper;
39 import com.fasterxml.jackson.annotation.JsonProperty;
40 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
42 public class TestMapper {
44 private String dummyJson = "{\"a\":\"%s\"}";
45 private DummyObj dummyObj = new DummyObj();
48 public static class DummyObj implements Serializable {
61 public void testGetMapper() {
62 assertNotNull(Mapper.getMapper());
66 public void testToJsonObject() {
68 out = Mapper.toJsonObject(".");
72 out = Mapper.toJsonObject(String.format(dummyJson, value));
74 assertEquals(value, out.get("a"));
78 public void testConstructor() {
79 // Only here for code coverage
80 Mapper m = new Mapper();
85 public void testMap() {
86 List<String> in = new ArrayList<String>();
90 List<DummyObj> out = Mapper.mapList(in, DummyObj.class);
92 assertTrue(out.isEmpty());
94 in.add(String.format(dummyJson, "1"));
95 in.add("{\"invalid\":\"yes\"}");
96 in.add(String.format(dummyJson, "2"));
98 out = Mapper.mapList(in, DummyObj.class);
100 assertEquals(2, out.size());
101 assertEquals("1", out.get(0).a);
102 assertEquals("2", out.get(1).a);