HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfaces / RoutingCustomizerTest.java
1 /*
2  * Copyright (c) 2016 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.translate.v3po.interfaces;
18
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.verifyZeroInteractions;
22 import static org.mockito.Mockito.when;
23
24 import io.fd.honeycomb.translate.vpp.util.NamingContext;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
27 import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTable;
28 import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTableReply;
29 import org.junit.Test;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Routing;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.RoutingBuilder;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37
38 public class RoutingCustomizerTest extends WriterCustomizerTest {
39     private static final String IFACE_CTX_NAME = "interface-ctx";
40     private static final String IF_NAME = "eth1";
41     private static final int IF_INDEX = 1;
42     private static final InstanceIdentifier<Routing> IID =
43             InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME))
44                     .augmentation(VppInterfaceAugmentation.class).child(Routing.class);
45
46     private RoutingCustomizer customizer;
47
48     @Override
49     protected void setUp() throws Exception {
50         customizer = new RoutingCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME));
51         defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME);
52     }
53
54     @Test
55     public void testWrite() throws WriteFailedException {
56         final int vrfId = 123;
57         when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
58         customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext);
59         verify(api).swInterfaceSetTable(expectedRequest(vrfId));
60     }
61
62     @Test(expected = WriteFailedException.class)
63     public void testWriteFailed() throws WriteFailedException {
64         when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
65         customizer.writeCurrentAttributes(IID, routing(213), writeContext);
66     }
67
68     @Test
69     public void testUpdate() throws WriteFailedException {
70         when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
71         customizer.updateCurrentAttributes(IID, routing(123L), null, writeContext);
72         verifyZeroInteractions(api);
73     }
74
75     @Test(expected = WriteFailedException.class)
76     public void testUpdateFailed() throws WriteFailedException {
77         when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
78         customizer.updateCurrentAttributes(IID, routing(123L), routing(321L), writeContext);
79     }
80
81     @Test
82     public void testDelete() throws WriteFailedException {
83         when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
84         customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
85         verify(api).swInterfaceSetTable(expectedRequest(0));
86     }
87
88     @Test(expected = WriteFailedException.DeleteFailedException.class)
89     public void testDeleteFailed() throws WriteFailedException {
90         when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
91         customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
92     }
93
94     private Routing routing(final long vrfId) {
95         return new RoutingBuilder().setVrfId(vrfId).build();
96     }
97
98     private SwInterfaceSetTable expectedRequest(final int vrfId) {
99         final SwInterfaceSetTable request = new SwInterfaceSetTable();
100         request.isIpv6 = 0;
101         request.swIfIndex = IF_INDEX;
102         request.vrfId = vrfId;
103         return request;
104     }
105 }