HONEYCOMB-206: change package name to match groupId
[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 org.junit.Test;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Routing;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.RoutingBuilder;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.openvpp.jvpp.core.dto.SwInterfaceSetTable;
36 import org.openvpp.jvpp.core.dto.SwInterfaceSetTableReply;
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.CreateFailedException.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.UpdateFailedException.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         customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
84         verifyZeroInteractions(api);
85     }
86
87     private Routing routing(final long vrfId) {
88         return new RoutingBuilder().setVrfId(vrfId).build();
89     }
90
91     private SwInterfaceSetTable expectedRequest(final int vrfId) {
92         final SwInterfaceSetTable request = new SwInterfaceSetTable();
93         request.isIpv6 = 0;
94         request.swIfIndex = IF_INDEX;
95         request.vrfId = vrfId;
96         return request;
97     }
98 }