blob: 17e14b03b77a8b6133a220fe76acad4ff9a56007 [file] [log] [blame]
Ray Milkeybd4f0112015-03-02 17:07:09 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeybd4f0112015-03-02 17:07:09 -08003 *
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.net.intent;
17
Ray Milkeya05fd202015-04-27 15:27:30 -070018import java.util.Optional;
Ray Milkeybd4f0112015-03-02 17:07:09 -080019
Ray Milkeya05fd202015-04-27 15:27:30 -070020import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.MplsLabel;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25
26import com.google.common.testing.EqualsTester;
27
28import static org.hamcrest.MatcherAssert.assertThat;
29import static org.hamcrest.Matchers.is;
30import static org.hamcrest.core.IsEqual.equalTo;
Ray Milkeybd4f0112015-03-02 17:07:09 -080031import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ray Milkeya05fd202015-04-27 15:27:30 -070032import static org.onosproject.net.NetTestTools.APP_ID;
33import static org.onosproject.net.NetTestTools.connectPoint;
Ray Milkeybd4f0112015-03-02 17:07:09 -080034
35/**
36 * Unit tests for the MplsIntent class.
37 */
38
Ray Milkeya05fd202015-04-27 15:27:30 -070039public class MplsIntentTest extends AbstractIntentTest {
40 static final int PRIORITY = 22;
41
42 MplsIntent intent1;
43 MplsIntent intent2;
44
45 Optional<MplsLabel> label1;
46 Optional<MplsLabel> label2;
47
48 TrafficSelector selector;
49 TrafficTreatment treatment;
50
51 @Before
52 public void mplsIntentTestSetUp() throws Exception {
53
54 label1 = Optional.of(MplsLabel.mplsLabel(1));
55 label2 = Optional.of(MplsLabel.mplsLabel(2));
56
57 selector = new IntentTestsMocks.MockSelector();
58 treatment = new IntentTestsMocks.MockTreatment();
59
60 intent1 = MplsIntent.builder()
61 .appId(APP_ID)
62 .ingressLabel(label1)
63 .egressLabel(label2)
64 .ingressPoint(connectPoint("in", 1))
65 .egressPoint(connectPoint("out", 1))
66 .selector(selector)
67 .treatment(treatment)
68 .priority(PRIORITY)
69 .build();
70
71 intent2 = MplsIntent.builder()
72 .appId(APP_ID)
73 .ingressLabel(label1)
74 .egressLabel(label2)
75 .ingressPoint(connectPoint("in", 2))
76 .egressPoint(connectPoint("out", 2))
77 .selector(selector)
78 .treatment(treatment)
79 .priority(PRIORITY)
80 .build();
81 }
Ray Milkeybd4f0112015-03-02 17:07:09 -080082
83 /**
84 * Checks that the MplsIntent class is immutable.
85 */
86 @Test
87 public void testImmutability() {
88 assertThatClassIsImmutable(MplsIntent.class);
89 }
90
Ray Milkeya05fd202015-04-27 15:27:30 -070091 /**
92 * Checks the operation of equals(), hashCode() and toString() methods.
93 */
94 @Test
95 public void testEquals() {
96 new EqualsTester()
97 .addEqualityGroup(intent1)
98 .addEqualityGroup(intent2)
99 .testEquals();
100 }
101
102 /**
103 * Checks that the MplsIntent objects are created correctly.
104 */
105 @Test
106 public void testContents() {
107 assertThat(intent1.appId(), equalTo(APP_ID));
108 assertThat(intent1.ingressLabel(), equalTo(label1));
109 assertThat(intent1.egressLabel(), equalTo(label2));
110 assertThat(intent1.ingressPoint(), equalTo(connectPoint("in", 1)));
111 assertThat(intent1.egressPoint(), equalTo(connectPoint("out", 1)));
112 assertThat(intent1.selector(), equalTo(intent2.selector()));
113 assertThat(intent1.treatment(), equalTo(intent2.treatment()));
114 assertThat(intent1.priority(), is(PRIORITY));
Ray Milkeya05fd202015-04-27 15:27:30 -0700115 }
Ray Milkeybd4f0112015-03-02 17:07:09 -0800116}