2 * Copyright (c) 2016 Cisco 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.hc2vpp.routing;
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.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertThat;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.MockitoAnnotations.initMocks;
28 import com.google.inject.Guice;
29 import com.google.inject.Inject;
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.hc2vpp.common.translate.util.NamingContext;
34 import io.fd.hc2vpp.routing.read.RoutingStateReaderFactory;
35 import io.fd.hc2vpp.routing.write.RoutingWriterFactory;
36 import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
37 import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder;
38 import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder;
39 import io.fd.honeycomb.translate.read.ReaderFactory;
40 import io.fd.honeycomb.translate.write.WriterFactory;
41 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
42 import java.util.HashSet;
44 import org.junit.Before;
45 import org.junit.Test;
46 import org.mockito.Mock;
47 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
49 public class RoutingModuleTest {
51 @Named("honeycomb-context")
54 private DataBroker honeycombContext;
56 @Named("honeycomb-initializer")
59 private DataBroker honeycombInitializer;
61 @Named("interface-context")
63 private NamingContext interfaceContext;
65 @Named("classify-table-context")
68 private VppClassifierContextManager classifierContextManager;
72 private FutureJVppCore futureJVppCore;
75 private Set<ReaderFactory> readerFactories = new HashSet<>();
78 private Set<WriterFactory> writerFactories = new HashSet<>();
83 interfaceContext = new NamingContext("interfaceContext", "interfaceContext");
84 Guice.createInjector(new RoutingModule(), BoundFieldModule.of(this)).injectMembers(this);
88 public void testReaderFactories() throws Exception {
89 assertThat(readerFactories, is(not(empty())));
91 // Test registration process (all dependencies present, topological order of readers does exist, etc.)
92 final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder();
93 readerFactories.stream().forEach(factory -> factory.init(registryBuilder));
94 assertNotNull(registryBuilder.build());
95 assertEquals(1, readerFactories.size());
96 assertTrue(readerFactories.iterator().next() instanceof RoutingStateReaderFactory);
100 public void testWriterFactories() throws Exception {
101 assertThat(writerFactories, is(not(empty())));
103 // Test registration process (all dependencies present, topological order of writers does exist, etc.)
104 final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder();
105 writerFactories.stream().forEach(factory -> factory.init(registryBuilder));
106 assertNotNull(registryBuilder.build());
107 assertEquals(1, writerFactories.size());
108 assertTrue(writerFactories.iterator().next() instanceof RoutingWriterFactory);