use of org.apache.tapestry5.util.EnumSelectModel in project tapestry-5 by apache.
the class EnumSelectModelTest method generated_labels.
@Test
public void generated_labels() {
Messages messages = mockMessages();
stub_contains(messages, false);
replay();
SelectModel model = new EnumSelectModel(Stooge.class, messages);
List<OptionModel> options = model.getOptions();
assertEquals(options.size(), 3);
checkOption(options, 0, "Moe", Stooge.MOE);
checkOption(options, 1, "Larry", Stooge.LARRY);
checkOption(options, 2, "Curly Joe", Stooge.CURLY_JOE);
verify();
}
use of org.apache.tapestry5.util.EnumSelectModel 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();
}
use of org.apache.tapestry5.util.EnumSelectModel in project tapestry-5 by apache.
the class EnumSelectModelTest method prefixed_name_in_message_catalog.
@Test
public void prefixed_name_in_message_catalog() {
Messages messages = mockMessages();
stub_contains(messages, false);
train_contains(messages, "Stooge.LARRY", true);
train_get(messages, "Stooge.LARRY", "Mr. Larry Fine");
replay();
SelectModel model = new EnumSelectModel(Stooge.class, messages);
List<OptionModel> options = model.getOptions();
assertEquals(options.size(), 3);
checkOption(options, 0, "Moe", Stooge.MOE);
checkOption(options, 1, "Mr. Larry Fine", Stooge.LARRY);
checkOption(options, 2, "Curly Joe", Stooge.CURLY_JOE);
verify();
}
use of org.apache.tapestry5.util.EnumSelectModel in project tapestry-5 by apache.
the class EnumSelectModelTest method error_on_invalid_class.
@Test
public // TAP5-2495
void error_on_invalid_class() {
Messages messages = mockMessages();
replay();
Class c = String.class;
try {
SelectModel model = new EnumSelectModel(c, messages);
fail("should have thrown an exception");
} catch (IllegalArgumentException e) {
assertMessageContains(e, "not an enum class");
}
verify();
}
use of org.apache.tapestry5.util.EnumSelectModel in project tapestry-5 by apache.
the class EnumSelectModelTest method unprefixed_name_in_message_catalog.
@Test
public void unprefixed_name_in_message_catalog() {
Messages messages = mockMessages();
stub_contains(messages, false);
train_contains(messages, "MOE", true);
train_get(messages, "MOE", "Sir Moe Howard");
replay();
SelectModel model = new EnumSelectModel(Stooge.class, messages);
List<OptionModel> options = model.getOptions();
assertEquals(options.size(), 3);
checkOption(options, 0, "Sir Moe Howard", Stooge.MOE);
checkOption(options, 1, "Larry", Stooge.LARRY);
checkOption(options, 2, "Curly Joe", Stooge.CURLY_JOE);
verify();
}
Aggregations