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;
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Matchers.eq;
21 import static org.mockito.Mockito.doAnswer;
22 import static org.mockito.Mockito.doReturn;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
26 import io.fd.honeycomb.translate.vpp.util.NamingContext;
27 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
28 import io.fd.vpp.jvpp.core.dto.CreateLoopback;
29 import io.fd.vpp.jvpp.core.dto.CreateLoopbackReply;
30 import io.fd.vpp.jvpp.core.dto.DeleteLoopback;
31 import io.fd.vpp.jvpp.core.dto.DeleteLoopbackReply;
32 import org.junit.Test;
33 import org.mockito.invocation.InvocationOnMock;
34 import org.mockito.stubbing.Answer;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
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.InterfaceKey;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Loopback;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.LoopbackBuilder;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 public class LoopbackCustomizerTest extends WriterCustomizerTest {
46 private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
47 private LoopbackCustomizer loopCustomizer;
50 public void setUp() throws Exception {
51 InterfaceTypeTestUtils.setupWriteContext(writeContext,
52 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.Loopback.class);
53 loopCustomizer = new LoopbackCustomizer(api, new NamingContext("ifcintest", IFC_TEST_INSTANCE));
57 public void testCreate() throws Exception {
58 doAnswer(new Answer() {
63 public Object answer(final InvocationOnMock invocation) throws Throwable {
64 final CreateLoopbackReply t = new CreateLoopbackReply();
68 }).when(api).createLoopback(any(CreateLoopback.class));
70 loopCustomizer.writeCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext);
71 loopCustomizer.writeCurrentAttributes(getLoopbackId("loop2"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext);
73 verify(api, times(2)).createLoopback(any(CreateLoopback.class));
74 verify(mappingContext).put(eq(mappingIid("loop", IFC_TEST_INSTANCE)), eq(
75 mapping("loop", 0).get()));
76 verify(mappingContext).put(eq(mappingIid("loop2", IFC_TEST_INSTANCE)), eq(
77 mapping("loop2", 1).get()));
81 public void testDelete() throws Exception {
82 final CreateLoopbackReply t = new CreateLoopbackReply();
84 doReturn(future(t)).when(api).createLoopback(any(CreateLoopback.class));
86 doReturn(future(new DeleteLoopbackReply())).when(api).deleteLoopback(any(DeleteLoopback.class));
88 loopCustomizer.writeCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext);
89 defineMapping(mappingContext, "loop", 1, IFC_TEST_INSTANCE);
90 loopCustomizer.deleteCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext);
92 verify(api).createLoopback(any(CreateLoopback.class));
93 verify(api).deleteLoopback(any(DeleteLoopback.class));
94 verify(mappingContext).delete(eq(mappingIid("loop", IFC_TEST_INSTANCE)));
97 private InstanceIdentifier<Loopback> getLoopbackId(final String loop) {
98 return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(loop)).augmentation(
99 VppInterfaceAugmentation.class).child(Loopback.class);
102 private Loopback getLoopbackData(final String mac) {
103 return new LoopbackBuilder().setMac(new PhysAddress(mac)).build();