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.acl;
19 import static org.mockito.Mockito.doReturn;
20 import static org.mockito.Mockito.when;
22 import com.google.common.base.Optional;
23 import io.fd.honeycomb.translate.write.WriteFailedException;
24 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
25 import java.util.Collections;
26 import java.util.List;
27 import org.junit.Test;
28 import org.mockito.Mock;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.EthAcl;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentationBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.AccessListsBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.access.lists.AclBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.IetfAclBuilder;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 public class AclWriterTest extends WriterCustomizerTest {
47 private static final String ACL_NAME = "acl1";
48 private static final Class<? extends AclBase> ACL_TYPE = EthAcl.class;
49 private static final InstanceIdentifier<Acl> IID =
50 InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey(ACL_NAME, ACL_TYPE));
54 private AclWriter customizer;
58 customizer = new AclWriter();
59 when(acl.getAclName()).thenReturn(ACL_NAME);
60 doReturn(ACL_TYPE).when(acl).getAclType();
63 private void defineInterfacesContext(final List<Interface> interfaces) {
64 when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of(
65 new InterfacesBuilder().setInterface(interfaces).build()
70 public void testWrite() throws Exception {
71 customizer.writeCurrentAttributes(IID, acl, writeContext);
75 public void testUpdate() throws WriteFailedException {
76 defineInterfacesContext(Collections.emptyList());
77 customizer.updateCurrentAttributes(IID, acl, acl, writeContext);
81 public void testDelete() throws WriteFailedException {
82 defineInterfacesContext(Collections.emptyList());
83 customizer.deleteCurrentAttributes(IID, acl, writeContext);
86 @Test(expected = WriteFailedException.class)
87 public void testDeleteFailed() throws WriteFailedException {
88 final Interface iface = new InterfaceBuilder().addAugmentation(VppInterfaceAugmentation.class,
89 new VppInterfaceAugmentationBuilder().setIetfAcl(
90 new IetfAclBuilder().setAccessLists(
91 new AccessListsBuilder().setAcl(
92 Collections.singletonList(new AclBuilder().setName(ACL_NAME).setType(ACL_TYPE).build())
97 defineInterfacesContext(Collections.singletonList(iface));
98 customizer.deleteCurrentAttributes(IID, acl, writeContext);