aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/test/java/com/yahoo/jdisc/ContainerTestCase.java
blob: 2a4360be0d758802555e5724aefbd44fcc3a940e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc;

import com.google.inject.AbstractModule;
import com.yahoo.jdisc.service.BindingSetNotFoundException;
import com.yahoo.jdisc.test.TestDriver;
import org.junit.jupiter.api.Test;

import java.net.URI;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;


/**
 * @author Simon Thoresen Hult
 */
public class ContainerTestCase {

    @Test
    void requireThatNewRequestsReferenceSameSnapshot() throws Exception {
        TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
        driver.activateContainer(driver.newContainerBuilder());
        Request foo = new Request(driver, URI.create("http://foo"));
        Request bar = new Request(foo, URI.create("http://bar"));
        assertNotNull(foo.container());
        assertSame(foo.container(), bar.container());
        foo.release();
        bar.release();
        driver.close();
    }

    @Test
    void requireThatInjectionWorks() throws BindingSetNotFoundException {
        final Object foo = new Object();
        TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {

            @Override
            protected void configure() {
                bind(Object.class).toInstance(foo);
            }
        });
        driver.activateContainer(driver.newContainerBuilder());
        Request request = new Request(driver, URI.create("http://host/path"));
        assertSame(foo, request.container().getInstance(Object.class));
        request.release();
        driver.close();
    }
}