Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 18 | import org.junit.Before; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 19 | import org.junit.Ignore; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 21 | import org.onlab.onos.core.ApplicationId; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 22 | import org.onlab.onos.TestApplicationId; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 23 | import org.onlab.onos.net.ConnectPoint; |
| 24 | import org.onlab.onos.net.flow.TrafficSelector; |
| 25 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 26 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 27 | import java.util.HashSet; |
| 28 | import java.util.Set; |
| 29 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 30 | import static org.hamcrest.CoreMatchers.not; |
| 31 | import static org.hamcrest.MatcherAssert.assertThat; |
| 32 | import static org.hamcrest.Matchers.equalTo; |
| 33 | import static org.hamcrest.Matchers.is; |
Pavlin Radoslavov | d26f57a | 2014-10-23 17:19:45 -0700 | [diff] [blame] | 34 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 35 | import static org.onlab.onos.net.NetTestTools.connectPoint; |
| 36 | |
| 37 | /** |
| 38 | * Unit tests for the MultiPointToSinglePointIntent class. |
| 39 | */ |
| 40 | public class TestMultiPointToSinglePointIntent { |
| 41 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 42 | private static final ApplicationId APPID = new TestApplicationId("foo"); |
| 43 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 44 | private ConnectPoint point1 = connectPoint("dev1", 1); |
| 45 | private ConnectPoint point2 = connectPoint("dev2", 1); |
| 46 | private ConnectPoint point3 = connectPoint("dev3", 1); |
| 47 | |
| 48 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 49 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 50 | |
| 51 | Set<ConnectPoint> ingress1; |
| 52 | Set<ConnectPoint> ingress2; |
| 53 | |
| 54 | /** |
| 55 | * Creates a MultiPointToSinglePointIntent object. |
| 56 | * |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 57 | * @param ingress set of ingress points |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 58 | * @param egress egress point |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 59 | * @return MultiPointToSinglePoint intent |
| 60 | */ |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 61 | private MultiPointToSinglePointIntent makeIntent(Set<ConnectPoint> ingress, |
| 62 | ConnectPoint egress) { |
| 63 | return new MultiPointToSinglePointIntent(APPID, selector, treatment, |
| 64 | ingress, egress); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Initializes the ingress sets. |
| 69 | */ |
| 70 | @Before |
| 71 | public void setup() { |
| 72 | ingress1 = new HashSet<>(); |
| 73 | ingress2 = new HashSet<>(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Tests the equals() method where two MultiPointToSinglePoint have references |
| 78 | * to the same Links in different orders. These should compare equal. |
| 79 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 80 | @Test @Ignore("Needs to be merged with other API test") |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 81 | public void testSameEquals() { |
| 82 | |
| 83 | Set<ConnectPoint> ingress1 = new HashSet<>(); |
| 84 | ingress1.add(point2); |
| 85 | ingress1.add(point3); |
| 86 | |
| 87 | Set<ConnectPoint> ingress2 = new HashSet<>(); |
| 88 | ingress2.add(point3); |
| 89 | ingress2.add(point2); |
| 90 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 91 | Intent i1 = makeIntent(ingress1, point1); |
| 92 | Intent i2 = makeIntent(ingress2, point1); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 93 | |
| 94 | assertThat(i1, is(equalTo(i2))); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Tests the equals() method where two MultiPointToSinglePoint have references |
| 99 | * to different Links. These should compare not equal. |
| 100 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 101 | @Test @Ignore("Needs to be merged with other API test") |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 102 | public void testLinksDifferentEquals() { |
| 103 | ingress1.add(point3); |
| 104 | |
| 105 | ingress2.add(point3); |
| 106 | ingress2.add(point2); |
| 107 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 108 | Intent i1 = makeIntent(ingress1, point1); |
| 109 | Intent i2 = makeIntent(ingress2, point1); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 110 | |
| 111 | assertThat(i1, is(not(equalTo(i2)))); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Tests that the hashCode() values for two equivalent MultiPointToSinglePoint |
| 116 | * objects are the same. |
| 117 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 118 | @Test @Ignore("Needs to be merged with other API test") |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 119 | public void testHashCodeEquals() { |
| 120 | ingress1.add(point2); |
| 121 | ingress1.add(point3); |
| 122 | |
| 123 | ingress2.add(point3); |
| 124 | ingress2.add(point2); |
| 125 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 126 | Intent i1 = makeIntent(ingress1, point1); |
| 127 | Intent i2 = makeIntent(ingress2, point1); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 128 | |
| 129 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Tests that the hashCode() values for two distinct MultiPointToSinglePoint |
| 134 | * objects are different. |
| 135 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 136 | @Test @Ignore("Needs to be merged with other API test") |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 137 | public void testHashCodeDifferent() { |
| 138 | ingress1.add(point2); |
| 139 | |
| 140 | ingress2.add(point3); |
| 141 | ingress2.add(point2); |
| 142 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 143 | Intent i1 = makeIntent(ingress1, point1); |
| 144 | Intent i2 = makeIntent(ingress2, point1); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 145 | |
| 146 | |
| 147 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Checks that the MultiPointToSinglePointIntent class is immutable. |
| 152 | */ |
| 153 | @Test |
| 154 | public void checkImmutability() { |
Pavlin Radoslavov | d26f57a | 2014-10-23 17:19:45 -0700 | [diff] [blame] | 155 | assertThatClassIsImmutable(MultiPointToSinglePointIntent.class); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 156 | } |
| 157 | } |