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