HONEYCOMB-58 - Routing Api
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / V3poModuleTest.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;
18
19 import static org.hamcrest.CoreMatchers.is;
20 import static org.hamcrest.CoreMatchers.not;
21 import static org.hamcrest.Matchers.empty;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertThat;
24 import static org.mockito.MockitoAnnotations.initMocks;
25
26 import com.google.inject.Guice;
27 import com.google.inject.Inject;
28 import com.google.inject.name.Named;
29 import com.google.inject.testing.fieldbinder.Bind;
30 import com.google.inject.testing.fieldbinder.BoundFieldModule;
31 import io.fd.honeycomb.translate.MappingContext;
32 import io.fd.honeycomb.translate.read.ReaderFactory;
33 import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder;
34 import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder;
35 import io.fd.honeycomb.translate.write.WriterFactory;
36 import java.util.HashSet;
37 import java.util.Set;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.mockito.Mock;
41 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
42 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
43
44 public class V3poModuleTest {
45
46     @Named("honeycomb-context")
47     @Bind
48     @Mock
49     private MappingContext mappingContext;
50
51     @Named("honeycomb-initializer")
52     @Bind
53     @Mock
54     private DataBroker honeycombInitializer;
55
56     @Named("honeycomb-context")
57     @Bind
58     @Mock
59     private DataBroker honeycombContext;
60
61     @Bind
62     @Mock
63     private FutureJVppCore futureJVppCore;
64
65     @Inject
66     private Set<ReaderFactory> readerFactories = new HashSet<>();
67
68     @Inject
69     private Set<WriterFactory> writerFactories = new HashSet<>();
70
71     @Before
72     public void setUp() {
73         initMocks(this);
74         Guice.createInjector(new V3poModule(), BoundFieldModule.of(this)).injectMembers(this);
75     }
76
77     @Test
78     public void testReaderFactories() throws Exception {
79         assertThat(readerFactories, is(not(empty())));
80
81         // Test registration process (all dependencies present, topological order of readers does exist, etc.)
82         final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder();
83         readerFactories.stream().forEach(factory -> factory.init(registryBuilder));
84         assertNotNull(registryBuilder.build());
85     }
86
87     @Test
88     public void testWriterFactories() throws Exception {
89         assertThat(writerFactories, is(not(empty())));
90
91         // Test registration process (all dependencies present, topological order of writers does exist, etc.)
92         final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder();
93         writerFactories.stream().forEach(factory -> factory.init(registryBuilder));
94         assertNotNull(registryBuilder.build());
95     }
96 }