samueljcc
Committed by Gerrit Code Review

[ONOS-3245] Add the junit test code of DefaultAllocationPool

Change-Id: Ifa4fd9b97ef16fc842e621db40029040a2ac0df7
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 +package org.onosproject.vtnrsc.subnet;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
21 +
22 +import org.junit.Test;
23 +import org.onlab.packet.IpAddress;
24 +import org.onosproject.vtnrsc.AllocationPool;
25 +import org.onosproject.vtnrsc.DefaultAllocationPool;
26 +
27 +import com.google.common.testing.EqualsTester;
28 +
29 +/**
30 + * Unit tests for DefaultAllocationPool class.
31 + */
32 +public class DefaultAllocationPoolTest {
33 +
34 + final IpAddress startIP1 = IpAddress.valueOf("192.168.1.1");
35 + final IpAddress startIP2 = IpAddress.valueOf("192.168.1.2");
36 + final IpAddress endIP1 = IpAddress.valueOf("192.168.1.1");
37 + final IpAddress endIP2 = IpAddress.valueOf("192.168.1.2");
38 +
39 + /**
40 + * Checks that the DefaultAllocationPool class is immutable.
41 + */
42 + @Test
43 + public void testImmutability() {
44 + assertThatClassIsImmutable(DefaultAllocationPool.class);
45 + }
46 +
47 + /**
48 + * Checks the operation of equals() methods.
49 + */
50 + @Test
51 + public void testEquals() {
52 + AllocationPool pool1 = new DefaultAllocationPool(startIP1, endIP1);
53 + AllocationPool pool2 = new DefaultAllocationPool(startIP1, endIP1);
54 + AllocationPool pool3 = new DefaultAllocationPool(startIP2, endIP2);
55 + new EqualsTester().addEqualityGroup(pool1, pool2)
56 + .addEqualityGroup(pool3).testEquals();
57 + }
58 +
59 + /**
60 + * Checks the construction of a DefaultAllocationPool object.
61 + */
62 + @Test
63 + public void testConstruction() {
64 + final AllocationPool apool = new DefaultAllocationPool(startIP1, endIP1);
65 + assertThat(startIP1, is(apool.startIp()));
66 + assertThat(endIP1, is(apool.endIp()));
67 + }
68 +}