use of se.jbee.inject.Env in project silk by jbee.
the class TestExampleAnnotatedActionsBinds method annotatedMethodIsBoundAsActionWithGlobalSelector.
@Test
void annotatedMethodIsBoundAsActionWithGlobalSelector() {
Env env = Bootstrap.DEFAULT_ENV.with(CONNECT_QUALIFIER, ProducesBy.class, OPTIMISTIC.annotatedWith(Marker.class));
annotatedMethodIsBoundAsAction(Bootstrap.injector(env, TestExampleAnnotatedActionsBindsModule2.class));
}
use of se.jbee.inject.Env in project silk by jbee.
the class TestExamplePubSubBinds method assertSubscribedToPublisher.
private static void assertSubscribedToPublisher(Class<? extends Bundle> bundle, int initiallyExpectedSubscribers) {
PublisherImpl pub = new PublisherImpl();
Env env = Bootstrap.DEFAULT_ENV.with(Publisher.class, pub).with(PublishesBy.class, PublishesBy.OPTIMISTIC);
Injector context = Bootstrap.injector(env, bundle);
// at this point the context is created by not necessarily any instances
// this is where the difference between eager and lazy shows
assertEquals(initiallyExpectedSubscribers, pub.subs.size());
assertSame(pub, context.resolve(PublisherImpl.class));
assertEquals(3, pub.subs.size(), "lazy did not cause subscription");
Service1 sub1 = context.resolve(Service1.class);
Service2 sub2 = context.resolve(Service2.class);
Service3 sub3 = context.resolve(Service3.class);
assertEquals(0, sub1.events);
assertEquals(0, sub2.events);
assertEquals(0, sub3.events);
pub.publish();
assertEquals(1, sub1.events);
assertEquals(1, sub2.events);
assertEquals(1, sub3.events);
}
use of se.jbee.inject.Env in project silk by jbee.
the class TestExampleEnvConfiguredHintsBinds method passingPropertiesConfigurationToConfigureHints.
@Test
void passingPropertiesConfigurationToConfigureHints() {
Properties props = new Properties();
props.put("x", "abc");
props.put("y", 12);
Env env = Bootstrap.DEFAULT_ENV.with(Properties.class, props);
Injector injector = Bootstrap.injector(env, Example1Module1.class);
MyClass obj = injector.resolve(MyClass.class);
assertEquals(12, obj.twelve);
assertEquals("abc", obj.abc);
}
use of se.jbee.inject.Env in project silk by jbee.
the class TestFeatureDiskScopeSync method schedulerCallsSyncInConfiguredInterval.
/**
* When disk is asked to store the entry at least 4 times this means
* that in general scheduling has picked up the annotated method as well
* as that the configuration change did have an effect on the interval.
*/
@Test
void schedulerCallsSyncInConfiguredInterval() {
List<DiskScope.DiskEntry> recorded = new CopyOnWriteArrayList<>();
Consumer<DiskScope.DiskEntry> recorder = recorded::add;
RecordingScheduledExecutor executor = new RecordingScheduledExecutor();
Env env = Bootstrap.DEFAULT_ENV.with(consumerTypeOf(DiskScope.DiskEntry.class), recorder).with(SchedulerModule.ScheduledExecutor.class, executor);
Injector context = Bootstrap.injector(env, TestFeatureDiskScopeSyncModule.class);
assertEquals("Hello", context.resolve(String.class));
// after we now have created the scheduled "bean" and by that the scheduler
// the executor should have gotten a job
assertEquals(1, executor.recorded.size());
// verify the details of that job
Job last = executor.lastRecorded();
assertNotNull(last);
assertNotNull(last.task);
assertEquals(20L, last.unit.toMillis(last.period));
assertEquals(0L, last.initialDelay);
// now we simulate the scheduler work
assertEquals(1, recorded.size(), "loading does not update to disk");
last.task.run();
assertEquals(2, recorded.size());
last.task.run();
assertEquals(3, recorded.size());
last.task.run();
assertEquals(4, recorded.size());
// make sure all recorded entries are indeed the same
assertAllSame(recorded);
}
use of se.jbee.inject.Env in project silk by jbee.
the class TestCustomAnnotationBinds method customAnnotationsAddedViaServiceLoader.
/**
* This verifies that the {@link Support} annotation's effect is loaded via
* {@link ServiceLoader}. It is defined in the com.example.app test
* dependency jar file. If the {@link MySupportService} can be resolved it
* was bound which meant the annotation had done its effect. Otherwise no
* binding would exist for the class.
*/
@Test
void customAnnotationsAddedViaServiceLoader() {
Env env = Example.EXAMPLE_1.env();
Injector injector = Bootstrap.injector(env, TestCustomAnnotationBindsModule.class);
MySupportService service = injector.resolve(MySupportService.class);
assertNotNull(service);
}
Aggregations