blob: d1405b9083020184ce3a814b5d099d4b0f998366 [file] [log] [blame]
Ray Milkeyc8f481f2014-11-18 15:37:12 -08001/*
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 */
16package org.onlab.onos.net.intent;
17
18import org.junit.Test;
Ray Milkey37f6a382014-11-25 14:54:42 -080019import org.onlab.onos.TestApplicationId;
20import org.onlab.onos.core.ApplicationId;
Ray Milkeyc8f481f2014-11-18 15:37:12 -080021import org.onlab.onos.net.HostId;
22import org.onlab.onos.net.flow.TrafficSelector;
23
24import com.google.common.testing.EqualsTester;
25
Ray Milkey37f6a382014-11-25 14:54:42 -080026import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.equalTo;
28import static org.hamcrest.Matchers.is;
Ray Milkeyc8f481f2014-11-18 15:37:12 -080029import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
30import static org.onlab.onos.net.NetTestTools.APP_ID;
31import static org.onlab.onos.net.NetTestTools.hid;
32
33/**
34 * Unit tests for the HostToHostIntent class.
35 */
Brian O'Connor520c0522014-11-23 23:50:47 -080036public class HostToHostIntentTest extends IntentTest {
37 private final TrafficSelector selector = new IntentTestsMocks.MockSelector();
38 private final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment();
39 private final HostId id1 = hid("12:34:56:78:91:ab/1");
40 private final HostId id2 = hid("12:34:56:78:92:ab/1");
41 private final HostId id3 = hid("12:34:56:78:93:ab/1");
Ray Milkeyc8f481f2014-11-18 15:37:12 -080042
Ray Milkey37f6a382014-11-25 14:54:42 -080043 private static final ApplicationId APPID = new TestApplicationId("foo");
44
45 private HostToHostIntent makeHostToHost(HostId one, HostId two) {
46 return new HostToHostIntent(APPID, one, two, selector, treatment);
47 }
48
49 /**
50 * Tests the equals() method where two HostToHostIntents have references
51 * to the same hosts. These should compare equal.
52 */
53 @Test
54 public void testSameEquals() {
55
56 HostId one = hid("00:00:00:00:00:01/-1");
57 HostId two = hid("00:00:00:00:00:02/-1");
58 HostToHostIntent i1 = makeHostToHost(one, two);
59 HostToHostIntent i2 = makeHostToHost(one, two);
60
61 assertThat(i1.one(), is(equalTo(i2.one())));
62 assertThat(i1.two(), is(equalTo(i2.two())));
63 }
64
Ray Milkeyc8f481f2014-11-18 15:37:12 -080065 /**
66 * Checks that the HostToHostIntent class is immutable.
67 */
68 @Test
69 public void testImmutability() {
70 assertThatClassIsImmutable(HostToHostIntent.class);
71 }
72
73 /**
74 * Tests equals(), hashCode() and toString() methods.
75 */
Ray Milkey37f6a382014-11-25 14:54:42 -080076 @Test
Ray Milkeyc8f481f2014-11-18 15:37:12 -080077 public void testEquals() {
Ray Milkeyc8f481f2014-11-18 15:37:12 -080078 final HostToHostIntent intent1 = new HostToHostIntent(APP_ID,
79 id1,
80 id2,
81 selector,
82 treatment);
Ray Milkey37f6a382014-11-25 14:54:42 -080083
Ray Milkeyc8f481f2014-11-18 15:37:12 -080084 final HostToHostIntent intent2 = new HostToHostIntent(APP_ID,
85 id2,
86 id3,
87 selector,
88 treatment);
89
90 new EqualsTester()
Ray Milkey37f6a382014-11-25 14:54:42 -080091 .addEqualityGroup(intent1)
Ray Milkeyc8f481f2014-11-18 15:37:12 -080092 .addEqualityGroup(intent2)
93 .testEquals();
94 }
Brian O'Connor520c0522014-11-23 23:50:47 -080095
96 @Override
97 protected Intent createOne() {
98 return new HostToHostIntent(APP_ID, id1, id2, selector, treatment);
99 }
100
101 @Override
102 protected Intent createAnother() {
103 return new HostToHostIntent(APP_ID, id1, id3, selector, treatment);
104 }
Ray Milkeyc8f481f2014-11-18 15:37:12 -0800105}