blob: 205097384350820eb13e0ce816cf4e302ed08cad (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.client;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.yahoo.jdisc.application.BundleInstaller;
import com.yahoo.jdisc.application.ContainerActivator;
import com.yahoo.jdisc.application.OsgiFramework;
import org.junit.Test;
import org.osgi.framework.Bundle;
import java.util.List;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
public class ClientDriverIntegrationTest {
@Test
public void requireThatApplicationClassInjectionWorks() throws Exception {
MyModule module = new MyModule();
ClientDriver.runApplicationWithOsgi("target/bundlecache_client", MyApplication.class, module);
assertEquals(5, module.state);
}
private static class MyApplication implements ClientApplication {
final Logger log = Logger.getLogger(MyApplication.class.getName());
final ContainerActivator activator;
final BundleInstaller installer;
final MyModule module;
@Inject
MyApplication(ContainerActivator activator, OsgiFramework osgi, MyModule module) {
this.activator = activator;
this.installer = new BundleInstaller(osgi);
this.module = module;
module.state = 1;
}
@Override
public void start() {
if (++module.state != 2) {
throw new IllegalStateException();
}
}
@Override
public void run() {
if (++module.state != 3) {
throw new IllegalStateException();
}
try {
List<Bundle> bundles = installer.installAndStart("cert-a.jar");
Class<?> classObj = bundles.get(0).loadClass("com.yahoo.jdisc.bundle.a.CertificateA");
log.info("Loaded '" + classObj.getName() + "'.");
} catch (Exception e) {
throw new AssertionError(e);
}
}
@Override
public void stop() {
if (++module.state != 4) {
throw new IllegalStateException();
}
}
@Override
public void destroy() {
if (++module.state != 5) {
throw new IllegalStateException();
}
}
}
private static class MyModule extends AbstractModule {
int state = 0;
@Override
protected void configure() {
bind(MyModule.class).toInstance(this);
}
}
}
|