Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 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 | package org.onosproject.net.intent; |
| 17 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 18 | import java.util.Optional; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 19 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.MplsLabel; |
| 23 | import org.onosproject.net.Path; |
| 24 | import org.onosproject.net.flow.TrafficSelector; |
| 25 | import org.onosproject.net.flow.TrafficTreatment; |
| 26 | |
| 27 | import com.google.common.testing.EqualsTester; |
| 28 | |
| 29 | import static org.hamcrest.MatcherAssert.assertThat; |
| 30 | import static org.hamcrest.Matchers.is; |
| 31 | import static org.hamcrest.core.IsEqual.equalTo; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 32 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 33 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 34 | import static org.onosproject.net.NetTestTools.createPath; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Unit tests for the MplsPathIntent class. |
| 38 | */ |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 39 | public 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 fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 50 | static final Key KEY1 = Key.of(5L, APP_ID); |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 51 | |
| 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 fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 62 | .key(KEY1) |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 63 | .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 Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Checks that the MplsPathIntent class is immutable. |
| 81 | */ |
| 82 | @Test |
| 83 | public void testImmutability() { |
| 84 | assertThatClassIsImmutable(MplsPathIntent.class); |
| 85 | } |
| 86 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 87 | /** |
| 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 fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 110 | assertThat(intent1.key(), equalTo(KEY1)); |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 113 | } |