blob: 7ad77ac0acc07b51ceac8e10a60e021e0f2de4c6 [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;
19
20import java.time.Duration;
21import java.util.ArrayList;
22import java.util.Iterator;
23
24import org.junit.Before;
25import org.junit.Test;
26import org.onlab.packet.MacAddress;
27import org.onosproject.cfm.CfmCodecContext;
28import org.onosproject.incubator.net.l2monitoring.cfm.DefaultRemoteMepEntry;
29import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry;
30import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType;
31import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType;
32import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState;
33import org.onosproject.incubator.net.l2monitoring.cfm.SenderIdTlv.SenderIdTlvType;
34import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
35import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
36
37import com.fasterxml.jackson.databind.JsonNode;
38import com.fasterxml.jackson.databind.ObjectMapper;
39import com.fasterxml.jackson.databind.node.ObjectNode;
40
41public class RemoteMepEntryCodecTest {
42 ObjectMapper mapper;
43 CfmCodecContext context;
44 RemoteMepEntry remoteMep1;
45
46 @Before
47 public void setUp() throws Exception, CfmConfigException {
48 mapper = new ObjectMapper();
49 context = new CfmCodecContext();
50 remoteMep1 = DefaultRemoteMepEntry
51 .builder(MepId.valueOf((short) 10), RemoteMepState.RMEP_OK)
52 .failedOrOkTime(Duration.ofMillis(546546546L))
53 .interfaceStatusTlvType(InterfaceStatusTlvType.IS_LOWERLAYERDOWN)
54 .macAddress(MacAddress.IPV4_MULTICAST)
55 .portStatusTlvType(PortStatusTlvType.PS_NO_STATUS_TLV)
56 .rdi(true)
57 .senderIdTlvType(SenderIdTlvType.SI_NETWORK_ADDRESS)
58 .build();
59 }
60
61 @Test
62 public void testEncodeRemoteMepEntryCodecContext() {
63 ObjectNode node = mapper.createObjectNode();
64 node.set("remoteMep", context.codec(RemoteMepEntry.class)
65 .encode(remoteMep1, context));
66
67 assertEquals(10, node.get("remoteMep").get("remoteMepId").asInt());
68 }
69
70 @Test
71 public void testEncodeIterableOfRemoteMepEntryCodecContext()
72 throws CfmConfigException {
73 RemoteMepEntry remoteMep2 = DefaultRemoteMepEntry
74 .builder(MepId.valueOf((short) 20), RemoteMepState.RMEP_IDLE)
75 .build();
76
77 ArrayList<RemoteMepEntry> remoteMeps = new ArrayList<>();
78 remoteMeps.add(remoteMep1);
79 remoteMeps.add(remoteMep2);
80
81 ObjectNode node = mapper.createObjectNode();
82 node.set("remoteMep", context.codec(RemoteMepEntry.class)
83 .encode(remoteMeps, context));
84
85 Iterator<JsonNode> an = node.get("remoteMep").elements();
86 while (an.hasNext()) {
87 JsonNode jn = an.next();
88 assertEquals("RMEP_", jn.get("remoteMepState").asText().substring(0, 5));
89 }
90 }
91}