2 * Copyright (c) 2016 Intel and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.vppnsh.impl;
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.Mockito.mock;
25 import static org.mockito.MockitoAnnotations.initMocks;
27 import com.google.inject.Guice;
28 import com.google.inject.Inject;
29 import com.google.inject.Provider;
30 import com.google.inject.name.Named;
31 import com.google.inject.testing.fieldbinder.Bind;
32 import com.google.inject.testing.fieldbinder.BoundFieldModule;
33 import io.fd.honeycomb.translate.read.ReaderFactory;
34 import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder;
35 import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder;
36 import io.fd.honeycomb.translate.vpp.util.NamingContext;
37 import io.fd.honeycomb.translate.write.WriterFactory;
38 import io.fd.vpp.jvpp.JVppRegistry;
39 import io.fd.vpp.jvpp.nsh.future.FutureJVppNshFacade;
40 import java.util.HashSet;
42 import org.junit.Before;
43 import org.junit.Test;
44 import org.mockito.Mock;
45 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
47 public class VppNshModuleTest {
49 @Named("honeycomb-context")
52 private DataBroker honeycombContext;
54 @Named("honeycomb-initializer")
57 private DataBroker honeycombInitializer;
59 @Named("interface-context")
61 private NamingContext interfaceContext;
65 private JVppRegistry registry;
68 private Set<ReaderFactory> readerFactories = new HashSet<>();
71 private Set<WriterFactory> writerFactories = new HashSet<>();
74 public void setUp() throws Exception {
78 interfaceContext = new NamingContext("interface-", "interface-context");
80 Guice.createInjector(new VppNshModule(MockJVppNshProvider.class), BoundFieldModule.of(this)).injectMembers(this);
84 public void testReaderFactories() throws Exception {
85 assertThat(readerFactories, is(not(empty())));
87 // Test registration process (all dependencies present, topological order of readers does exist, etc.)
88 final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder();
89 readerFactories.forEach(factory -> factory.init(registryBuilder));
90 assertNotNull(registryBuilder.build());
94 public void testWriterFactories() throws Exception {
95 assertThat(writerFactories, is(not(empty())));
97 // Test registration process (all dependencies present, topological order of writers does exist, etc.)
98 final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder();
99 writerFactories.forEach(factory -> factory.init(registryBuilder));
100 assertNotNull(registryBuilder.build());
103 private static final class MockJVppNshProvider implements Provider<FutureJVppNshFacade> {
106 public FutureJVppNshFacade get() {
107 return mock(FutureJVppNshFacade.class);