2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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=========================================================
22 package org.openecomp.appc.listener.util;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
29 import java.io.Serializable;
30 import java.util.ArrayList;
31 import java.util.List;
33 import org.json.JSONObject;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.openecomp.appc.listener.util.Mapper;
38 import com.fasterxml.jackson.annotation.JsonProperty;
39 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
41 public class TestMapper {
43 private String dummyJson = "{\"a\":\"%s\"}";
44 private DummyObj dummyObj = new DummyObj();
47 public static class DummyObj implements Serializable {
60 public void testGetMapper() {
61 assertNotNull(Mapper.getMapper());
65 public void testToJsonObject() {
67 out = Mapper.toJsonObject(".");
71 out = Mapper.toJsonObject(String.format(dummyJson, value));
73 assertEquals(value, out.get("a"));
77 public void testConstructor() {
78 // Only here for code coverage
79 Mapper m = new Mapper();
84 public void testMap() {
85 List<String> in = new ArrayList<String>();
89 List<DummyObj> out = Mapper.mapList(in, DummyObj.class);
91 assertTrue(out.isEmpty());
93 in.add(String.format(dummyJson, "1"));
94 in.add("{\"invalid\":\"yes\"}");
95 in.add(String.format(dummyJson, "2"));
97 out = Mapper.mapList(in, DummyObj.class);
99 assertEquals(2, out.size());
100 assertEquals("1", out.get(0).a);
101 assertEquals("2", out.get(1).a);