HONEYCOMB-116: refactor v3po tests to use CTU.mockMapping
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / vppstate / VersionCustomizerTest.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.vppstate;
18
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23
24 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
25 import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
26 import java.util.concurrent.CompletableFuture;
27 import org.junit.Test;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.openvpp.jvpp.core.dto.ShowVersion;
33 import org.openvpp.jvpp.core.dto.ShowVersionReply;
34
35 public class VersionCustomizerTest extends ReaderCustomizerTest<Version, VersionBuilder> {
36
37     public VersionCustomizerTest() {
38         super(Version.class);
39     }
40
41     @Override
42     protected ReaderCustomizer<Version, VersionBuilder> initCustomizer() {
43         return new VersionCustomizer(api);
44     }
45
46     @Test
47     public void testMerge() {
48         final VppStateBuilder builder = mock(VppStateBuilder.class);
49         final Version value = mock(Version.class);
50         getCustomizer().merge(builder, value);
51         verify(builder).setVersion(value);
52     }
53
54     @Test
55     public void testReadCurrentAttributes() throws Exception {
56         final CompletableFuture<ShowVersionReply> replyFuture = new CompletableFuture<>();
57         final ShowVersionReply reply = new ShowVersionReply();
58         reply.version = new byte[] {};
59         reply.program = new byte[] {};
60         reply.buildDate = new byte[] {};
61         reply.buildDirectory = new byte[] {};
62         replyFuture.complete(reply);
63
64         when(api.showVersion(any(ShowVersion.class))).thenReturn(replyFuture);
65         getCustomizer().readCurrentAttributes(InstanceIdentifier.create(Version.class), new VersionBuilder(), ctx);
66         verify(api).showVersion(any(ShowVersion.class));
67     }
68 }