Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 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.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
| 25 | |
| 26 | import com.google.common.testing.EqualsTester; |
| 27 | |
| 28 | import static org.hamcrest.MatcherAssert.assertThat; |
| 29 | import static org.hamcrest.Matchers.is; |
| 30 | import static org.hamcrest.core.IsEqual.equalTo; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 31 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 32 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 33 | import static org.onosproject.net.NetTestTools.connectPoint; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Unit tests for the MplsIntent class. |
| 37 | */ |
| 38 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 39 | public 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 Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * Checks that the MplsIntent class is immutable. |
| 85 | */ |
| 86 | @Test |
| 87 | public void testImmutability() { |
| 88 | assertThatClassIsImmutable(MplsIntent.class); |
| 89 | } |
| 90 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 91 | /** |
| 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 Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 115 | } |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 116 | } |