blob: e2c853ac47d042ec0dbbac3f92d0df8d85745826 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-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 */
16package org.onosproject.cfm.web;
17
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertNull;
20
21import java.io.ByteArrayInputStream;
22import java.io.IOException;
23import java.io.InputStream;
24import java.nio.charset.StandardCharsets;
25
26import org.junit.Before;
27import org.junit.Test;
28import org.onosproject.cfm.CfmCodecContext;
29import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate;
30
31import com.fasterxml.jackson.core.JsonProcessingException;
32import com.fasterxml.jackson.databind.JsonNode;
33import com.fasterxml.jackson.databind.ObjectMapper;
34import com.fasterxml.jackson.databind.node.ObjectNode;
35
36public class MepLbCreateCodecTest {
37 ObjectMapper mapper;
38 CfmCodecContext context;
39
40 @Before
41 public void setUp() throws Exception {
42 mapper = new ObjectMapper();
43 context = new CfmCodecContext();
44 }
45
46 @Test
47 public void testDecodeMepLbCreateMepId() throws JsonProcessingException, IOException {
48 String loopbackString = "{\"loopback\": { \"remoteMepId\": 20," +
49 "\"numberMessages\": 10, \"vlanDropEligible\": true," +
50 "\"vlanPriority\": 6, \"dataTlvHex\": \"0A:BB:CC\" }}";
51
52 InputStream input = new ByteArrayInputStream(
53 loopbackString.getBytes(StandardCharsets.UTF_8));
54 JsonNode cfg = mapper.readTree(input);
55 MepLbCreate mepLbCreate = context
56 .codec(MepLbCreate.class).decode((ObjectNode) cfg, context);
57
58 assertNull(mepLbCreate.remoteMepAddress());
59 assertEquals(20, mepLbCreate.remoteMepId().id().shortValue());
60 assertEquals(10, mepLbCreate.numberMessages().intValue());
61 assertEquals(6, mepLbCreate.vlanPriority().ordinal());
62 assertEquals(true, mepLbCreate.vlanDropEligible());
63 assertEquals("0A:BB:CC".toLowerCase(), mepLbCreate.dataTlvHex());
64 }
65
66 @Test
67 public void testDecodeMepLbCreateMepMac() throws JsonProcessingException, IOException {
68 String loopbackString = "{\"loopback\": { " +
69 "\"remoteMepMac\": \"AA:BB:CC:DD:EE:FF\" }}";
70 InputStream input = new ByteArrayInputStream(
71 loopbackString.getBytes(StandardCharsets.UTF_8));
72 JsonNode cfg = mapper.readTree(input);
73 MepLbCreate mepLbCreate = context
74 .codec(MepLbCreate.class).decode((ObjectNode) cfg, context);
75
76 assertNull(mepLbCreate.remoteMepId());
77 assertEquals("AA:BB:CC:DD:EE:FF", mepLbCreate.remoteMepAddress().toString());
78 assertNull(mepLbCreate.dataTlvHex());
79 }
80}