blob: 662e311c2c51a01cf817b85bb88edb563e1ab553 [file] [log] [blame]
Ray Milkeybd4f0112015-03-02 17:07:09 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeybd4f0112015-03-02 17:07:09 -08003 *
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.onosproject.net.intent;
17
Ray Milkeya05fd202015-04-27 15:27:30 -070018import org.hamcrest.Matchers;
19import org.junit.Before;
Ray Milkeybd4f0112015-03-02 17:07:09 -080020import org.junit.Test;
Ray Milkeya05fd202015-04-27 15:27:30 -070021import org.onosproject.net.flow.TrafficSelector;
22import org.onosproject.net.flow.TrafficTreatment;
Ray Milkeybd4f0112015-03-02 17:07:09 -080023
Ray Milkeya05fd202015-04-27 15:27:30 -070024import com.google.common.testing.EqualsTester;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28import static org.hamcrest.core.IsEqual.equalTo;
Ray Milkeybd4f0112015-03-02 17:07:09 -080029import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ray Milkeya05fd202015-04-27 15:27:30 -070030import static org.onosproject.net.NetTestTools.APP_ID;
31import static org.onosproject.net.NetTestTools.connectPoint;
Ray Milkeybd4f0112015-03-02 17:07:09 -080032/**
33 * Unit tests for the TwoWayP2PIntent class.
34 */
Ray Milkeya05fd202015-04-27 15:27:30 -070035public class TwoWayP2PIntentTest extends AbstractIntentTest {
36
37 TrafficSelector selector;
38 TrafficTreatment treatment;
39
40 TwoWayP2PIntent intent1;
41 TwoWayP2PIntent intent2;
42
43 static final int PRIORITY = 12;
44
45 @Before
46 public void twoWatP2PIntentTestSetUp() {
47 selector = new IntentTestsMocks.MockSelector();
48 treatment = new IntentTestsMocks.MockTreatment();
49
50 intent1 = TwoWayP2PIntent.builder()
51 .appId(APP_ID)
52 .priority(PRIORITY)
53 .selector(selector)
54 .treatment(treatment)
55 .one(connectPoint("one", 1))
56 .two(connectPoint("two", 2))
57 .build();
58
59 intent2 = TwoWayP2PIntent.builder()
60 .appId(APP_ID)
61 .priority(PRIORITY)
62 .selector(selector)
63 .treatment(treatment)
64 .one(connectPoint("two", 2))
65 .two(connectPoint("three", 2))
66 .build();
67 }
Ray Milkeybd4f0112015-03-02 17:07:09 -080068
69 /**
70 * Checks that the TwoWayP2PIntent class is immutable.
71 */
72 @Test
73 public void testImmutability() {
74 assertThatClassIsImmutable(TwoWayP2PIntent.class);
75 }
76
Ray Milkeya05fd202015-04-27 15:27:30 -070077 /**
78 * Checks the operation of equals(), hashCode() and toString() methods.
79 */
80 @Test
81 public void testEquals() {
82 new EqualsTester()
83 .addEqualityGroup(intent1)
84 .addEqualityGroup(intent2)
85 .testEquals();
86 }
87
88 /**
89 * Checks that the optical path ntent objects are created correctly.
90 */
91 @Test
92 public void testContents() {
93 assertThat(intent1.appId(), equalTo(APP_ID));
94 assertThat(intent1.one(), Matchers.equalTo(connectPoint("one", 1)));
95 assertThat(intent1.two(), Matchers.equalTo(connectPoint("two", 2)));
96 assertThat(intent1.priority(), is(PRIORITY));
97 assertThat(intent1.selector(), is(selector));
98 assertThat(intent1.treatment(), is(treatment));
99 }
Ray Milkeybd4f0112015-03-02 17:07:09 -0800100}