blob: 7af382f8caf1803c2e6eaacee885974bdefc76a8 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 Milkeyc0fa4db2014-10-17 08:49:54 -070016package org.onlab.onos.net.intent;
17
18import org.junit.Test;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070019import org.onlab.onos.core.ApplicationId;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070020import org.onlab.onos.TestApplicationId;
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070021import org.onlab.onos.net.ConnectPoint;
22import org.onlab.onos.net.flow.TrafficSelector;
23import org.onlab.onos.net.flow.TrafficTreatment;
24
25import static org.hamcrest.MatcherAssert.assertThat;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070026import static org.hamcrest.Matchers.*;
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070027import static org.onlab.onos.net.NetTestTools.connectPoint;
28
29/**
30 * Unit tests for the HostToHostIntent class.
31 */
32public class TestPointToPointIntent {
33
Thomas Vachuskab97cf282014-10-20 23:31:12 -070034 private static final ApplicationId APPID = new TestApplicationId("foo");
35
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070036 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
37 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
38
39 private ConnectPoint point1 = connectPoint("dev1", 1);
40 private ConnectPoint point2 = connectPoint("dev2", 1);
41
Thomas Vachuskab97cf282014-10-20 23:31:12 -070042 private PointToPointIntent makePointToPoint(ConnectPoint ingress,
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070043 ConnectPoint egress) {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070044 return new PointToPointIntent(APPID, selector, treatment, ingress, egress);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070045 }
46
47 /**
48 * Tests the equals() method where two PointToPointIntents have references
49 * to the same ingress and egress points. These should compare equal.
50 */
51 @Test
52 public void testSameEquals() {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070053 PointToPointIntent i1 = makePointToPoint(point1, point2);
54 PointToPointIntent i2 = makePointToPoint(point1, point2);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070055
56 assertThat(i1, is(equalTo(i2)));
57 }
58
59 /**
60 * Tests the equals() method where two HostToHostIntents have references
61 * to different Hosts. These should compare not equal.
62 */
63 @Test
64 public void testLinksDifferentEquals() {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070065 PointToPointIntent i1 = makePointToPoint(point1, point2);
66 PointToPointIntent i2 = makePointToPoint(point2, point1);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070067
68 assertThat(i1, is(not(equalTo(i2))));
69 }
70
71 /**
72 * Tests that the hashCode() values for two equivalent HostToHostIntent
73 * objects are the same.
74 */
75 @Test
76 public void testHashCodeEquals() {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070077 PointToPointIntent i1 = makePointToPoint(point1, point2);
78 PointToPointIntent i2 = makePointToPoint(point1, point2);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070079
80 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
81 }
82
83 /**
84 * Tests that the hashCode() values for two distinct LinkCollectionIntent
85 * objects are different.
86 */
87 @Test
88 public void testHashCodeDifferent() {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070089 PointToPointIntent i1 = makePointToPoint(point1, point2);
90 PointToPointIntent i2 = makePointToPoint(point2, point1);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070091
92 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
93 }
94}