diff options
Diffstat (limited to 'acl/acl-impl/src/test/java/io')
-rw-r--r-- | acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java | 28 | ||||
-rw-r--r-- | acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclValidatorTest.java (renamed from acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclReferenceCheckTest.java) | 67 |
2 files changed, 62 insertions, 33 deletions
diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java index 63633aa75..a3fa6db0e 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java @@ -18,9 +18,7 @@ package io.fd.hc2vpp.acl.write; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -43,7 +41,6 @@ import io.fd.vpp.jvpp.acl.types.AclRule; import io.fd.vpp.jvpp.acl.types.MacipAclRule; import java.nio.charset.StandardCharsets; import java.util.Arrays; -import java.util.Collections; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -53,10 +50,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.cont import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceStateAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -278,27 +271,6 @@ public class VppAclCustomizerTest extends WriterCustomizerTest implements AclTes assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); } - @Test - public void deleteCurrentAttributesUdpReferenced( - @InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") - AccessLists standardAcls, - @InjectTestData(resourcePath = "/acl/standard/interface-ref-acl-udp.json") - Interfaces references) throws Exception { - // TODO - HONEYCOMB-349 - change after resolving to specific node injection - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn( - Optional.of(new InterfacesBuilder().setInterface(references.getInterface()).build())); - - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - try { - aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - } catch (IllegalStateException e) { - verify(aclApi, never()).aclDel(any(AclDel.class)); - return; - } - fail("IllegalStateException should have been thrown"); - } - private void verifyUdpRequest(final int aclIndex) { final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); assertEquals(aclIndex, request.aclIndex); diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclReferenceCheckTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclValidatorTest.java index 8d89845f6..287e53f80 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclReferenceCheckTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclValidatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Cisco and/or its affiliates. + * Copyright (c) 2018 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. @@ -16,7 +16,7 @@ package io.fd.hc2vpp.acl.write; -import static io.fd.hc2vpp.acl.write.VppAclCustomizer.AclReferenceCheck.checkAclReferenced; +import static io.fd.hc2vpp.acl.write.VppAclValidator.checkAclReferenced; import static java.util.stream.Collectors.toSet; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -28,33 +28,90 @@ import com.google.common.base.Optional; import io.fd.hc2vpp.acl.AclTestSchemaContext; import io.fd.honeycomb.test.tools.HoneycombTestRunner; import io.fd.honeycomb.test.tools.annotations.InjectTestData; +import io.fd.honeycomb.translate.write.DataValidationFailedException; import io.fd.honeycomb.translate.write.WriteContext; import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAcl; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - @RunWith(HoneycombTestRunner.class) -public class AclReferenceCheckTest implements AclTestSchemaContext { +public class VppAclValidatorTest implements AclTestSchemaContext { + + private static final InstanceIdentifier<Acl> ID = InstanceIdentifier.create(AccessLists.class) + .child(Acl.class, new AclKey("standard-acl", VppAcl.class)); - @InjectTestData(id = "/ietf-interfaces:interfaces", resourcePath = "/reference/acl-references.json") + @InjectTestData(id = "/ietf-interfaces:interfaces", resourcePath = "/interface-acl/acl-references.json") private Interfaces interfaces; @Mock private WriteContext writeContext; + private VppAclValidator validator; + @Before public void init(){ initMocks(this); when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of(interfaces)); + validator = new VppAclValidator(); + } + + @Test + public void testValidateWrite( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") AccessLists acls) + throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(ID, acls.getAcl().get(0), writeContext); + } + + @Test(expected = DataValidationFailedException.CreateValidationFailedException.class) + public void testValidateWriteEmptyAcl() + throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(ID, new AclBuilder().build(), writeContext); + } + + @Test + public void testValidateUpdate( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") AccessLists acls) + throws DataValidationFailedException.UpdateValidationFailedException { + final Acl data = acls.getAcl().get(0); + validator.validateUpdate(ID, data, data, writeContext); + } + + @Test(expected = DataValidationFailedException.UpdateValidationFailedException.class) + public void testValidateUpdateUnsupportedType( + @InjectTestData(resourcePath = "/acl/ipv4/ipv4-acl.json") AccessLists acls) + throws DataValidationFailedException.UpdateValidationFailedException { + final Acl data = acls.getAcl().get(0); + validator.validateUpdate(ID, data, data, writeContext); + } + + @Test + public void testValidateDelete( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") AccessLists acls) + throws DataValidationFailedException.DeleteValidationFailedException { + validator.validateDelete(ID, acls.getAcl().get(0), writeContext); + } + + @Test(expected = DataValidationFailedException.DeleteValidationFailedException.class) + public void testValidateDeleteReferenced( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") + AccessLists standardAcls, + @InjectTestData(resourcePath = "/acl/standard/interface-ref-acl-udp.json") + Interfaces references) throws Exception { + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn( + Optional.of(new InterfacesBuilder().setInterface(references.getInterface()).build())); + validator.validateDelete(ID, standardAcls.getAcl().get(0), writeContext); } @Test |