blob: ea2c5e8f266babec2b2d16ebb202429a6992d113 [file] [log] [blame]
Simon Huntf257a962017-08-25 18:58:47 -07001/*
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 */
16
17package org.onosproject.ui.impl;
18
19import org.junit.Before;
20import org.junit.Test;
21import org.onosproject.driver.extensions.Ofdpa3SetMplsType;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.flow.instructions.ExtensionTreatment;
24import org.onosproject.net.flow.instructions.Instruction;
25import org.onosproject.net.flow.instructions.Instructions;
26
27import static org.junit.Assert.assertEquals;
28import static org.onosproject.net.DeviceId.deviceId;
29import static org.onosproject.net.PortNumber.portNumber;
30
31/**
32 * Unit tests for {@link FlowViewMessageHandler}.
33 */
34public class FlowViewMessageHandlerTest extends AbstractUiImplTest {
35
36 private static final String DEV_OF_204 = "of:0000000000000204";
37
38 private static final String EXT_FULL_STR =
39 "EXTENSION:of:0000000000000204/Ofdpa3SetMplsType{mplsType=32}";
40 private static final String EXT_NO_DPID =
41 "EXTENSION:Ofdpa3SetMplsType{mplsType=32}";
42
43 private FlowViewMessageHandler handler;
44 private Instruction instr;
45 private String string;
46 private String render;
47
48
49 @Before
50 public void setUp() {
51 handler = new FlowViewMessageHandler();
52 }
53
54 @Test
55 public void renderOutputInstruction() {
56 title("renderOutputInstruction");
57 instr = Instructions.createOutput(portNumber(4));
58 string = instr.toString();
59 render = handler.renderInstructionForDisplay(instr);
60
61 print(string);
62 assertEquals("not same output", string, render);
63 assertEquals("not output to port 4", "OUTPUT:4", render);
64 }
65
66
67 @Test
68 public void renderExtensionInstruction() {
69 title("renderExtensionInstruction");
70
71 ExtensionTreatment extn = new Ofdpa3SetMplsType((short) 32);
72 DeviceId devid = deviceId(DEV_OF_204);
73
74 instr = Instructions.extension(extn, devid);
75 string = instr.toString();
76 render = handler.renderInstructionForDisplay(instr);
77
78 print(string);
79 print(render);
80
81 assertEquals("unexpected toString", EXT_FULL_STR, string);
82 assertEquals("unexpected short string", EXT_NO_DPID, render);
83 }
84}