4648676bfeac03b1349facf84fb215cc35dd1be7
[honeycomb.git] / vpp-common / vpp-translate-test / src / main / java / io / fd / honeycomb / vpp / test / read / ReaderCustomizerTest.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.vpp.test.read;
18
19 import static org.junit.Assert.assertNotNull;
20
21 import io.fd.honeycomb.translate.MappingContext;
22 import io.fd.honeycomb.translate.ModificationCache;
23 import io.fd.honeycomb.translate.read.ReadContext;
24 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.mockito.MockitoAnnotations;
30 import org.opendaylight.yangtools.concepts.Builder;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.openvpp.jvpp.core.future.FutureJVppCore;
34
35 /**
36  * Generic test for classes implementing {@link ReaderCustomizer} interface.
37  *
38  * @param <D> Specific DataObject derived type (Identifiable), that is handled by this customizer
39  * @param <B> Specific Builder for handled type (D)
40  */
41 public abstract class ReaderCustomizerTest<D extends DataObject, B extends Builder<D>> {
42
43     @Mock
44     protected FutureJVppCore api;
45     @Mock
46     protected ReadContext ctx;
47     @Mock
48     protected MappingContext mappingContext;
49
50     protected ModificationCache cache;
51     protected final Class<D> dataObjectClass;
52     private ReaderCustomizer<D, B> customizer;
53
54     protected ReaderCustomizerTest(Class<D> dataObjectClass) {
55         this.dataObjectClass = dataObjectClass;
56     }
57
58     @Before
59     public void setUpParent() throws Exception {
60         MockitoAnnotations.initMocks(this);
61         cache = new ModificationCache();
62         Mockito.doReturn(cache).when(ctx).getModificationCache();
63         Mockito.doReturn(mappingContext).when(ctx).getMappingContext();
64         setUp();
65         customizer = initCustomizer();
66     }
67
68     /**
69      * Optional setup for subclasses. Invoked before customizer is initialized.
70      */
71     protected void setUp() throws Exception {
72     }
73
74     protected abstract ReaderCustomizer<D, B> initCustomizer();
75
76     protected ReaderCustomizer<D, B> getCustomizer() {
77         return customizer;
78     }
79
80     @Test
81     public void testGetBuilder() throws Exception {
82         assertNotNull(customizer.getBuilder(InstanceIdentifier.create(dataObjectClass)));
83     }
84
85     // TODO HONEYCOMB-116: create generic testMerge()
86 }