diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-03-03 09:21:00 +0100 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2017-03-03 09:21:00 +0100 |
commit | 9453a0f3c2f6c04a6f67988fa6617a7918e4bbc7 (patch) | |
tree | 8b986132e8912676ba132f82b1e117a3236d1e36 /v3po/v3po2vpp/src/test | |
parent | aa2919c2bd6dcad22212a1bd123988e09daf1e38 (diff) |
HC2VPP-78 - subnet validation fix
Validation removed, more descriptive expcetion handling to be added
after VPP-649
Change-Id: I6e0a84b2dc3f3c9d3d943874baa508636a1df808
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test')
2 files changed, 1 insertions, 131 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidatorTest.java deleted file mode 100644 index faa860f45..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidatorTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation; - - -import com.google.common.collect.Lists; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; - -public class Ipv4SubnetValidatorTest { - - private Ipv4SubnetValidator subnetValidator; - - @Before - public void init() { - subnetValidator = new Ipv4SubnetValidator(); - } - - @Test(expected = SubnetValidationException.class) - public void testValidateNegativeSameTypes() throws SubnetValidationException { - List<Address> addresses = Lists.newArrayList(); - - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - - subnetValidator.checkNotAddingToSameSubnet(addresses); - } - - @Test(expected = SubnetValidationException.class) - public void testValidateNegativeMixedTypes() throws SubnetValidationException { - List<Address> addresses = Lists.newArrayList(); - - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - addresses.add(new AddressBuilder() - .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.255.0")).build()) - .build()); - - subnetValidator.checkNotAddingToSameSubnet(addresses); - } - - @Test - public void testValidatePositiveSameTypes() throws SubnetValidationException { - List<Address> addresses = Lists.newArrayList(); - - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 25).build()) - .build()); - - subnetValidator.checkNotAddingToSameSubnet(addresses); - } - - @Test - public void testValidatePositiveMixedTypes() throws SubnetValidationException { - List<Address> addresses = Lists.newArrayList(); - - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - addresses.add(new AddressBuilder() - .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.0.0")).build()) - .build()); - - subnetValidator.checkNotAddingToSameSubnet(addresses); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java index 8f3dafd10..ffae78ea8 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java @@ -30,8 +30,6 @@ import static org.mockito.Mockito.when; import com.google.common.base.Optional; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.Ipv4SubnetValidator; -import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.SubnetValidationException; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.VppBaseCallException; import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; @@ -68,9 +66,6 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { private static final String IFACE_NAME = "eth0"; private static final int IFACE_ID = 123; - @Mock - private Ipv4SubnetValidator subnetValidator; - private NamingContext interfaceContext; private Ipv4AddressCustomizer customizer; @@ -92,11 +87,9 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { public void setUpTest() throws Exception { interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - customizer = new Ipv4AddressCustomizer(api, interfaceContext, subnetValidator); + customizer = new Ipv4AddressCustomizer(api, interfaceContext); doReturn(future(new IpAddressDetailsReplyDump())).when(api).ipAddressDump(any()); - when(writeContext.readAfter(Mockito.any())) - .thenReturn(Optional.of(new Ipv4Builder().setAddress(Collections.emptyList()).build())); } private void whenSwInterfaceAddDelAddressThenSuccess() { @@ -109,8 +102,6 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { @Test public void testAddPrefixLengthIpv4Address() throws Exception { - doNothing().when(subnetValidator).checkNotAddingToSameSubnet(Mockito.anyList()); - final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME); when(writeContext.readBefore(id)).thenReturn(Optional.absent()); @@ -151,39 +142,6 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { fail("WriteFailedException was expected"); } - @Test - public void testAddPrefixLengthIpv4AddressConflicted() throws Exception { - - final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME); - when(writeContext.readBefore(id)).thenReturn(Optional.absent()); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - final List<Address> addressList = Arrays.asList(data); - - //throws when validation invoked - Mockito.doThrow(SubnetValidationException.forConflictingData((short) 24, Arrays.asList(data))).when(subnetValidator) - .checkNotAddingToSameSubnet(addressList); - - //fake data return from WriteContext - doReturn(Optional.of(new Ipv4Builder().setAddress(addressList).build())).when(writeContext) - .readAfter(argThat(matchInstanceIdentifier(Ipv4.class))); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - try { - customizer.writeCurrentAttributes(id, data, writeContext); - } catch (WriteFailedException e) { - //verifies if cause of exception is correct type - assertTrue(e.getCause() instanceof SubnetValidationException); - - //verify that validation call was invoked with data from writeContext - verify(subnetValidator, times(1)).checkNotAddingToSameSubnet(addressList); - } - - } - @Test(expected = WriteFailedException.UpdateFailedException.class) public void testUpdate() throws Exception { final Address data = mock(Address.class); |