samueljcc
Committed by Gerrit Code Review

[ONOS-3250] Add the junit test code of FixedIp

Change-Id: Ic8a6ff9d81b0bfca667bec49c11399e6cd3838db
1 +/*
2 + * Copyright 2015 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 + */
16 +
17 +package org.onosproject.vtnrsc.virtualport;
18 +
19 +import static org.hamcrest.MatcherAssert.assertThat;
20 +import static org.hamcrest.Matchers.is;
21 +import static org.hamcrest.Matchers.notNullValue;
22 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
23 +
24 +import org.junit.Test;
25 +import org.onlab.packet.IpAddress;
26 +import org.onosproject.vtnrsc.FixedIp;
27 +import org.onosproject.vtnrsc.SubnetId;
28 +
29 +import com.google.common.testing.EqualsTester;
30 +
31 +/**
32 + * Unit tests for FixedIp class.
33 + */
34 +public class FixedIpTest {
35 +
36 + final SubnetId subnetId1 = SubnetId.subnetId("lef11-95w-4er-9c9c");
37 + final SubnetId subnetId2 = SubnetId.subnetId("lefaa-95w-4er-9c9c");
38 + final IpAddress ip1 = IpAddress.valueOf("192.168.0.1");
39 + final IpAddress ip2 = IpAddress.valueOf("192.168.1.1");
40 +
41 + /**
42 + * Checks that the FixedIp class is immutable.
43 + */
44 + @Test
45 + public void testImmutability() {
46 + assertThatClassIsImmutable(FixedIp.class);
47 + }
48 +
49 + /**
50 + * Checks the operation of equals().
51 + */
52 + @Test
53 + public void testEquals() {
54 + FixedIp fixedIp1 = FixedIp.fixedIp(subnetId1, ip1);
55 + FixedIp fixedIp2 = FixedIp.fixedIp(subnetId1, ip1);
56 + FixedIp fixedIp3 = FixedIp.fixedIp(subnetId2, ip2);
57 + new EqualsTester().addEqualityGroup(fixedIp1, fixedIp2)
58 + .addEqualityGroup(fixedIp3).testEquals();
59 + }
60 +
61 + /**
62 + * Checks the construction of a FixedIp object.
63 + */
64 + @Test
65 + public void testConstruction() {
66 + FixedIp fixedIp = FixedIp.fixedIp(subnetId1, ip1);
67 + assertThat(ip1, is(notNullValue()));
68 + assertThat(ip1, is(fixedIp.ip()));
69 + assertThat(subnetId1, is(notNullValue()));
70 + assertThat(subnetId1, is(fixedIp.subnetId()));
71 + }
72 +}