blob: 2596f7bef1f6c0c3687c6cd1493f78eb955acc69 [file] [log] [blame]
Ray Milkey201f04b2017-09-25 10:13:19 -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.net.behaviour;
18
19import java.util.List;
20import java.util.Optional;
21
22import org.junit.Test;
23import org.onlab.packet.VlanId;
24
25import com.google.common.collect.ImmutableList;
26
27import static org.hamcrest.MatcherAssert.assertThat;
28import static org.hamcrest.Matchers.containsString;
29import static org.hamcrest.Matchers.is;
30import static org.hamcrest.Matchers.notNullValue;
31import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
32
33public class DefaultMirroringDescriptionTest {
34
35 private static final MirroringName NAME_1 = MirroringName.mirroringName("mirror1");
36 private static final List<String> MONITOR_SRC_PORTS_1 =
37 ImmutableList.of("s1", "s2", "s3");
38 private static final List<String> MONITOR_DST_PORTS_1 =
39 ImmutableList.of("d1", "d2");
40 private static final List<VlanId> MONITOR_VLANS_1 = ImmutableList.of(VlanId.ANY);
41 private static final Optional<String> MIRROR_PORT_1 = Optional.of("port1");
42 private static final Optional<VlanId> MIRROR_VLAN_1 = Optional.of(VlanId.ANY);
43 private MirroringDescription md1 =
44 new DefaultMirroringDescription(NAME_1, MONITOR_SRC_PORTS_1,
45 MONITOR_DST_PORTS_1, MONITOR_VLANS_1,
46 MIRROR_PORT_1, MIRROR_VLAN_1);
47
48
49 @Test
50 public void testImmutability() {
51 assertThatClassIsImmutable(DefaultMirroringDescription.class);
52 }
53
54 @Test
55 public void testConstruction() {
56 assertThat(md1.name(), is(NAME_1));
57 assertThat(md1.monitorSrcPorts(), is(MONITOR_SRC_PORTS_1));
58 assertThat(md1.monitorDstPorts(), is(MONITOR_DST_PORTS_1));
59 assertThat(md1.monitorVlans(), is(MONITOR_VLANS_1));
60 assertThat(md1.mirrorPort(), is(MIRROR_PORT_1));
61 assertThat(md1.mirrorVlan(), is(MIRROR_VLAN_1));
62 }
63
64 @Test
65 public void testToString() {
66 String result = md1.toString();
67 assertThat(result, notNullValue());
68 assertThat(result, containsString("name=" + NAME_1.toString()));
69 assertThat(result, containsString("monitorsrcports=" + MONITOR_SRC_PORTS_1.toString()));
70 assertThat(result, containsString("monitordstports=" + MONITOR_DST_PORTS_1.toString()));
71 assertThat(result, containsString("monitorvlans=" + MONITOR_VLANS_1.toString()));
72 assertThat(result, containsString("mirrorport=" + MIRROR_PORT_1.toString()));
73 assertThat(result, containsString("mirrorvlan=" + MIRROR_VLAN_1.toString()));
74 }
75}