use of org.apache.tapestry5.internal.util.Holder in project tapestry-5 by apache.
the class ClientPersistentFieldStorageImplTest method store_and_restore_a_change.
@SuppressWarnings("unchecked")
@Test
public void store_and_restore_a_change() {
Request request = mockRequest(null);
Link link = mockLink();
String pageName = "Foo";
String componentId = "bar.baz";
String fieldName = "biff";
Object value = 99;
final Holder<String> holder = captureLinkModification(link);
replay();
ClientPersistentFieldStorage storage1 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
storage1.postChange(pageName, componentId, fieldName, value);
List<PersistentFieldChange> changes1 = newList(storage1.gatherFieldChanges(pageName));
storage1.updateLink(link);
verify();
assertEquals(changes1.size(), 1);
PersistentFieldChange change1 = changes1.get(0);
assertEquals(change1.getComponentId(), componentId);
assertEquals(change1.getFieldName(), fieldName);
assertEquals(change1.getValue(), value);
// Now more training ...
train_getParameter(request, ClientPersistentFieldStorageImpl.PARAMETER_NAME, holder.get());
replay();
ClientPersistentFieldStorage storage2 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
List<PersistentFieldChange> changes2 = newList(storage2.gatherFieldChanges(pageName));
verify();
assertEquals(changes2.size(), 1);
PersistentFieldChange change2 = changes2.get(0);
assertEquals(change2.getComponentId(), componentId);
assertEquals(change2.getFieldName(), fieldName);
assertEquals(change2.getValue(), value);
assertNotSame(change1, change2);
}
use of org.apache.tapestry5.internal.util.Holder in project tapestry-5 by apache.
the class SelectTest method submitted_option_matches_against_value_encoded_option_model_value.
/**
* This a test for TAP5-2184
*/
@Test
public void submitted_option_matches_against_value_encoded_option_model_value() throws ValidationException {
ValueEncoder<Integer> encoder = getService(ValueEncoderSource.class).getValueEncoder(Integer.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("5");
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, "5");
fvs.validate(5, resources, null);
replay();
// TAP5-2184 is triggered by the automatic String->SelectModel coercion, because the OptionModel
// values are Strings even if the desired property type is not (Integer, here). Select has a little
// hack to run the model values through the ValueEncoder for comparison.
modelHolder.put(getService(TypeCoercer.class).coerce("1,5,10,20", SelectModel.class));
set(select, "encoder", encoder);
set(select, "model", modelHolder.get());
set(select, "request", request);
set(select, "secure", SecureOption.ALWAYS);
// 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");
verify();
assertEquals(get(select, "value"), 5);
}
use of org.apache.tapestry5.internal.util.Holder in project tapestry-5 by apache.
the class PropertyConduitSourceImplTest method not_operator.
@Test
public void not_operator() {
PropertyConduit conduit = source.create(IntegerHolder.class, "! value");
IntegerHolder holder = new IntegerHolder();
assertEquals(conduit.get(holder), Boolean.TRUE);
holder.setValue(99);
assertEquals(conduit.get(holder), Boolean.FALSE);
}
use of org.apache.tapestry5.internal.util.Holder in project tapestry-5 by apache.
the class PropertyConduitSourceImplTest method navigate_through_public_field.
@Test
public void navigate_through_public_field() {
PublicFieldBean bean = new PublicFieldBean();
PublicFieldBeanHolder holder = new PublicFieldBeanHolder(bean);
bean.stringField = "x";
PropertyConduit pc = source.create(PublicFieldBeanHolder.class, "bean.stringField");
assertEquals(pc.get(holder), "x");
pc.set(holder, "y");
assertEquals(bean.stringField, "y");
}
use of org.apache.tapestry5.internal.util.Holder in project tapestry-5 by apache.
the class PropertyConduitSourceImplTest method generic_parameterized_base_with_properties.
@Test
public void generic_parameterized_base_with_properties() {
final String first = "John";
final String last = "Doe";
final SimpleBean simple = new SimpleBean();
simple.setAge(2);
simple.setFirstName(first);
simple.setLastName(last);
final RealizedParameters bean = new RealizedParameters();
final Holder<SimpleBean> holder = new Holder<SimpleBean>();
holder.put(simple);
bean.setType1Property(holder);
bean.setType2Property(1234L);
bean.type1Field = holder;
bean.type2Field = 5678L;
bean.type2ArrayField = new Long[] { 123L, 456L };
PropertyConduit conduit = source.create(RealizedParameters.class, "type1property.get().firstName");
assertSame(conduit.get(bean), first);
conduit.set(bean, "Change");
assertSame(conduit.get(bean), "Change");
conduit.set(bean, first);
conduit = source.create(RealizedParameters.class, "type1field.get().firstName");
assertSame(conduit.get(bean), first);
conduit = source.create(RealizedParameters.class, "type2field");
assertEquals(conduit.get(bean), bean.type2Field);
conduit = source.create(RealizedParameters.class, "type2property");
assertEquals(conduit.get(bean), bean.getType2Property());
conduit = source.create(RealizedParameters.class, "type2ArrayField");
assertEquals(conduit.get(bean), bean.type2ArrayField);
}
Aggregations