Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 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 | |
| 17 | package org.onosproject.ui.impl.gui2; |
| 18 | |
| 19 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.fasterxml.jackson.databind.module.SimpleModule; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | import org.onosproject.ui.UiExtension; |
| 25 | import org.onosproject.ui.UiView; |
| 26 | |
| 27 | import java.util.ArrayList; |
| 28 | import java.util.List; |
| 29 | |
| 30 | import static org.junit.Assert.assertEquals; |
| 31 | |
| 32 | public class UiViewSerializerTest { |
| 33 | |
| 34 | UiView uiView1 = new UiView(UiView.Category.NETWORK, "uiView1", "uiView1", "icon1"); |
| 35 | UiView uiView2 = new UiView(UiView.Category.OTHER, "uiView2", "uiView2", "icon2"); |
| 36 | |
| 37 | @Before |
| 38 | public void init() { |
| 39 | } |
| 40 | |
| 41 | @Test |
| 42 | public void uiViewSerializerTest() throws JsonProcessingException { |
| 43 | UiViewSerializer serializer = new UiViewSerializer(UiView.class); |
| 44 | ObjectMapper mapper = new ObjectMapper(); |
| 45 | |
| 46 | SimpleModule module = |
| 47 | new SimpleModule("UiViewSerializer"); |
| 48 | module.addSerializer(serializer); |
| 49 | mapper.registerModule(module); |
| 50 | String ext = mapper.writeValueAsString(uiView1); |
| 51 | assertEquals("{\"id\":\"uiView1\",\"icon\":\"icon1\",\"cat\":\"NETWORK\",\"label\":\"uiView1\"}", ext); |
| 52 | } |
| 53 | } |