use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class HibernateEntityValueEncoderTest method to_client_id_null.
@Test
public void to_client_id_null() {
Session session = mockSession();
Logger logger = mockLogger();
replay();
SampleEntity entity = new SampleEntity();
HibernateEntityValueEncoder<SampleEntity> encoder = new HibernateEntityValueEncoder<SampleEntity>(SampleEntity.class, "id", session, access, typeCoercer, logger);
assertNull(encoder.toClient(entity));
verify();
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class HibernateEntityValueEncoderTest method to_value_not_found.
@Test
public void to_value_not_found() {
Session session = mockSession();
Logger logger = mockLogger();
expect(session.get(SampleEntity.class, new Long(12345))).andReturn(null);
logger.error("Unable to convert client value '12345' into an entity instance.");
replay();
SampleEntity entity = new SampleEntity();
HibernateEntityValueEncoder<SampleEntity> encoder = new HibernateEntityValueEncoder<SampleEntity>(SampleEntity.class, "id", session, access, typeCoercer, logger);
assertNull(encoder.toValue("12345"));
verify();
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class HibernateEntityValueEncoderTest method to_value_bad_type_coercion.
@Test
public void to_value_bad_type_coercion() {
Session session = mockSession();
Logger logger = mockLogger();
replay();
HibernateEntityValueEncoder<SampleEntity> encoder = new HibernateEntityValueEncoder<SampleEntity>(SampleEntity.class, "id", session, access, typeCoercer, logger);
try {
encoder.toValue("xyz");
unreachable();
} catch (RuntimeException ex) {
assertMessageContains(ex, "Exception converting 'xyz' to instance of java.lang.Long (id type for entity org.apache.tapestry5.internal.hibernate.SampleEntity)");
}
assertNull(encoder.toValue(""));
verify();
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class JpaModule method provideValueEncoders.
@Contribute(ValueEncoderSource.class)
public static void provideValueEncoders(final MappedConfiguration<Class, ValueEncoderFactory> configuration, @Symbol(JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERS) final boolean provideEncoders, final EntityManagerSource entityManagerSource, final EntityManagerManager entityManagerManager, final TypeCoercer typeCoercer, final PropertyAccess propertyAccess, final LoggerSource loggerSource) {
if (!provideEncoders)
return;
for (final PersistenceUnitInfo info : entityManagerSource.getPersistenceUnitInfos()) {
final EntityManagerFactory emf = entityManagerSource.getEntityManagerFactory(info.getPersistenceUnitName());
final Metamodel metamodel = emf.getMetamodel();
for (final EntityType<?> entity : metamodel.getEntities()) {
final Class<?> javaType = entity.getJavaType();
final ValueEncoderFactory factory = new ValueEncoderFactory() {
@Override
public ValueEncoder create(final Class type) {
return new JpaValueEncoder(entity, entityManagerManager, info.getPersistenceUnitName(), propertyAccess, typeCoercer, loggerSource.getLogger(javaType));
}
};
configuration.add(javaType, factory);
}
}
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class ExpansionPageElementImplTest method variant_binding_is_not_cached.
@Test
public void variant_binding_is_not_cached() {
Binding binding = mockBinding();
TypeCoercer coercer = mockTypeCoercer();
MarkupWriter writer = mockMarkupWriter();
RenderQueue queue = mockRenderQueue();
Object value = new Object();
train_isInvariant(binding, false);
replay();
RenderCommand element = new ExpansionPageElement(binding, coercer);
verify();
train_get(binding, value);
train_coerce(coercer, value, String.class, "STRING-VALUE");
writer.write("STRING-VALUE");
replay();
element.render(writer, queue);
verify();
train_get(binding, value);
train_coerce(coercer, value, String.class, "STRING-VALUE2");
writer.write("STRING-VALUE2");
replay();
element.render(writer, queue);
verify();
}
Aggregations