HONEYCOMB-58 - Routing Api
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfaces / ip / subnet / validation / SubnetValidatorTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
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 io.fd.honeycomb.translate.v3po.interfaces.ip.subnet.validation;
18
19
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;
29
30 public class SubnetValidatorTest {
31
32     private SubnetValidator subnetValidator;
33
34     @Before
35     public void init() {
36         subnetValidator = new SubnetValidator();
37     }
38
39     @Test(expected = SubnetValidationException.class)
40     public void testValidateNegativeSameTypes() throws SubnetValidationException {
41         List<Address> addresses = Lists.newArrayList();
42
43         addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
44                 .build());
45         addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
46                 .build());
47
48         subnetValidator.checkNotAddingToSameSubnet(addresses);
49     }
50
51     @Test(expected = SubnetValidationException.class)
52     public void testValidateNegativeMixedTypes() throws SubnetValidationException {
53         List<Address> addresses = Lists.newArrayList();
54
55         addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
56                 .build());
57         addresses.add(new AddressBuilder()
58                 .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.255.0")).build())
59                 .build());
60
61         subnetValidator.checkNotAddingToSameSubnet(addresses);
62     }
63
64     @Test
65     public void testValidatePositiveSameTypes() throws SubnetValidationException {
66         List<Address> addresses = Lists.newArrayList();
67
68         addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
69                 .build());
70         addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 25).build())
71                 .build());
72
73         subnetValidator.checkNotAddingToSameSubnet(addresses);
74     }
75
76     @Test
77     public void testValidatePositiveMixedTypes() throws SubnetValidationException {
78         List<Address> addresses = Lists.newArrayList();
79
80         addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build())
81                 .build());
82         addresses.add(new AddressBuilder()
83                 .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.0.0")).build())
84                 .build());
85
86         subnetValidator.checkNotAddingToSameSubnet(addresses);
87     }
88 }