blob: 301553474cf7f96c4749c63c012a0962da9723b9 [file] [log] [blame]
Phaneendra Manda65440bf2016-02-20 19:41:21 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Phaneendra Manda65440bf2016-02-20 19:41:21 +05303 *
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.vtnrsc;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.hamcrest.Matchers.notNullValue;
21import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
22
23import org.junit.Test;
24import org.onlab.packet.IPv4;
25import org.onlab.packet.IpAddress;
26import org.onosproject.net.PortNumber;
27
28import com.google.common.testing.EqualsTester;
29
30/**
31 * Unit tests for FiveTuple class.
32 */
33public class DefaultFiveTupleTest {
34
35
36 final FiveTuple fiveTuple1 = DefaultFiveTuple.builder().setIpSrc(IpAddress.valueOf("1.1.1.1"))
37 .setIpDst(IpAddress.valueOf("2.2.2.2"))
38 .setPortSrc(PortNumber.portNumber(500))
39 .setPortDst(PortNumber.portNumber(1000))
40 .setProtocol(IPv4.PROTOCOL_TCP)
41 .setTenantId(TenantId.tenantId("aaa"))
42 .build();
43
44 final FiveTuple sameAsFiveTuple1 = DefaultFiveTuple.builder().setIpSrc(IpAddress.valueOf("1.1.1.1"))
45 .setIpDst(IpAddress.valueOf("2.2.2.2"))
46 .setPortSrc(PortNumber.portNumber(500))
47 .setPortDst(PortNumber.portNumber(1000))
48 .setProtocol(IPv4.PROTOCOL_TCP)
49 .setTenantId(TenantId.tenantId("aaa"))
50 .build();
51
52 final FiveTuple fiveTuple2 = DefaultFiveTuple.builder().setIpSrc(IpAddress.valueOf("3.3.3.3"))
53 .setIpDst(IpAddress.valueOf("4.4.4.4"))
54 .setPortSrc(PortNumber.portNumber(1500))
55 .setPortDst(PortNumber.portNumber(2000))
56 .setProtocol(IPv4.PROTOCOL_UDP)
57 .setTenantId(TenantId.tenantId("bbb"))
58 .build();
59
60 /**
61 * Checks that the FiveTuple class is immutable.
62 */
63 @Test
64 public void testImmutability() {
65 assertThatClassIsImmutable(DefaultFiveTuple.class);
66 }
67
68 /**
69 * Checks the operation of equals() methods.
70 */
71 @Test
72 public void testEquals() {
73 new EqualsTester().addEqualityGroup(fiveTuple1, sameAsFiveTuple1).addEqualityGroup(fiveTuple2)
74 .testEquals();
75 }
76
77 /**
78 * Checks the construction of a FiveTuple object.
79 */
80 @Test
81 public void testConstruction() {
82 final FiveTuple fiveTuple1 = DefaultFiveTuple.builder().setIpSrc(IpAddress.valueOf("1.1.1.1"))
83 .setIpDst(IpAddress.valueOf("2.2.2.2"))
84 .setPortSrc(PortNumber.portNumber(500))
85 .setPortDst(PortNumber.portNumber(1000))
86 .setProtocol(IPv4.PROTOCOL_TCP)
87 .setTenantId(TenantId.tenantId("aaa"))
88 .build();
89
90 assertThat(fiveTuple1, is(notNullValue()));
91 assertThat(fiveTuple1.protocol(), is(IPv4.PROTOCOL_TCP));
92 assertThat(fiveTuple1.ipSrc(), is(IpAddress.valueOf("1.1.1.1")));
93 assertThat(fiveTuple1.ipDst(), is(IpAddress.valueOf("2.2.2.2")));
94 assertThat(fiveTuple1.portSrc(), is(PortNumber.portNumber(500)));
95 assertThat(fiveTuple1.portDst(), is(PortNumber.portNumber(1000)));
96 assertThat(fiveTuple1.tenantId(), is(TenantId.tenantId("aaa")));
97 }
98}