Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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 org.hamcrest.Matchers; |
| 19 | import org.junit.Before; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 20 | import org.junit.Test; |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 21 | import org.onosproject.net.flow.TrafficSelector; |
| 22 | import org.onosproject.net.flow.TrafficTreatment; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 23 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 24 | import com.google.common.testing.EqualsTester; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | import static org.hamcrest.core.IsEqual.equalTo; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 29 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 30 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 31 | import static org.onosproject.net.NetTestTools.connectPoint; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 32 | /** |
| 33 | * Unit tests for the TwoWayP2PIntent class. |
| 34 | */ |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 35 | public class TwoWayP2PIntentTest extends AbstractIntentTest { |
| 36 | |
| 37 | TrafficSelector selector; |
| 38 | TrafficTreatment treatment; |
| 39 | |
| 40 | TwoWayP2PIntent intent1; |
| 41 | TwoWayP2PIntent intent2; |
| 42 | |
| 43 | static final int PRIORITY = 12; |
| 44 | |
| 45 | @Before |
| 46 | public void twoWatP2PIntentTestSetUp() { |
| 47 | selector = new IntentTestsMocks.MockSelector(); |
| 48 | treatment = new IntentTestsMocks.MockTreatment(); |
| 49 | |
| 50 | intent1 = TwoWayP2PIntent.builder() |
| 51 | .appId(APP_ID) |
| 52 | .priority(PRIORITY) |
| 53 | .selector(selector) |
| 54 | .treatment(treatment) |
| 55 | .one(connectPoint("one", 1)) |
| 56 | .two(connectPoint("two", 2)) |
| 57 | .build(); |
| 58 | |
| 59 | intent2 = TwoWayP2PIntent.builder() |
| 60 | .appId(APP_ID) |
| 61 | .priority(PRIORITY) |
| 62 | .selector(selector) |
| 63 | .treatment(treatment) |
| 64 | .one(connectPoint("two", 2)) |
| 65 | .two(connectPoint("three", 2)) |
| 66 | .build(); |
| 67 | } |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Checks that the TwoWayP2PIntent class is immutable. |
| 71 | */ |
| 72 | @Test |
| 73 | public void testImmutability() { |
| 74 | assertThatClassIsImmutable(TwoWayP2PIntent.class); |
| 75 | } |
| 76 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 79 | */ |
| 80 | @Test |
| 81 | public void testEquals() { |
| 82 | new EqualsTester() |
| 83 | .addEqualityGroup(intent1) |
| 84 | .addEqualityGroup(intent2) |
| 85 | .testEquals(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Checks that the optical path ntent objects are created correctly. |
| 90 | */ |
| 91 | @Test |
| 92 | public void testContents() { |
| 93 | assertThat(intent1.appId(), equalTo(APP_ID)); |
| 94 | assertThat(intent1.one(), Matchers.equalTo(connectPoint("one", 1))); |
| 95 | assertThat(intent1.two(), Matchers.equalTo(connectPoint("two", 2))); |
| 96 | assertThat(intent1.priority(), is(PRIORITY)); |
| 97 | assertThat(intent1.selector(), is(selector)); |
| 98 | assertThat(intent1.treatment(), is(treatment)); |
| 99 | } |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 100 | } |