aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/test/java/com/yahoo/jdisc/core/ApplicationEnvironmentModuleTestCase.java
blob: 87a0d4d0e188b41acd86dd4f61300810524e95be (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
50
51
52
53
54
55
56
57
58
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;

import com.google.inject.Binding;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.yahoo.jdisc.application.ContainerActivator;
import com.yahoo.jdisc.application.ContainerBuilder;
import com.yahoo.jdisc.application.OsgiFramework;
import com.yahoo.jdisc.service.CurrentContainer;
import com.yahoo.jdisc.test.NonWorkingOsgiFramework;
import org.junit.jupiter.api.Test;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadFactory;

import static java.util.Collections.emptyList;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

    @Test
    void requireThatBindingsExist() {
        List<Class<?>> expected = new LinkedList<>();
        expected.add(ContainerActivator.class);
        expected.add(ContainerBuilder.class);
        expected.add(CurrentContainer.class);
        expected.add(OsgiFramework.class);
        expected.add(ThreadFactory.class);

        Injector injector = Guice.createInjector();
        for (Map.Entry<Key<?>, Binding<?>> entry : injector.getBindings().entrySet()) {
            expected.add(entry.getKey().getTypeLiteral().getRawType());
        }

        ApplicationLoader loader = new ApplicationLoader(new NonWorkingOsgiFramework(), emptyList());
        injector = Guice.createInjector(new ApplicationEnvironmentModule(loader));
        for (Map.Entry<Key<?>, Binding<?>> entry : injector.getBindings().entrySet()) {
            assertNotNull(expected.remove(entry.getKey().getTypeLiteral().getRawType()));
        }
        assertTrue(expected.isEmpty());
    }

    @Test
    void requireThatContainerBuilderCanBeInjected() {
        ApplicationLoader loader = new ApplicationLoader(new NonWorkingOsgiFramework(), emptyList());
        assertNotNull(new ApplicationEnvironmentModule(loader).containerBuilder());
        assertNotNull(Guice.createInjector(new ApplicationEnvironmentModule(loader))
                .getInstance(ContainerBuilder.class));
    }
}