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; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 21 | import org.onosproject.net.OchSignalType; |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 22 | import org.onosproject.net.Path; |
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; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 32 | import static org.onosproject.net.NetTestTools.createLambda; |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 33 | import static org.onosproject.net.NetTestTools.createPath; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 34 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 35 | public class OpticalPathIntentTest extends AbstractIntentTest { |
| 36 | |
| 37 | static final int PRIORITY = 777; |
| 38 | |
| 39 | OpticalPathIntent intent1; |
| 40 | OpticalPathIntent intent2; |
| 41 | Path defaultPath; |
| 42 | |
| 43 | @Before |
| 44 | public void opticalPathIntentTestSetUp() { |
| 45 | defaultPath = createPath("a", "b", "c"); |
| 46 | intent1 = OpticalPathIntent.builder() |
| 47 | .appId(APP_ID) |
| 48 | .src(connectPoint("one", 1)) |
| 49 | .dst(connectPoint("two", 2)) |
| 50 | .path(defaultPath) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 51 | .lambda(createLambda()) |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 52 | .signalType(OchSignalType.FIXED_GRID) |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 53 | .priority(PRIORITY) |
| 54 | .build(); |
| 55 | |
| 56 | intent2 = OpticalPathIntent.builder() |
| 57 | .appId(APP_ID) |
| 58 | .src(connectPoint("two", 1)) |
| 59 | .dst(connectPoint("one", 2)) |
| 60 | .path(defaultPath) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 61 | .lambda(createLambda()) |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 62 | .signalType(OchSignalType.FIXED_GRID) |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 63 | .priority(PRIORITY) |
| 64 | .build(); |
| 65 | } |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Checks that the OpticalPathIntent class is immutable. |
| 69 | */ |
| 70 | @Test |
| 71 | public void testImmutability() { |
| 72 | assertThatClassIsImmutable(OpticalPathIntent.class); |
| 73 | } |
| 74 | |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 77 | */ |
| 78 | @Test |
| 79 | public void testEquals() { |
| 80 | new EqualsTester() |
| 81 | .addEqualityGroup(intent1) |
| 82 | .addEqualityGroup(intent2) |
| 83 | .testEquals(); |
| 84 | } |
| 85 | |
| 86 | /** |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 87 | * Checks that the optical path intent objects are created correctly. |
Ray Milkey | a05fd20 | 2015-04-27 15:27:30 -0700 | [diff] [blame] | 88 | */ |
| 89 | @Test |
| 90 | public void testContents() { |
| 91 | assertThat(intent1.appId(), equalTo(APP_ID)); |
| 92 | assertThat(intent1.src(), Matchers.equalTo(connectPoint("one", 1))); |
| 93 | assertThat(intent1.dst(), Matchers.equalTo(connectPoint("two", 2))); |
| 94 | assertThat(intent1.priority(), is(PRIORITY)); |
| 95 | assertThat(intent1.path(), is(defaultPath)); |
| 96 | } |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 97 | } |