2 * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.test;
10 import static org.junit.Assert.assertEquals;
12 import com.google.common.util.concurrent.ThreadFactoryBuilder;
13 import com.google.inject.AbstractModule;
14 import com.google.inject.Provides;
15 import java.io.IOException;
16 import java.net.URISyntaxException;
17 import javax.inject.Inject;
18 import javax.inject.Singleton;
19 import org.junit.Ignore;
20 import org.junit.Rule;
21 import org.junit.Test;
22 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
23 import org.opendaylight.aaa.web.WebServer;
24 import org.opendaylight.aaa.web.testutils.TestWebClient;
25 import org.opendaylight.aaa.web.testutils.WebTestModule;
26 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
27 import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
28 import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule;
29 import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
30 import org.opendaylight.restconf.nb.rfc8040.RestconfApplication;
31 import org.opendaylight.restconf.nb.rfc8040.Rfc8040RestConfWiring;
32 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
33 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl;
34 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
35 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
36 import org.opendaylight.restconf.nb.rfc8040.test.incubate.InMemoryMdsalModule;
37 import org.opendaylight.restconf.nb.rfc8040.web.WebInitializer;
38 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
41 * Tests if the {@link Rfc8040RestConfWiring} works.
43 * @author Michael Vorburger.ch
46 public class Rfc8040RestConfWiringTest {
48 public static class TestModule extends AbstractModule {
50 private static final Configuration SAMPLE_SSE_CONFIGURATION
51 = new Configuration(8192, 5000, 30000, true);
54 protected void configure() {
55 bind(Rfc8040RestConfWiring.class).asEagerSingleton();
56 bind(RestconfApplication.class).asEagerSingleton();
57 bind(JSONRestconfServiceRfc8040Impl.class).asEagerSingleton();
58 bind(WebInitializer.class).asEagerSingleton();
59 bind(CustomFilterAdapterConfiguration.class).toInstance(listener -> { });
60 bind(Configuration.class).toInstance(SAMPLE_SSE_CONFIGURATION);
64 @Singleton ServicesWrapper getServicesWrapper(final Rfc8040RestConfWiring wiring) {
65 return wiring.getServicesWrapper();
69 @Singleton ScheduledThreadPool getScheduledThreadPool() {
70 return new ScheduledThreadPoolWrapper(8, new ThreadFactoryBuilder().build());
74 public @Rule GuiceRule guice = new GuiceRule(TestModule.class,
75 InMemoryMdsalModule.class, WebTestModule.class, AnnotationsModule.class);
77 @Inject WebServer webServer;
78 @Inject TestWebClient webClient;
80 @Inject EffectiveModelContextProvider schemaContextProvider;
81 @Inject SchemaContextHandler schemaContextHandler;
84 public void testWiring() throws IOException, InterruptedException, URISyntaxException {
85 schemaContextHandler.onModelContextUpdated(schemaContextProvider.getEffectiveModelContext());
86 assertEquals(200, webClient.request("GET", "/rests/yang-library-version").statusCode());