blob: 79d3a81d7b67492b18774bbe934324b0a7331f8d [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.Path;
24import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
26
27import com.google.common.testing.EqualsTester;
28
29import static org.hamcrest.MatcherAssert.assertThat;
30import static org.hamcrest.Matchers.is;
31import static org.hamcrest.core.IsEqual.equalTo;
Ray Milkeybd4f0112015-03-02 17:07:09 -080032import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ray Milkeya05fd202015-04-27 15:27:30 -070033import static org.onosproject.net.NetTestTools.APP_ID;
34import static org.onosproject.net.NetTestTools.createPath;
Ray Milkeybd4f0112015-03-02 17:07:09 -080035
36/**
37 * Unit tests for the MplsPathIntent class.
38 */
Ray Milkeya05fd202015-04-27 15:27:30 -070039public class MplsPathIntentTest extends AbstractIntentTest {
40
41 static final int PRIORITY = 777;
42
43 MplsPathIntent intent1;
44 MplsPathIntent intent2;
45 Path defaultPath;
46 Optional<MplsLabel> label1;
47 Optional<MplsLabel> label2;
48 TrafficSelector selector;
49 TrafficTreatment treatment;
ilhem fajjarib0a06842015-11-02 18:59:02 +010050 static final Key KEY1 = Key.of(5L, APP_ID);
Ray Milkeya05fd202015-04-27 15:27:30 -070051
52 @Before
53 public void mplsPathIntentTestSetUp() {
54 defaultPath = createPath("a", "b", "c");
55 selector = new IntentTestsMocks.MockSelector();
56 treatment = new IntentTestsMocks.MockTreatment();
57
58 label1 = Optional.of(MplsLabel.mplsLabel(1));
59 label2 = Optional.of(MplsLabel.mplsLabel(2));
60 intent1 = MplsPathIntent.builder()
61 .appId(APP_ID)
ilhem fajjarib0a06842015-11-02 18:59:02 +010062 .key(KEY1)
Ray Milkeya05fd202015-04-27 15:27:30 -070063 .ingressLabel(label1)
64 .egressLabel(label2)
65 .path(defaultPath)
66 .priority(PRIORITY)
67 .build();
68
69 intent2 = MplsPathIntent.builder()
70 .appId(APP_ID)
71 .ingressLabel(label1)
72 .egressLabel(label2)
73 .path(defaultPath)
74 .priority(PRIORITY)
75 .build();
76 }
77
Ray Milkeybd4f0112015-03-02 17:07:09 -080078
79 /**
80 * Checks that the MplsPathIntent class is immutable.
81 */
82 @Test
83 public void testImmutability() {
84 assertThatClassIsImmutable(MplsPathIntent.class);
85 }
86
Ray Milkeya05fd202015-04-27 15:27:30 -070087 /**
88 * Checks the operation of equals(), hashCode() and toString() methods.
89 */
90 @Test
91 public void testEquals() {
92 new EqualsTester()
93 .addEqualityGroup(intent1)
94 .addEqualityGroup(intent2)
95 .testEquals();
96 }
97
98 /**
99 * Checks that the MPLS path intent objects are created correctly.
100 */
101 @Test
102 public void testContents() {
103 assertThat(intent1.appId(), equalTo(APP_ID));
104 assertThat(intent1.ingressLabel(), equalTo(label1));
105 assertThat(intent1.egressLabel(), equalTo(label2));
106 assertThat(intent1.selector(), equalTo(intent2.selector()));
107 assertThat(intent1.treatment(), equalTo(intent2.treatment()));
108 assertThat(intent1.priority(), is(PRIORITY));
109 assertThat(intent1.path(), is(defaultPath));
ilhem fajjarib0a06842015-11-02 18:59:02 +0100110 assertThat(intent1.key(), equalTo(KEY1));
Ray Milkeya05fd202015-04-27 15:27:30 -0700111 }
112
Ray Milkeybd4f0112015-03-02 17:07:09 -0800113}