use of org.qi4j.api.service.ServiceReference in project qi4j-sdk by Qi4j.
the class ServicesInstance method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder("Services{");
String sep = " ";
for (ServiceReference serviceReference : serviceReferences) {
sb.append(sep).append(serviceReference.identity()).append("(active=").append(serviceReference.isActive()).append(")");
sep = ", ";
}
return sb.append(" }").toString();
}
use of org.qi4j.api.service.ServiceReference in project qi4j-sdk by Qi4j.
the class JDKMixinTest method testMixinExtendsJDK.
@Test
public void testMixinExtendsJDK() {
List<ServiceReference<JSONSerializableMap>> services = toList(filter(EXTENDS_IDENTITY_SPEC, module.findServices(JSONSerializableMap.class)));
assertThat(services.size(), equalTo(1));
assertThat(services.get(0).identity(), equalTo(EXTENDS_IDENTITY));
JSONSerializableMap extending = services.get(0).get();
// Concern trigger #1 (put)
extending.put("foo", "bar");
// Concern trigger #2, #3 and #4 (toJSON, size, entrySet)
JSONObject json = extending.toJSON();
assertThat(json.length(), equalTo(1));
assertThat(json.optString("foo"), equalTo("bar"));
assertThat(CONCERN_RECORDS.size(), equalTo(4));
}
use of org.qi4j.api.service.ServiceReference in project qi4j-sdk by Qi4j.
the class JDKMixinTest method testComposeJDKMixin.
@Test
public void testComposeJDKMixin() {
List<ServiceReference<JSONSerializableMap>> services = toList(filter(COMPOSE_IDENTITY_SPEC, module.findServices(JSONSerializableMap.class)));
assertThat(services.size(), equalTo(1));
assertThat(services.get(0).identity(), equalTo(COMPOSE_IDENTITY));
JSONSerializableMap composing = services.get(0).get();
// Concern trigger #1 (put)
composing.put("foo", "bar");
// Concern trigger #2, #3 and #4 (toJSON, size, entrySet)
JSONObject json = composing.toJSON();
assertThat(json.length(), equalTo(1));
assertThat(json.optString("foo"), equalTo("bar"));
assertThat(CONCERN_RECORDS.size(), equalTo(4));
}
use of org.qi4j.api.service.ServiceReference in project qi4j-sdk by Qi4j.
the class PassivationTest method givenSuccessPassivationWhenPassivatingExpectNoExceptions.
@Test
public void givenSuccessPassivationWhenPassivatingExpectNoExceptions() throws Throwable {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
}
};
Iterable<ServiceReference<DataAccess>> iterable = assembly.module().findServices(DataAccess.class);
for (ServiceReference<DataAccess> service : iterable) {
assertTrue("Service should not be Active before accessed", !service.isActive());
assertTrue(service.get().data().activated);
assertTrue("Service should be Active after access.", service.isActive());
}
assembly.application().passivate();
}
use of org.qi4j.api.service.ServiceReference in project qi4j-sdk by Qi4j.
the class TypeToCompositeLookupTest method servicesPluralDeclaration.
@Test
public void servicesPluralDeclaration() throws ActivationException, AssemblyException {
Module module = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.services(SomeOtherFoo.class, BasicFoo.class);
}
}.module();
assertEquals(1, Iterables.count(module.findServices(SomeOtherFoo.class)));
assertEquals(2, Iterables.count(module.findServices(BasicFoo.class)));
assertEquals(2, Iterables.count(module.findServices(Foo.class)));
assertEquals(CATHEDRAL, module.findService(SomeOtherFoo.class).get().bar());
// Exact type match first even if it is assembled _after_ an assignable, the assignable comes after
Iterator<ServiceReference<BasicFoo>> basicFoos = module.findServices(BasicFoo.class).iterator();
assertEquals(BAZAR, basicFoos.next().get().bar());
assertEquals(CATHEDRAL, basicFoos.next().get().bar());
assertFalse(basicFoos.hasNext());
// No exact type match, all assembled are assignable, follows assembly Type order
Iterator<ServiceReference<Foo>> foos = module.findServices(Foo.class).iterator();
assertEquals(CATHEDRAL, foos.next().get().bar());
assertEquals(BAZAR, foos.next().get().bar());
assertFalse(foos.hasNext());
}
Aggregations