2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.listener.util;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertNull;
30 import static org.junit.Assert.assertTrue;
32 import java.io.Serializable;
33 import java.util.ArrayList;
34 import java.util.List;
36 import org.json.JSONObject;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.openecomp.appc.listener.util.Mapper;
41 import com.fasterxml.jackson.annotation.JsonProperty;
42 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
44 public class TestMapper {
46 private String dummyJson = "{\"a\":\"%s\"}";
47 private DummyObj dummyObj = new DummyObj();
50 public static class DummyObj implements Serializable {
63 public void testGetMapper() {
64 assertNotNull(Mapper.getMapper());
68 public void testToJsonObject() {
70 out = Mapper.toJsonObject(".");
74 out = Mapper.toJsonObject(String.format(dummyJson, value));
76 assertEquals(value, out.get("a"));
80 public void testConstructor() {
81 // Only here for code coverage
82 Mapper m = new Mapper();
87 public void testMap() {
88 List<String> in = new ArrayList<String>();
92 List<DummyObj> out = Mapper.mapList(in, DummyObj.class);
94 assertTrue(out.isEmpty());
96 in.add(String.format(dummyJson, "1"));
97 in.add("{\"invalid\":\"yes\"}");
98 in.add(String.format(dummyJson, "2"));
100 out = Mapper.mapList(in, DummyObj.class);
102 assertEquals(2, out.size());
103 assertEquals("1", out.get(0).a);
104 assertEquals("2", out.get(1).a);