use of org.apache.tapestry5.corelib.components.SelectTest.Platform 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.corelib.components.SelectTest.Platform in project tapestry-5 by apache.
the class TemplateParserImplTest method just_HTML.
@Test
public void just_HTML() {
Resource resource = getResource("justHTML.tml");
ComponentTemplate template = getParser().parseTemplate(resource);
assertSame(template.getResource(), resource);
assertFalse(template.usesStrictMixinParameters());
List<TemplateToken> tokens = template.getTokens();
// They add up quick ...
assertEquals(tokens.size(), 20);
StartElementToken t0 = get(tokens, 0);
// Spot check a few things ...
assertEquals(t0.name, "html");
assertEquals(t0.namespaceURI, "");
checkLine(t0, 1);
TextToken t1 = get(tokens, 1);
// Concerned this may not work cross platform.
assertEquals(t1.text, "\n ");
StartElementToken t2 = get(tokens, 2);
assertEquals(t2.name, "head");
checkLine(t2, 2);
TextToken t5 = get(tokens, 5);
assertEquals(t5.text, "title");
checkLine(t5, 3);
get(tokens, 6);
StartElementToken t12 = get(tokens, 12);
assertEquals(t12.name, "p");
AttributeToken t13 = get(tokens, 13);
assertEquals(t13.name, "class");
assertEquals(t13.value, "important");
assertEquals(t13.namespaceURI, "");
TextToken t14 = get(tokens, 14);
// Simplify the text, converting consecutive whitespace to just a single space.
assertEquals(t14.text.replaceAll("\\s+", " ").trim(), "Tapestry rocks! Line 2");
// Line number is the *start* line of the whole text block.
checkLine(t14, 6);
}
use of org.apache.tapestry5.corelib.components.SelectTest.Platform in project tapestry-5 by apache.
the class ModuleTargetAttribute method write.
@Override
protected ByteVector write(final ClassWriter classWriter, final byte[] code, final int codeLength, final int maxStack, final int maxLocals) {
ByteVector byteVector = new ByteVector();
byteVector.putShort(platform == null ? 0 : classWriter.newUTF8(platform));
return byteVector;
}
use of org.apache.tapestry5.corelib.components.SelectTest.Platform in project tapestry-5 by apache.
the class SelectTest method checkSubmittedOption.
/**
* Utility for testing the "secure" option with various values and model
* states. This avoids a lot of redundant test setup code.
*
* @param withModel whether there should be a model to test against
* @param secureOption which "secure" option to test
* @param expectedError the expected error message, nor null if no error
* @throws ValidationException
*/
private void checkSubmittedOption(boolean withModel, SecureOption secureOption, String expectedError) throws ValidationException {
ValueEncoder<Platform> encoder = getService(ValueEncoderSource.class).getValueEncoder(Platform.class);
ValidationTracker tracker = mockValidationTracker();
Request request = mockRequest();
Messages messages = mockMessages();
FieldValidationSupport fvs = mockFieldValidationSupport();
TypeCoercer typeCoercer = mockTypeCoercer();
InternalComponentResources resources = mockInternalComponentResources();
Binding selectModelBinding = mockBinding();
expect(request.getParameter("xyz")).andReturn("MAC");
expect(messages.contains(EasyMock.anyObject(String.class))).andReturn(false).anyTimes();
expect(resources.getBinding("model")).andReturn(selectModelBinding);
final Holder<SelectModel> modelHolder = Holder.create();
expect(typeCoercer.coerce(EasyMock.or(EasyMock.isA(SelectModel.class), EasyMock.isNull()), EasyMock.eq(SelectModel.class))).andAnswer(new IAnswer<SelectModel>() {
@Override
public SelectModel answer() throws Throwable {
return modelHolder.get();
}
});
expect(selectModelBinding.get()).andAnswer(new IAnswer<SelectModel>() {
@Override
public SelectModel answer() throws Throwable {
return modelHolder.get();
}
});
Select select = new Select();
tracker.recordInput(select, "MAC");
// when not failing we will expect to call the fvs.validate method
if (expectedError == null) {
fvs.validate(Platform.MAC, resources, null);
} else {
tracker.recordError(EasyMock.eq(select), EasyMock.contains(expectedError));
}
replay();
if (withModel) {
modelHolder.put(new EnumSelectModel(Platform.class, messages));
}
set(select, "encoder", encoder);
set(select, "model", modelHolder.get());
set(select, "request", request);
set(select, "secure", secureOption);
// Disable BeanValidationContextSupport
set(select, "beanValidationDisabled", true);
set(select, "tracker", tracker);
set(select, "fieldValidationSupport", fvs);
set(select, "typeCoercer", typeCoercer);
set(select, "resources", resources);
select.processSubmission("xyz");
if (expectedError == null) {
assertEquals(get(select, "value"), Platform.MAC);
}
verify();
}
Aggregations