2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.listener.util;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
31 import java.io.Serializable;
32 import java.util.ArrayList;
33 import java.util.List;
35 import org.json.JSONObject;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.appc.listener.util.Mapper;
40 import com.fasterxml.jackson.annotation.JsonProperty;
41 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
43 public class TestMapper {
45 private String dummyJson = "{\"a\":\"%s\"}";
46 private DummyObj dummyObj = new DummyObj();
49 public static class DummyObj implements Serializable {
62 public void testGetMapper() {
63 assertNotNull(Mapper.getMapper());
67 public void testToJsonObject() {
69 out = Mapper.toJsonObject(".");
73 out = Mapper.toJsonObject(String.format(dummyJson, value));
75 assertEquals(value, out.get("a"));
79 public void testConstructor() {
80 // Only here for code coverage
81 Mapper m = new Mapper();
86 public void testMap() {
87 List<String> in = new ArrayList<String>();
91 List<DummyObj> out = Mapper.mapList(in, DummyObj.class);
93 assertTrue(out.isEmpty());
95 in.add(String.format(dummyJson, "1"));
96 in.add("{\"invalid\":\"yes\"}");
97 in.add(String.format(dummyJson, "2"));
99 out = Mapper.mapList(in, DummyObj.class);
101 assertEquals(2, out.size());
102 assertEquals("1", out.get(0).a);
103 assertEquals("2", out.get(1).a);