Committed by
Gerrit Code Review
Add unit test for LISP address to check obj equality & construction
This commit adds various unit tests of LISP addresses in a way to check object equality and construction. This commit also makes minor changes to existing LISP address classes to allow the test cases to pass all unit tests. Change-Id: Ice9f9634bdd243baaf1eed1539ea8d5808dda01d
Showing
14 changed files
with
680 additions
and
2 deletions
... | @@ -17,6 +17,8 @@ package org.onosproject.lisp.msg.types; | ... | @@ -17,6 +17,8 @@ package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | import org.onlab.packet.IpAddress; | 18 | import org.onlab.packet.IpAddress; |
19 | 19 | ||
20 | +import java.util.Objects; | ||
21 | + | ||
20 | import static com.google.common.base.Preconditions.checkArgument; | 22 | import static com.google.common.base.Preconditions.checkArgument; |
21 | 23 | ||
22 | /** | 24 | /** |
... | @@ -33,4 +35,23 @@ public class LispIpv4Address extends LispIpAddress { | ... | @@ -33,4 +35,23 @@ public class LispIpv4Address extends LispIpAddress { |
33 | super(address, AddressFamilyIdentifierEnum.IP); | 35 | super(address, AddressFamilyIdentifierEnum.IP); |
34 | checkArgument(address.isIp4()); | 36 | checkArgument(address.isIp4()); |
35 | } | 37 | } |
38 | + | ||
39 | + @Override | ||
40 | + public boolean equals(Object obj) { | ||
41 | + if (this == obj) { | ||
42 | + return true; | ||
43 | + } | ||
44 | + | ||
45 | + if (obj instanceof LispIpv4Address) { | ||
46 | + final LispIpv4Address other = (LispIpv4Address) obj; | ||
47 | + return Objects.equals(this.address, other.address) && | ||
48 | + Objects.equals(this.getAfi(), other.getAfi()); | ||
49 | + } | ||
50 | + return false; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public int hashCode() { | ||
55 | + return Objects.hash(address, getAfi()); | ||
56 | + } | ||
36 | } | 57 | } | ... | ... |
... | @@ -17,6 +17,8 @@ package org.onosproject.lisp.msg.types; | ... | @@ -17,6 +17,8 @@ package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | import org.onlab.packet.IpAddress; | 18 | import org.onlab.packet.IpAddress; |
19 | 19 | ||
20 | +import java.util.Objects; | ||
21 | + | ||
20 | import static com.google.common.base.Preconditions.checkArgument; | 22 | import static com.google.common.base.Preconditions.checkArgument; |
21 | 23 | ||
22 | /** | 24 | /** |
... | @@ -33,4 +35,23 @@ public class LispIpv6Address extends LispIpAddress { | ... | @@ -33,4 +35,23 @@ public class LispIpv6Address extends LispIpAddress { |
33 | super(address, AddressFamilyIdentifierEnum.IP); | 35 | super(address, AddressFamilyIdentifierEnum.IP); |
34 | checkArgument(address.isIp6()); | 36 | checkArgument(address.isIp6()); |
35 | } | 37 | } |
38 | + | ||
39 | + @Override | ||
40 | + public boolean equals(Object obj) { | ||
41 | + if (this == obj) { | ||
42 | + return true; | ||
43 | + } | ||
44 | + | ||
45 | + if (obj instanceof LispIpv6Address) { | ||
46 | + final LispIpv6Address other = (LispIpv6Address) obj; | ||
47 | + return Objects.equals(this.address, other.address) && | ||
48 | + Objects.equals(this.getAfi(), other.getAfi()); | ||
49 | + } | ||
50 | + return false; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public int hashCode() { | ||
55 | + return Objects.hash(address, getAfi()); | ||
56 | + } | ||
36 | } | 57 | } | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableList; | ||
19 | + | ||
18 | import java.util.List; | 20 | import java.util.List; |
19 | import java.util.Objects; | 21 | import java.util.Objects; |
20 | 22 | ||
... | @@ -61,6 +63,7 @@ public class LispListLcafAddress extends LispLcafAddress { | ... | @@ -61,6 +63,7 @@ public class LispListLcafAddress extends LispLcafAddress { |
61 | */ | 63 | */ |
62 | public LispListLcafAddress(List<LispAfiAddress> addresses) { | 64 | public LispListLcafAddress(List<LispAfiAddress> addresses) { |
63 | super(LispCanonicalAddressFormatEnum.LIST, LENGTH); | 65 | super(LispCanonicalAddressFormatEnum.LIST, LENGTH); |
66 | + this.addresses = addresses; | ||
64 | } | 67 | } |
65 | 68 | ||
66 | /** | 69 | /** |
... | @@ -69,7 +72,7 @@ public class LispListLcafAddress extends LispLcafAddress { | ... | @@ -69,7 +72,7 @@ public class LispListLcafAddress extends LispLcafAddress { |
69 | * @return a set of AFI addresses | 72 | * @return a set of AFI addresses |
70 | */ | 73 | */ |
71 | public List<LispAfiAddress> getAddresses() { | 74 | public List<LispAfiAddress> getAddresses() { |
72 | - return addresses; | 75 | + return ImmutableList.copyOf(addresses); |
73 | } | 76 | } |
74 | 77 | ||
75 | @Override | 78 | @Override | ... | ... |
... | @@ -17,6 +17,8 @@ package org.onosproject.lisp.msg.types; | ... | @@ -17,6 +17,8 @@ package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | import org.onlab.packet.MacAddress; | 18 | import org.onlab.packet.MacAddress; |
19 | 19 | ||
20 | +import java.util.Objects; | ||
21 | + | ||
20 | /** | 22 | /** |
21 | * MAC address that is used by LISP Locator. | 23 | * MAC address that is used by LISP Locator. |
22 | */ | 24 | */ |
... | @@ -50,7 +52,16 @@ public class LispMacAddress extends LispAfiAddress { | ... | @@ -50,7 +52,16 @@ public class LispMacAddress extends LispAfiAddress { |
50 | 52 | ||
51 | @Override | 53 | @Override |
52 | public boolean equals(Object obj) { | 54 | public boolean equals(Object obj) { |
53 | - return address.equals(obj); | 55 | + if (this == obj) { |
56 | + return true; | ||
57 | + } | ||
58 | + | ||
59 | + if (obj instanceof LispMacAddress) { | ||
60 | + final LispMacAddress other = (LispMacAddress) obj; | ||
61 | + return Objects.equals(this.address, other.address) && | ||
62 | + Objects.equals(this.getAfi(), other.getAfi()); | ||
63 | + } | ||
64 | + return false; | ||
54 | } | 65 | } |
55 | 66 | ||
56 | @Override | 67 | @Override | ... | ... |
protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispAppDataLcafAddressTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.IpAddress; | ||
22 | + | ||
23 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
24 | +import static org.hamcrest.Matchers.is; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for LispAppDataLcafAddress class. | ||
28 | + */ | ||
29 | +public class LispAppDataLcafAddressTest { | ||
30 | + | ||
31 | + private LispAppDataLcafAddress address1; | ||
32 | + private LispAppDataLcafAddress sameAsAddress1; | ||
33 | + private LispAppDataLcafAddress address2; | ||
34 | + | ||
35 | + @Before | ||
36 | + public void setup() { | ||
37 | + | ||
38 | + LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
39 | + address1 = new LispAppDataLcafAddress((byte) 0x01, 1, (short) 10, (short) 20, ipv4Address1); | ||
40 | + | ||
41 | + sameAsAddress1 = new LispAppDataLcafAddress((byte) 0x01, 1, (short) 10, (short) 20, ipv4Address1); | ||
42 | + | ||
43 | + LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); | ||
44 | + address2 = new LispAppDataLcafAddress((byte) 0x02, 2, (short) 20, (short) 40, ipv4Address2); | ||
45 | + } | ||
46 | + | ||
47 | + @Test | ||
48 | + public void testEquality() { | ||
49 | + new EqualsTester() | ||
50 | + .addEqualityGroup(address1, sameAsAddress1) | ||
51 | + .addEqualityGroup(address2).testEquals(); | ||
52 | + } | ||
53 | + | ||
54 | + @Test | ||
55 | + public void testConstruction() { | ||
56 | + LispAppDataLcafAddress appDataLcafAddress = address1; | ||
57 | + | ||
58 | + LispAfiAddress ipv4Address = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
59 | + | ||
60 | + assertThat(appDataLcafAddress.getProtocol(), is((byte) 0x01)); | ||
61 | + assertThat(appDataLcafAddress.getIpTos(), is(1)); | ||
62 | + assertThat(appDataLcafAddress.getLocalPort(), is((short) 10)); | ||
63 | + assertThat(appDataLcafAddress.getRemotePort(), is((short) 20)); | ||
64 | + assertThat(appDataLcafAddress.getAddress(), is(ipv4Address)); | ||
65 | + } | ||
66 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | + | ||
22 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
23 | +import static org.hamcrest.Matchers.is; | ||
24 | + | ||
25 | +/** | ||
26 | + * Unit tests for LispAsAddress class. | ||
27 | + */ | ||
28 | +public class LispAsAddressTest { | ||
29 | + | ||
30 | + private LispAsAddress address1; | ||
31 | + private LispAsAddress sameAsAddress1; | ||
32 | + private LispAsAddress address2; | ||
33 | + | ||
34 | + @Before | ||
35 | + public void setup() { | ||
36 | + | ||
37 | + address1 = new LispAsAddress(1); | ||
38 | + sameAsAddress1 = new LispAsAddress(1); | ||
39 | + address2 = new LispAsAddress(2); | ||
40 | + } | ||
41 | + | ||
42 | + @Test | ||
43 | + public void testEquality() { | ||
44 | + new EqualsTester() | ||
45 | + .addEqualityGroup(address1, sameAsAddress1) | ||
46 | + .addEqualityGroup(address2).testEquals(); | ||
47 | + } | ||
48 | + | ||
49 | + @Test | ||
50 | + public void testConstruction() { | ||
51 | + LispAsAddress asAddress = address1; | ||
52 | + assertThat(asAddress.getASNum(), is(1)); | ||
53 | + } | ||
54 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | + | ||
22 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
23 | +import static org.hamcrest.Matchers.is; | ||
24 | + | ||
25 | +/** | ||
26 | + * Unit tests for LispDistinguishedNameAddress class. | ||
27 | + */ | ||
28 | +public class LispDistinguishedNameAddressTest { | ||
29 | + | ||
30 | + private LispDistinguishedNameAddress address1; | ||
31 | + private LispDistinguishedNameAddress sameAsAddress1; | ||
32 | + private LispDistinguishedNameAddress address2; | ||
33 | + | ||
34 | + @Before | ||
35 | + public void setup() { | ||
36 | + | ||
37 | + address1 = new LispDistinguishedNameAddress("distAddress1"); | ||
38 | + sameAsAddress1 = new LispDistinguishedNameAddress("distAddress1"); | ||
39 | + address2 = new LispDistinguishedNameAddress("distAddress2"); | ||
40 | + } | ||
41 | + | ||
42 | + @Test | ||
43 | + public void testEquality() { | ||
44 | + new EqualsTester() | ||
45 | + .addEqualityGroup(address1, sameAsAddress1) | ||
46 | + .addEqualityGroup(address2).testEquals(); | ||
47 | + } | ||
48 | + | ||
49 | + @Test | ||
50 | + public void testConstruction() { | ||
51 | + LispDistinguishedNameAddress distinguishedNameAddress = address1; | ||
52 | + | ||
53 | + assertThat(distinguishedNameAddress.getDistinguishedName(), is("distAddress1")); | ||
54 | + } | ||
55 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.IpAddress; | ||
22 | + | ||
23 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
24 | +import static org.hamcrest.Matchers.is; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for LispIpv4Address class. | ||
28 | + */ | ||
29 | +public class LispIpv4AddressTest { | ||
30 | + | ||
31 | + private LispIpv4Address address1; | ||
32 | + private LispIpv4Address sameAsAddress1; | ||
33 | + private LispIpv4Address address2; | ||
34 | + | ||
35 | + @Before | ||
36 | + public void setup() { | ||
37 | + | ||
38 | + address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
39 | + sameAsAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
40 | + address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); | ||
41 | + } | ||
42 | + | ||
43 | + @Test | ||
44 | + public void testEquality() { | ||
45 | + new EqualsTester() | ||
46 | + .addEqualityGroup(address1, sameAsAddress1) | ||
47 | + .addEqualityGroup(address2).testEquals(); | ||
48 | + } | ||
49 | + | ||
50 | + @Test | ||
51 | + public void testConstruction() { | ||
52 | + LispIpv4Address ipv4Address = address1; | ||
53 | + assertThat(ipv4Address.getAddress(), is(IpAddress.valueOf("192.168.1.1"))); | ||
54 | + } | ||
55 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.IpAddress; | ||
22 | + | ||
23 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
24 | +import static org.hamcrest.Matchers.is; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for LispIpv6Address class. | ||
28 | + */ | ||
29 | +public class LispIpv6AddressTest { | ||
30 | + | ||
31 | + private LispIpv6Address address1; | ||
32 | + private LispIpv6Address sameAsAddress1; | ||
33 | + private LispIpv6Address address2; | ||
34 | + | ||
35 | + @Before | ||
36 | + public void setup() { | ||
37 | + | ||
38 | + address1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885")); | ||
39 | + sameAsAddress1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885")); | ||
40 | + address2 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8886")); | ||
41 | + } | ||
42 | + | ||
43 | + @Test | ||
44 | + public void testEquality() { | ||
45 | + new EqualsTester() | ||
46 | + .addEqualityGroup(address1, sameAsAddress1) | ||
47 | + .addEqualityGroup(address2).testEquals(); | ||
48 | + } | ||
49 | + | ||
50 | + @Test | ||
51 | + public void testConstruction() { | ||
52 | + LispIpv6Address ipv6Address = address1; | ||
53 | + assertThat(ipv6Address.getAddress(), is(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885"))); | ||
54 | + } | ||
55 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | + | ||
22 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
23 | +import static org.hamcrest.Matchers.is; | ||
24 | + | ||
25 | +/** | ||
26 | + * Unit tests for LispLcafAddress class. | ||
27 | + */ | ||
28 | +public class LispLcafAddressTest { | ||
29 | + | ||
30 | + private LispLcafAddress address1; | ||
31 | + private LispLcafAddress sameAsAddress1; | ||
32 | + private LispLcafAddress address2; | ||
33 | + | ||
34 | + @Before | ||
35 | + public void setup() { | ||
36 | + | ||
37 | + address1 = new LispLcafAddress(LispCanonicalAddressFormatEnum.NAT, | ||
38 | + (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01); | ||
39 | + sameAsAddress1 = new LispLcafAddress(LispCanonicalAddressFormatEnum.NAT, | ||
40 | + (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01); | ||
41 | + address2 = new LispLcafAddress(LispCanonicalAddressFormatEnum.NAT, | ||
42 | + (byte) 0x02, (byte) 0x02, (byte) 0x02, (byte) 0x02); | ||
43 | + } | ||
44 | + | ||
45 | + @Test | ||
46 | + public void testEquality() { | ||
47 | + new EqualsTester() | ||
48 | + .addEqualityGroup(address1, sameAsAddress1) | ||
49 | + .addEqualityGroup(address2).testEquals(); | ||
50 | + } | ||
51 | + | ||
52 | + @Test | ||
53 | + public void testConstruction() { | ||
54 | + LispLcafAddress lcafAddress = address1; | ||
55 | + | ||
56 | + assertThat(lcafAddress.getType(), is(LispCanonicalAddressFormatEnum.NAT)); | ||
57 | + assertThat(lcafAddress.getReserved1(), is((byte) 0x01)); | ||
58 | + assertThat(lcafAddress.getReserved2(), is((byte) 0x01)); | ||
59 | + assertThat(lcafAddress.getFlag(), is((byte) 0x01)); | ||
60 | + assertThat(lcafAddress.getLength(), is((byte) 0x01)); | ||
61 | + } | ||
62 | +} |
protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispListLcafAddressTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.collect.Lists; | ||
19 | +import com.google.common.testing.EqualsTester; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onlab.packet.IpAddress; | ||
23 | + | ||
24 | +import java.util.List; | ||
25 | + | ||
26 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
27 | +import static org.hamcrest.Matchers.is; | ||
28 | + | ||
29 | +/** | ||
30 | + * Unit tests for LispListLcafAddress class. | ||
31 | + */ | ||
32 | +public class LispListLcafAddressTest { | ||
33 | + | ||
34 | + private LispListLcafAddress address1; | ||
35 | + private LispListLcafAddress sameAsAddress1; | ||
36 | + private LispListLcafAddress address2; | ||
37 | + | ||
38 | + @Before | ||
39 | + public void setup() { | ||
40 | + | ||
41 | + LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
42 | + LispAfiAddress ipv6Address1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885")); | ||
43 | + | ||
44 | + List<LispAfiAddress> afiAddresses1 = Lists.newArrayList(); | ||
45 | + afiAddresses1.add(ipv4Address1); | ||
46 | + afiAddresses1.add(ipv6Address1); | ||
47 | + | ||
48 | + address1 = new LispListLcafAddress(afiAddresses1); | ||
49 | + | ||
50 | + sameAsAddress1 = new LispListLcafAddress(afiAddresses1); | ||
51 | + | ||
52 | + LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); | ||
53 | + LispAfiAddress ipv6Address2 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8886")); | ||
54 | + | ||
55 | + List<LispAfiAddress> afiAddresses2 = Lists.newArrayList(); | ||
56 | + afiAddresses2.add(ipv4Address2); | ||
57 | + afiAddresses2.add(ipv6Address2); | ||
58 | + | ||
59 | + address2 = new LispListLcafAddress(afiAddresses2); | ||
60 | + } | ||
61 | + | ||
62 | + @Test | ||
63 | + public void testEquality() { | ||
64 | + new EqualsTester() | ||
65 | + .addEqualityGroup(address1, sameAsAddress1) | ||
66 | + .addEqualityGroup(address2).testEquals(); | ||
67 | + } | ||
68 | + | ||
69 | + @Test | ||
70 | + public void testConstruction() { | ||
71 | + LispListLcafAddress listLcafAddress = address1; | ||
72 | + | ||
73 | + LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
74 | + LispAfiAddress ipv6Address1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885")); | ||
75 | + | ||
76 | + List<LispAfiAddress> afiAddresses1 = Lists.newArrayList(); | ||
77 | + afiAddresses1.add(ipv4Address1); | ||
78 | + afiAddresses1.add(ipv6Address1); | ||
79 | + | ||
80 | + assertThat(listLcafAddress.getAddresses(), is(afiAddresses1)); | ||
81 | + } | ||
82 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.MacAddress; | ||
22 | + | ||
23 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
24 | +import static org.hamcrest.Matchers.is; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for LispMacAddress class. | ||
28 | + */ | ||
29 | +public class LispMacAddressTest { | ||
30 | + | ||
31 | + private LispMacAddress address1; | ||
32 | + private LispMacAddress sameAsAddress1; | ||
33 | + private LispMacAddress address2; | ||
34 | + | ||
35 | + @Before | ||
36 | + public void setup() { | ||
37 | + | ||
38 | + address1 = new LispMacAddress(MacAddress.valueOf("00:00:00:00:00:01")); | ||
39 | + sameAsAddress1 = new LispMacAddress(MacAddress.valueOf("00:00:00:00:00:01")); | ||
40 | + address2 = new LispMacAddress(MacAddress.valueOf("00:00:00:00:00:02")); | ||
41 | + } | ||
42 | + | ||
43 | + @Test | ||
44 | + public void testEquality() { | ||
45 | + new EqualsTester() | ||
46 | + .addEqualityGroup(address1, sameAsAddress1) | ||
47 | + .addEqualityGroup(address2).testEquals(); | ||
48 | + } | ||
49 | + | ||
50 | + @Test | ||
51 | + public void testConstruction() { | ||
52 | + LispMacAddress macAddress = address1; | ||
53 | + assertThat(macAddress.getAddress(), is(MacAddress.valueOf("00:00:00:00:00:01"))); | ||
54 | + } | ||
55 | +} |
protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSegmentLcafAddressTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.IpAddress; | ||
22 | + | ||
23 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
24 | +import static org.hamcrest.Matchers.is; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for LispSegmentLcafAddress class. | ||
28 | + */ | ||
29 | +public class LispSegmentLcafAddressTest { | ||
30 | + | ||
31 | + private LispSegmentLcafAddress address1; | ||
32 | + private LispSegmentLcafAddress sameAsAddress1; | ||
33 | + private LispSegmentLcafAddress address2; | ||
34 | + | ||
35 | + @Before | ||
36 | + public void setup() { | ||
37 | + | ||
38 | + LispIpv4Address ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
39 | + address1 = new LispSegmentLcafAddress((byte) 0x01, 1, ipv4Address1); | ||
40 | + | ||
41 | + sameAsAddress1 = new LispSegmentLcafAddress((byte) 0x01, 1, ipv4Address1); | ||
42 | + | ||
43 | + LispIpv4Address ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); | ||
44 | + address2 = new LispSegmentLcafAddress((byte) 0x02, 2, ipv4Address2); | ||
45 | + } | ||
46 | + | ||
47 | + @Test | ||
48 | + public void testEquality() { | ||
49 | + new EqualsTester() | ||
50 | + .addEqualityGroup(address1, sameAsAddress1) | ||
51 | + .addEqualityGroup(address2).testEquals(); | ||
52 | + } | ||
53 | + | ||
54 | + @Test | ||
55 | + public void testConstruction() { | ||
56 | + LispSegmentLcafAddress segmentLcafAddress = address1; | ||
57 | + | ||
58 | + LispIpv4Address ipv4Address = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
59 | + | ||
60 | + assertThat(segmentLcafAddress.getIdMaskLength(), is((byte) 0x01)); | ||
61 | + assertThat(segmentLcafAddress.getInstanceId(), is(1)); | ||
62 | + assertThat(segmentLcafAddress.getAddress(), is(ipv4Address)); | ||
63 | + } | ||
64 | +} |
protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddressTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present 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.lisp.msg.types; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.IpAddress; | ||
22 | + | ||
23 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
24 | +import static org.hamcrest.Matchers.is; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for LispSourceDestLcafAddress class. | ||
28 | + */ | ||
29 | +public class LispSourceDestLcafAddressTest { | ||
30 | + | ||
31 | + private LispSourceDestLcafAddress address1; | ||
32 | + private LispSourceDestLcafAddress sameAsAddress1; | ||
33 | + private LispSourceDestLcafAddress address2; | ||
34 | + | ||
35 | + @Before | ||
36 | + public void setup() { | ||
37 | + | ||
38 | + LispIpv4Address srcAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
39 | + LispIpv4Address dstAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); | ||
40 | + | ||
41 | + address1 = new LispSourceDestLcafAddress((short) 1, (byte) 0x01, | ||
42 | + (byte) 0x01, srcAddress1, dstAddress1); | ||
43 | + | ||
44 | + sameAsAddress1 = new LispSourceDestLcafAddress((short) 1, (byte) 0x01, | ||
45 | + (byte) 0x01, srcAddress1, dstAddress1); | ||
46 | + | ||
47 | + LispIpv4Address srcAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); | ||
48 | + LispIpv4Address dstAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.2")); | ||
49 | + | ||
50 | + address2 = new LispSourceDestLcafAddress((short) 2, (byte) 0x02, | ||
51 | + (byte) 0x02, srcAddress2, dstAddress2); | ||
52 | + } | ||
53 | + | ||
54 | + @Test | ||
55 | + public void testEquality() { | ||
56 | + new EqualsTester() | ||
57 | + .addEqualityGroup(address1, sameAsAddress1) | ||
58 | + .addEqualityGroup(address2).testEquals(); | ||
59 | + } | ||
60 | + | ||
61 | + @Test | ||
62 | + public void testConstruction() { | ||
63 | + LispSourceDestLcafAddress sourceDestLcafAddress = address1; | ||
64 | + | ||
65 | + LispIpv4Address srcAddress = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
66 | + LispIpv4Address dstAddress = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); | ||
67 | + | ||
68 | + assertThat(sourceDestLcafAddress.getReserved(), is((short) 1)); | ||
69 | + assertThat(sourceDestLcafAddress.getSrcMaskLength(), is((byte) 0x01)); | ||
70 | + assertThat(sourceDestLcafAddress.getDstMaskLength(), is((byte) 0x01)); | ||
71 | + assertThat(sourceDestLcafAddress.getSrcPrefix(), is(srcAddress)); | ||
72 | + assertThat(sourceDestLcafAddress.getDstPrefix(), is(dstAddress)); | ||
73 | + } | ||
74 | +} |
-
Please register or login to post a comment