2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.translate.v3po.interfaces.ip.subnet.validation;
20 import com.google.common.collect.Lists;
21 import java.util.List;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad;
30 public class SubnetValidatorTest {
32 private SubnetValidator subnetValidator;
36 subnetValidator = new SubnetValidator();
39 @Test(expected = SubnetValidationException.class)
40 public void testValidateNegativeSameTypes() throws SubnetValidationException {
41 List<Address> addresses = Lists.newArrayList();
43 addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
45 addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
48 subnetValidator.checkNotAddingToSameSubnet(addresses);
51 @Test(expected = SubnetValidationException.class)
52 public void testValidateNegativeMixedTypes() throws SubnetValidationException {
53 List<Address> addresses = Lists.newArrayList();
55 addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
57 addresses.add(new AddressBuilder()
58 .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.255.0")).build())
61 subnetValidator.checkNotAddingToSameSubnet(addresses);
65 public void testValidatePositiveSameTypes() throws SubnetValidationException {
66 List<Address> addresses = Lists.newArrayList();
68 addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
70 addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 25).build())
73 subnetValidator.checkNotAddingToSameSubnet(addresses);
77 public void testValidatePositiveMixedTypes() throws SubnetValidationException {
78 List<Address> addresses = Lists.newArrayList();
80 addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
82 addresses.add(new AddressBuilder()
83 .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.0.0")).build())
86 subnetValidator.checkNotAddingToSameSubnet(addresses);