blob: ff9d24c886a6c8c51debe93161cc86a7fb18ff1d [file] [log] [blame]
chengfan9d60b6e2016-12-01 11:06:39 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
chengfan9d60b6e2016-12-01 11:06:39 +08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.provider.te.utils;
18
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.node.ObjectNode;
21import org.junit.Assert;
22import org.junit.Before;
23import org.junit.Test;
24
25import static org.junit.Assert.assertEquals;
26
27/**
28 * Unit test for codec tools.
29 */
30public class CodecToolsTest {
31 private static final ObjectMapper MAP = new ObjectMapper();
32 private final ObjectNode simpleObject = MAP.createObjectNode();
33 private String simpleString;
34
35
36 @Before
37 public void setup() throws Exception {
38 simpleObject.put("field1", 1);
39 simpleString = "{\n" +
40 " \"field1\" : 1\n" +
41 "}";
42 }
43
44 @Test
45 public void toJson() throws Exception {
46 Assert.assertEquals(simpleObject, CodecTools.toJson(simpleString));
47 }
48
49 @Test
50 public void jsonToString() throws Exception {
51 assertEquals(simpleString, CodecTools.jsonToString(simpleObject));
52 }
53}