use of org.apache.tapestry5.internal.services.ContextValueEncoderImpl in project tapestry-5 by apache.
the class SelectTest method context_that_needs_to_be_encoded.
@Test
public void context_that_needs_to_be_encoded() throws Exception {
ValueEncoderSource valueEncoderSource = mockValueEncoderSource();
TypeCoercer typeCoercer = getService(TypeCoercer.class);
ContextValueEncoder contextValueEncoder = new ContextValueEncoderImpl(valueEncoderSource);
ValueEncoder<Platform> platformEncoder = new ValueEncoder<SelectTest.Platform>() {
@Override
public Platform toValue(String clientValue) {
return Platform.valueOf(clientValue.substring(10));
}
@Override
public String toClient(Platform value) {
return "Platform: " + value.name();
}
};
InternalComponentResources resources = mockInternalComponentResources();
expect(valueEncoderSource.getValueEncoder(Platform.class)).andReturn(platformEncoder).anyTimes();
expect(valueEncoderSource.getValueEncoder(String.class)).andReturn(new StringValueEncoder()).anyTimes();
expect(resources.triggerContextEvent(EasyMock.eq(EventConstants.VALUE_CHANGED), eqEventContext(null, Platform.LINUX), EasyMock.isA(ComponentEventCallback.class))).andReturn(true);
Select select = new Select();
set(select, "resources", resources);
set(select, "encoder", new StringValueEncoder());
set(select, "typeCoercer", typeCoercer);
replay();
select.onChange(new URLEventContext(contextValueEncoder, new String[] { platformEncoder.toClient(Platform.LINUX) }), null);
verify();
}
use of org.apache.tapestry5.internal.services.ContextValueEncoderImpl in project tapestry-5 by apache.
the class ContextValueEncoderImplTest method to_value.
@Test
public void to_value() {
ValueEncoder valueEncoder = mockValueEncoder();
ValueEncoderSource source = mockValueEncoderSource();
Long value = 23L;
String clientValue = "twentythree";
train_getValueEncoder(source, Long.class, valueEncoder);
train_toValue(valueEncoder, clientValue, value);
replay();
ContextValueEncoder cve = new ContextValueEncoderImpl(source);
assertSame(cve.toValue(Long.class, clientValue), value);
verify();
}
use of org.apache.tapestry5.internal.services.ContextValueEncoderImpl in project tapestry-5 by apache.
the class ContextValueEncoderImplTest method to_client.
@Test
public void to_client() {
ValueEncoder valueEncoder = mockValueEncoder();
ValueEncoderSource source = mockValueEncoderSource();
Long value = 23L;
String encoded = "twentythree";
train_getValueEncoder(source, Long.class, valueEncoder);
train_toClient(valueEncoder, value, encoded);
replay();
ContextValueEncoder cve = new ContextValueEncoderImpl(source);
assertSame(cve.toClient(value), encoded);
verify();
}
Aggregations