HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / InterfaceCustomizerTest.java
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.lisp.translate.write;
18
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;
26
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;
45
46 public class InterfaceCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
47
48     @Captor
49     private ArgumentCaptor<LispAddDelLocator> intfCaptor;
50
51     private InstanceIdentifier<Interface> id;
52     private Interface intf;
53     private InterfaceCustomizer customizer;
54
55     @Override
56     public void setUp() {
57         final String ifcCtxName = "INInterruptedException, ExecutionException, STANCE";
58         final String interfaceName = "Interface";
59         defineMapping(mappingContext, interfaceName, 5, ifcCtxName);
60
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))
66                 .build();
67
68         intf = new InterfaceBuilder()
69                 .setPriority((short) 1)
70                 .setWeight((short) 2)
71                 .build();
72
73         customizer = new InterfaceCustomizer(api, new NamingContext("PREFIX", ifcCtxName));
74
75         when(api.lispAddDelLocator(any(LispAddDelLocator.class))).thenReturn(future(new LispAddDelLocatorReply()));
76     }
77
78     @Test(expected = NullPointerException.class)
79     public void testWriteCurrentAttributesNullData() throws WriteFailedException {
80         customizer.writeCurrentAttributes(null, null, null);
81     }
82
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);
88
89         customizer.writeCurrentAttributes(null, intf, null);
90     }
91
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);
97
98         customizer.writeCurrentAttributes(null, intf, null);
99     }
100
101     @Test
102     public void testWriteCurrentAttributes() throws WriteFailedException {
103         customizer.writeCurrentAttributes(id, intf, writeContext);
104
105         verify(api, times(1)).lispAddDelLocator(intfCaptor.capture());
106
107         LispAddDelLocator request = intfCaptor.getValue();
108
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));
115     }
116
117     @Test(expected = UnsupportedOperationException.class)
118     public void testUpdateCurrentAttributes() throws WriteFailedException {
119         customizer.updateCurrentAttributes(null, null, null, null);
120     }
121
122     @Test(expected = NullPointerException.class)
123     public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
124         customizer.deleteCurrentAttributes(null, null, null);
125     }
126
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);
132
133         customizer.deleteCurrentAttributes(null, interf, null);
134     }
135
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);
141
142         customizer.deleteCurrentAttributes(null, interf, null);
143     }
144
145     @Test
146     public void testDeleteCurrentAttributes() throws WriteFailedException {
147         customizer.deleteCurrentAttributes(id, intf, writeContext);
148
149         verify(api, times(1)).lispAddDelLocator(intfCaptor.capture());
150
151         LispAddDelLocator request = intfCaptor.getValue();
152
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));
159     }
160 }