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 com.google.common.truth.Truth.assertThat;
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.Rule;
20 import org.junit.Test;
21 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
22 import org.opendaylight.aaa.web.WebServer;
23 import org.opendaylight.aaa.web.testutils.TestWebClient;
24 import org.opendaylight.aaa.web.testutils.WebTestModule;
25 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
26 import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
27 import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule;
28 import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
29 import org.opendaylight.infrautils.testutils.LogRule;
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.websockets.WebSocketConfiguration;
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.SchemaContextProvider;
41 * Tests if the {@link Rfc8040RestConfWiring} works.
43 * @author Michael Vorburger.ch
45 public class Rfc8040RestConfWiringTest {
47 public static class TestModule extends AbstractModule {
49 private static final WebSocketConfiguration SAMPLE_WEB_SOCKET_CONFIGURATION
50 = new WebSocketConfiguration(8192, 30000, 5000);
53 protected void configure() {
54 bind(Rfc8040RestConfWiring.class).asEagerSingleton();
55 bind(RestconfApplication.class).asEagerSingleton();
56 bind(JSONRestconfServiceRfc8040Impl.class).asEagerSingleton();
57 bind(WebInitializer.class).asEagerSingleton();
58 bind(CustomFilterAdapterConfiguration.class).toInstance(listener -> { });
59 bind(WebSocketConfiguration.class).toInstance(SAMPLE_WEB_SOCKET_CONFIGURATION);
63 @Singleton ServicesWrapper getServicesWrapper(final Rfc8040RestConfWiring wiring) {
64 return wiring.getServicesWrapper();
68 @Singleton ScheduledThreadPool getScheduledThreadPool() {
69 return new ScheduledThreadPoolWrapper(8, new ThreadFactoryBuilder().build());
73 public @Rule LogRule logRule = new LogRule();
75 public @Rule GuiceRule guice = new GuiceRule(TestModule.class,
76 InMemoryMdsalModule.class, WebTestModule.class, AnnotationsModule.class);
78 @Inject WebServer webServer;
79 @Inject TestWebClient webClient;
81 @Inject SchemaContextProvider schemaContextProvider;
82 @Inject SchemaContextHandler schemaContextHandler;
85 public void testWiring() throws IOException, InterruptedException, URISyntaxException {
86 schemaContextHandler.onGlobalContextUpdated(schemaContextProvider.getSchemaContext());
87 assertThat(webClient.request("GET", "/rests/yang-library-version").statusCode()).isEqualTo(200);