blob: 551f19eb8e5a4cb5dd607d8c5e6ad7fc62b9271a [file] [log] [blame]
Ray Milkeybd4f0112015-03-02 17:07:09 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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.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;
50
51 @Before
52 public void mplsPathIntentTestSetUp() {
53 defaultPath = createPath("a", "b", "c");
54 selector = new IntentTestsMocks.MockSelector();
55 treatment = new IntentTestsMocks.MockTreatment();
56
57 label1 = Optional.of(MplsLabel.mplsLabel(1));
58 label2 = Optional.of(MplsLabel.mplsLabel(2));
59 intent1 = MplsPathIntent.builder()
60 .appId(APP_ID)
61 .ingressLabel(label1)
62 .egressLabel(label2)
63 .path(defaultPath)
64 .priority(PRIORITY)
65 .build();
66
67 intent2 = MplsPathIntent.builder()
68 .appId(APP_ID)
69 .ingressLabel(label1)
70 .egressLabel(label2)
71 .path(defaultPath)
72 .priority(PRIORITY)
73 .build();
74 }
75
Ray Milkeybd4f0112015-03-02 17:07:09 -080076
77 /**
78 * Checks that the MplsPathIntent class is immutable.
79 */
80 @Test
81 public void testImmutability() {
82 assertThatClassIsImmutable(MplsPathIntent.class);
83 }
84
Ray Milkeya05fd202015-04-27 15:27:30 -070085 /**
86 * Checks the operation of equals(), hashCode() and toString() methods.
87 */
88 @Test
89 public void testEquals() {
90 new EqualsTester()
91 .addEqualityGroup(intent1)
92 .addEqualityGroup(intent2)
93 .testEquals();
94 }
95
96 /**
97 * Checks that the MPLS path intent objects are created correctly.
98 */
99 @Test
100 public void testContents() {
101 assertThat(intent1.appId(), equalTo(APP_ID));
102 assertThat(intent1.ingressLabel(), equalTo(label1));
103 assertThat(intent1.egressLabel(), equalTo(label2));
104 assertThat(intent1.selector(), equalTo(intent2.selector()));
105 assertThat(intent1.treatment(), equalTo(intent2.treatment()));
106 assertThat(intent1.priority(), is(PRIORITY));
107 assertThat(intent1.path(), is(defaultPath));
108 }
109
Ray Milkeybd4f0112015-03-02 17:07:09 -0800110}