2011-11-17 23:15:19 +01:00
|
|
|
/**
|
2012-01-19 18:21:06 +01:00
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
2011-11-17 23:15:19 +01:00
|
|
|
*/
|
|
|
|
|
package akka.actor;
|
|
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.BeforeClass;
|
2011-11-17 23:15:19 +01:00
|
|
|
import org.junit.Test;
|
2011-11-21 15:58:01 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
import akka.testkit.AkkaSpec;
|
|
|
|
|
|
2011-11-21 15:58:01 +01:00
|
|
|
import com.typesafe.config.ConfigFactory;
|
|
|
|
|
import com.typesafe.config.Config;
|
|
|
|
|
|
2011-11-17 23:15:19 +01:00
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
public class JavaExtension {
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2012-01-20 11:30:33 +01:00
|
|
|
static class TestExtensionId extends AbstractExtensionId<TestExtension> implements ExtensionIdProvider {
|
2012-01-23 16:11:58 +01:00
|
|
|
public final static TestExtensionId TestExtensionProvider = new TestExtensionId();
|
2012-01-20 11:30:33 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
public ExtensionId<TestExtension> lookup() {
|
2012-01-23 16:11:58 +01:00
|
|
|
return TestExtensionId.TestExtensionProvider;
|
2011-11-30 15:16:20 +01:00
|
|
|
}
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2012-01-24 11:33:40 +01:00
|
|
|
public TestExtension createExtension(ExtendedActorSystem i) {
|
2011-11-25 10:45:22 +01:00
|
|
|
return new TestExtension(i);
|
2011-11-17 23:15:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-25 10:45:22 +01:00
|
|
|
static class TestExtension implements Extension {
|
2012-01-24 11:33:40 +01:00
|
|
|
public final ExtendedActorSystem system;
|
2011-11-29 11:50:22 +01:00
|
|
|
|
2012-01-24 11:33:40 +01:00
|
|
|
public TestExtension(ExtendedActorSystem i) {
|
2011-11-29 11:50:22 +01:00
|
|
|
system = i;
|
|
|
|
|
}
|
2011-11-25 10:45:22 +01:00
|
|
|
}
|
2012-01-20 11:30:33 +01:00
|
|
|
|
2011-11-29 23:00:57 +01:00
|
|
|
static class OtherExtension implements Extension {
|
2012-01-20 11:30:33 +01:00
|
|
|
static final ExtensionKey<OtherExtension> key = new ExtensionKey<OtherExtension>(OtherExtension.class) {
|
|
|
|
|
};
|
2011-11-29 23:00:57 +01:00
|
|
|
|
|
|
|
|
public final ActorSystemImpl system;
|
2012-01-20 11:30:33 +01:00
|
|
|
|
2011-11-29 23:00:57 +01:00
|
|
|
public OtherExtension(ActorSystemImpl i) {
|
|
|
|
|
system = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-25 10:45:22 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
private static ActorSystem system;
|
2011-11-17 23:15:19 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
@BeforeClass
|
|
|
|
|
public static void beforeAll() {
|
2012-01-20 11:30:33 +01:00
|
|
|
Config c = ConfigFactory.parseString("akka.extensions = [ \"akka.actor.JavaExtension$TestExtensionId\" ]")
|
|
|
|
|
.withFallback(AkkaSpec.testConf());
|
2011-11-30 15:16:20 +01:00
|
|
|
system = ActorSystem.create("JavaExtension", c);
|
|
|
|
|
}
|
2011-11-17 23:15:19 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
@AfterClass
|
|
|
|
|
public static void afterAll() {
|
2011-12-14 01:06:20 +01:00
|
|
|
system.shutdown();
|
2011-11-30 15:16:20 +01:00
|
|
|
system = null;
|
|
|
|
|
}
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-17 23:15:19 +01:00
|
|
|
@Test
|
|
|
|
|
public void mustBeAccessible() {
|
2012-01-23 16:11:58 +01:00
|
|
|
assertSame(system.extension(TestExtensionId.TestExtensionProvider).system, system);
|
|
|
|
|
assertSame(TestExtensionId.TestExtensionProvider.apply(system).system, system);
|
2011-11-17 23:15:19 +01:00
|
|
|
}
|
2012-01-20 11:30:33 +01:00
|
|
|
|
2011-11-29 23:00:57 +01:00
|
|
|
@Test
|
|
|
|
|
public void mustBeAdHoc() {
|
|
|
|
|
assertSame(OtherExtension.key.apply(system).system, system);
|
|
|
|
|
}
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-17 23:15:19 +01:00
|
|
|
}
|