RESTCONF RFC8040 compliance: SSE support
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / test / Rfc8040RestConfWiringTest.java
1 /*
2  * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.nb.rfc8040.test;
9
10 import static org.junit.Assert.assertEquals;
11
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;
39
40 /**
41  * Tests if the {@link Rfc8040RestConfWiring} works.
42  *
43  * @author Michael Vorburger.ch
44  */
45 @Ignore
46 public class Rfc8040RestConfWiringTest {
47
48     public static class TestModule extends AbstractModule {
49
50         private static final Configuration SAMPLE_SSE_CONFIGURATION
51                 = new Configuration(8192, 5000, 30000, true);
52
53         @Override
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);
61         }
62
63         @Provides
64         @Singleton ServicesWrapper getServicesWrapper(final Rfc8040RestConfWiring wiring) {
65             return wiring.getServicesWrapper();
66         }
67
68         @Provides
69         @Singleton ScheduledThreadPool getScheduledThreadPool() {
70             return new ScheduledThreadPoolWrapper(8, new ThreadFactoryBuilder().build());
71         }
72     }
73
74     public @Rule GuiceRule guice = new GuiceRule(TestModule.class,
75             InMemoryMdsalModule.class, WebTestModule.class, AnnotationsModule.class);
76
77     @Inject WebServer webServer;
78     @Inject TestWebClient webClient;
79
80     @Inject EffectiveModelContextProvider schemaContextProvider;
81     @Inject SchemaContextHandler schemaContextHandler;
82
83     @Test
84     public void testWiring() throws IOException, InterruptedException, URISyntaxException {
85         schemaContextHandler.onModelContextUpdated(schemaContextProvider.getEffectiveModelContext());
86         assertEquals(200, webClient.request("GET", "/rests/yang-library-version").statusCode());
87     }
88 }