use of org.qi4j.logging.debug.records.ServiceDebugRecordEntity in project qi4j-sdk by Qi4j.
the class DebuggingTest method whenCallingMethodThenExpectDebugEntityCreated.
@Test
public void whenCallingMethodThenExpectDebugEntityCreated() {
UnitOfWork uow = module.newUnitOfWork();
try {
// There is no Query capability available for Libraries, since that sits in Extensions.
// Obtaining the EntityStore directly is a very ugly hack to get around this problem, and only related
// to the test sitting in qi4j-libraries source repository.
// QueryBuilder<DebugRecord> builder = module.newQueryBuilder( DebugRecord.class );
// Query<DebugRecord> query = builder.newQuery( uow );
// assertEquals( 0, query.count() );
Some service = (Some) module.findService(Some.class).get();
String message = service.doSomething("World!", 10);
assertEquals(message, "Hello!");
EntityStore es = (EntityStore) module.findService(EntityStore.class).get();
final String[] result = new String[1];
es.entityStates(module).transferTo(Transforms.map(new Function<EntityState, EntityState>() {
public EntityState map(EntityState entityState) {
if (ServiceDebugRecordEntity.class.getName().equals(first(entityState.entityDescriptor().types()).getName())) {
result[0] = entityState.identity().identity();
}
return entityState;
}
}, Outputs.<EntityState>noop()));
ServiceDebugRecordEntity debugEntry = uow.get(ServiceDebugRecordEntity.class, result[0]);
String mess = debugEntry.message().get();
System.out.println(mess);
assertEquals("some message.", mess);
uow.complete();
} catch (ConcurrentEntityModificationException e) {
e.printStackTrace();
uow.discard();
} catch (UnitOfWorkCompletionException e) {
e.printStackTrace();
uow.discard();
} finally {
if (uow.isOpen()) {
uow.discard();
}
}
}
use of org.qi4j.logging.debug.records.ServiceDebugRecordEntity in project qi4j-sdk by Qi4j.
the class DebuggingServiceMixin method createDebugRecord.
private void createDebugRecord(UnitOfWork uow, Composite composite, String message, List<Serializable> params) {
if (composite instanceof ServiceComposite) {
EntityBuilder<ServiceDebugRecordEntity> builder = uow.newEntityBuilder(ServiceDebugRecordEntity.class);
ServiceDebugRecordEntity state = builder.instance();
setStandardStuff(composite, message, state, params);
state.source().set(((ServiceComposite) composite).identity().get());
ServiceDebugRecordEntity slr = builder.newInstance();
} else if (composite instanceof EntityComposite) {
EntityBuilder<EntityDebugRecordEntity> builder = uow.newEntityBuilder(EntityDebugRecordEntity.class);
EntityDebugRecordEntity state = builder.instance();
setStandardStuff(composite, message, state, params);
state.source().set((EntityComposite) composite);
EntityDebugRecordEntity elr = builder.newInstance();
} else {
EntityBuilder<CompositeDebugRecordEntity> builder = uow.newEntityBuilder(CompositeDebugRecordEntity.class);
CompositeDebugRecordEntity state = builder.instance();
setStandardStuff(composite, message, state, params);
state.source().set(composite);
CompositeDebugRecordEntity clr = builder.newInstance();
}
}
Aggregations