blob: 31d6c4defd1936e0d02ebcdb4425c603bef0b4f8 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Ray Milkeyc8f481f2014-11-18 15:37:12 -080017
18import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.TestApplicationId;
20import org.onosproject.core.ApplicationId;
21import org.onosproject.net.HostId;
22import org.onosproject.net.flow.TrafficSelector;
Ray Milkeyc8f481f2014-11-18 15:37:12 -080023
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;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import static org.onosproject.net.NetTestTools.hid;
Ray Milkeyc8f481f2014-11-18 15:37:12 -080031
32/**
33 * Unit tests for the HostToHostIntent class.
34 */
Brian O'Connor520c0522014-11-23 23:50:47 -080035public class HostToHostIntentTest extends IntentTest {
36 private final TrafficSelector selector = new IntentTestsMocks.MockSelector();
37 private final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment();
38 private final HostId id1 = hid("12:34:56:78:91:ab/1");
39 private final HostId id2 = hid("12:34:56:78:92:ab/1");
40 private final HostId id3 = hid("12:34:56:78:93:ab/1");
Ray Milkeyc8f481f2014-11-18 15:37:12 -080041
Ray Milkey37f6a382014-11-25 14:54:42 -080042 private static final ApplicationId APPID = new TestApplicationId("foo");
43
44 private HostToHostIntent makeHostToHost(HostId one, HostId two) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070045 return HostToHostIntent.builder()
46 .appId(APPID)
47 .one(one)
48 .two(two)
49 .selector(selector)
50 .treatment(treatment)
51 .build();
Ray Milkey37f6a382014-11-25 14:54:42 -080052 }
53
54 /**
55 * Tests the equals() method where two HostToHostIntents have references
56 * to the same hosts. These should compare equal.
57 */
58 @Test
59 public void testSameEquals() {
60
61 HostId one = hid("00:00:00:00:00:01/-1");
62 HostId two = hid("00:00:00:00:00:02/-1");
63 HostToHostIntent i1 = makeHostToHost(one, two);
64 HostToHostIntent i2 = makeHostToHost(one, two);
65
66 assertThat(i1.one(), is(equalTo(i2.one())));
67 assertThat(i1.two(), is(equalTo(i2.two())));
68 }
69
Ray Milkeyc8f481f2014-11-18 15:37:12 -080070 /**
71 * Checks that the HostToHostIntent class is immutable.
72 */
73 @Test
74 public void testImmutability() {
75 assertThatClassIsImmutable(HostToHostIntent.class);
76 }
77
78 /**
79 * Tests equals(), hashCode() and toString() methods.
80 */
Ray Milkey37f6a382014-11-25 14:54:42 -080081 @Test
Ray Milkeyc8f481f2014-11-18 15:37:12 -080082 public void testEquals() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070083 final HostToHostIntent intent1 = HostToHostIntent.builder()
84 .appId(APPID)
85 .one(id1)
86 .two(id2)
87 .selector(selector)
88 .treatment(treatment)
89 .build();
Ray Milkey37f6a382014-11-25 14:54:42 -080090
Ray Milkeyebc5d222015-03-18 15:45:36 -070091 final HostToHostIntent intent2 = HostToHostIntent.builder()
92 .appId(APPID)
93 .one(id2)
94 .two(id3)
95 .selector(selector)
96 .treatment(treatment)
97 .build();
Ray Milkeyc8f481f2014-11-18 15:37:12 -080098
99 new EqualsTester()
Ray Milkey37f6a382014-11-25 14:54:42 -0800100 .addEqualityGroup(intent1)
Ray Milkeyc8f481f2014-11-18 15:37:12 -0800101 .addEqualityGroup(intent2)
102 .testEquals();
103 }
Brian O'Connor520c0522014-11-23 23:50:47 -0800104
105 @Override
106 protected Intent createOne() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700107 return HostToHostIntent.builder()
108 .appId(APPID)
109 .one(id1)
110 .two(id2)
111 .selector(selector)
112 .treatment(treatment)
113 .build();
Brian O'Connor520c0522014-11-23 23:50:47 -0800114 }
115
116 @Override
117 protected Intent createAnother() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700118 return HostToHostIntent.builder()
119 .appId(APPID)
120 .one(id1)
121 .two(id3)
122 .selector(selector)
123 .treatment(treatment)
124 .build();
Brian O'Connor520c0522014-11-23 23:50:47 -0800125 }
Ray Milkeyc8f481f2014-11-18 15:37:12 -0800126}