2 * Copyright (c) 2015 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.lisp.translate.write;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.mockito.Matchers.any;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
27 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
28 import io.fd.honeycomb.translate.vpp.util.NamingContext;
29 import io.fd.honeycomb.translate.write.WriteFailedException;
30 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
31 import org.junit.Test;
32 import org.mockito.ArgumentCaptor;
33 import org.mockito.Captor;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.lisp.feature.data.grouping.LispFeatureData;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.LocatorSets;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSet;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetKey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.Interface;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.InterfaceBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.InterfaceKey;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import io.fd.vpp.jvpp.core.dto.LispAddDelLocator;
44 import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorReply;
46 public class InterfaceCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
49 private ArgumentCaptor<LispAddDelLocator> intfCaptor;
51 private InstanceIdentifier<Interface> id;
52 private Interface intf;
53 private InterfaceCustomizer customizer;
57 final String ifcCtxName = "INInterruptedException, ExecutionException, STANCE";
58 final String interfaceName = "Interface";
59 defineMapping(mappingContext, interfaceName, 5, ifcCtxName);
61 id = InstanceIdentifier.builder(Lisp.class)
62 .child(LispFeatureData.class)
63 .child(LocatorSets.class)
64 .child(LocatorSet.class, new LocatorSetKey("Locator"))
65 .child(Interface.class, new InterfaceKey(interfaceName))
68 intf = new InterfaceBuilder()
69 .setPriority((short) 1)
73 customizer = new InterfaceCustomizer(api, new NamingContext("PREFIX", ifcCtxName));
75 when(api.lispAddDelLocator(any(LispAddDelLocator.class))).thenReturn(future(new LispAddDelLocatorReply()));
78 @Test(expected = NullPointerException.class)
79 public void testWriteCurrentAttributesNullData() throws WriteFailedException {
80 customizer.writeCurrentAttributes(null, null, null);
83 @Test(expected = NullPointerException.class)
84 public void testWriteCurrentAttributesNullPriority() throws WriteFailedException {
85 Interface intf = mock(Interface.class);
86 when(intf.getWeight()).thenReturn((short) 1);
87 when(intf.getPriority()).thenReturn(null);
89 customizer.writeCurrentAttributes(null, intf, null);
92 @Test(expected = NullPointerException.class)
93 public void testWriteCurrentAttributesNullWeight() throws WriteFailedException {
94 Interface intf = mock(Interface.class);
95 when(intf.getWeight()).thenReturn(null);
96 when(intf.getPriority()).thenReturn((short) 1);
98 customizer.writeCurrentAttributes(null, intf, null);
102 public void testWriteCurrentAttributes() throws WriteFailedException {
103 customizer.writeCurrentAttributes(id, intf, writeContext);
105 verify(api, times(1)).lispAddDelLocator(intfCaptor.capture());
107 LispAddDelLocator request = intfCaptor.getValue();
109 assertNotNull(request);
110 assertEquals(1, request.isAdd);
111 assertEquals(2, request.weight);
112 assertEquals(1, request.priority);
113 assertEquals(5, request.swIfIndex);
114 assertEquals("Locator", toString(request.locatorSetName));
117 @Test(expected = UnsupportedOperationException.class)
118 public void testUpdateCurrentAttributes() throws WriteFailedException {
119 customizer.updateCurrentAttributes(null, null, null, null);
122 @Test(expected = NullPointerException.class)
123 public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
124 customizer.deleteCurrentAttributes(null, null, null);
127 @Test(expected = NullPointerException.class)
128 public void testDeleteCurrentAttributesNullPriority() throws WriteFailedException {
129 Interface interf = mock(Interface.class);
130 when(interf.getWeight()).thenReturn((short) 1);
131 when(interf.getPriority()).thenReturn(null);
133 customizer.deleteCurrentAttributes(null, interf, null);
136 @Test(expected = NullPointerException.class)
137 public void testDeleteCurrentAttributesNullWeight() throws WriteFailedException {
138 Interface interf = mock(Interface.class);
139 when(interf.getWeight()).thenReturn(null);
140 when(interf.getPriority()).thenReturn((short) 1);
142 customizer.deleteCurrentAttributes(null, interf, null);
146 public void testDeleteCurrentAttributes() throws WriteFailedException {
147 customizer.deleteCurrentAttributes(id, intf, writeContext);
149 verify(api, times(1)).lispAddDelLocator(intfCaptor.capture());
151 LispAddDelLocator request = intfCaptor.getValue();
153 assertNotNull(request);
154 assertEquals(0, request.isAdd);
155 assertEquals(2, request.weight);
156 assertEquals(1, request.priority);
157 assertEquals(5, request.swIfIndex);
158 assertEquals("Locator", toString(request.locatorSetName));