use of org.jowidgets.cap.ui.impl.beans.IPerson in project jo-client-platform by jo-source.
the class BeanProxyImplTest method testAllValidatorsForInitialValidPerson.
private void testAllValidatorsForInitialValidPerson(final IBeanProxy<IPerson> personProxy) {
IValidationResult validationResult = personProxy.validate();
Assert.assertTrue(validationResult.isOk());
// make name invalid
final IPerson person = personProxy.getBean();
person.setName(PersonNameValidator.FORBIDDEN_NAME);
validationResult = personProxy.validate();
IValidationMessage worstFirst = validationResult.getWorstFirst();
Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
Assert.assertEquals(MessageType.ERROR, worstFirst.getType());
// make name valid again
personProxy.undoModifications();
validationResult = personProxy.validate();
Assert.assertTrue(validationResult.isOk());
// make name invalid
person.setName(null);
validationResult = personProxy.validate();
worstFirst = validationResult.getWorstFirst();
Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
Assert.assertEquals(MessageType.INFO_ERROR, worstFirst.getType());
// make name valid again
personProxy.undoModifications();
validationResult = personProxy.validate();
Assert.assertTrue(validationResult.isOk());
// make lastname invalid
person.setLastname(null);
validationResult = personProxy.validate();
worstFirst = validationResult.getWorstFirst();
Assert.assertEquals(personAttributes.getAttribute(IPerson.LAST_NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
Assert.assertEquals(MessageType.INFO_ERROR, worstFirst.getType());
// make lastname valid again
personProxy.undoModifications();
validationResult = personProxy.validate();
Assert.assertTrue(validationResult.isOk());
// make name invalid again
person.setName(PersonNameValidator.FORBIDDEN_NAME);
validationResult = personProxy.validate();
worstFirst = validationResult.getWorstFirst();
Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
Assert.assertEquals(MessageType.ERROR, worstFirst.getType());
// modify lastname valid
person.setLastname("Foo");
// name must still be invalid
validationResult = personProxy.validate();
worstFirst = validationResult.getWorstFirst();
Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
Assert.assertEquals(MessageType.ERROR, worstFirst.getType());
}
use of org.jowidgets.cap.ui.impl.beans.IPerson in project jo-client-platform by jo-source.
the class BeanProxyImplTest method testCreateTransientPersonWithOverriddenDefaults.
@Test
public void testCreateTransientPersonWithOverriddenDefaults() {
final IBeanProxyFactoryBuilder<IPerson> factoryBuilder = BeanProxyFactory.builder(IPerson.class);
factoryBuilder.setBeanTypeId(IPerson.class);
factoryBuilder.setAttributes(personAttributes);
final Map<String, Object> originalDefaults = new HashMap<String, Object>();
originalDefaults.put(IPerson.NAME_PROPERTY, INVALID_PERSON_NAME);
originalDefaults.put(IPerson.LAST_NAME_PROPERTY, INVALID_PERSON_NAME);
final Map<String, Object> overridenDefaults = new HashMap<String, Object>();
overridenDefaults.put(IPerson.NAME_PROPERTY, PERSON_NAME);
factoryBuilder.setDefaultValuesForTransientBeans(originalDefaults);
final IPerson person = factoryBuilder.build().createTransientProxy(overridenDefaults).getBean();
Assert.assertEquals(PERSON_NAME, person.getName());
// all properties will be overridden and if not set, null is the new default
Assert.assertNull(person.getLastname());
}
use of org.jowidgets.cap.ui.impl.beans.IPerson in project jo-client-platform by jo-source.
the class BeanProxyImplTest method testInvalidBeanProxyCreation.
@Test
public void testInvalidBeanProxyCreation() {
final IBeanProxy<IPerson> invalidPersonProxy = createPersonProxy(invalidPersonDto, personValidators);
final IPerson invalidPerson = invalidPersonProxy.getBean();
Assert.assertEquals(INVALID_PERSON_NAME, invalidPerson.getName());
Assert.assertEquals(INVALID_PERSON_LAST_NAME, invalidPerson.getLastname());
Assert.assertEquals(INVALID_PERSON_GENDER, invalidPerson.getGender());
Assert.assertFalse(invalidPersonProxy.isModified(IPerson.NAME_PROPERTY));
Assert.assertFalse(invalidPersonProxy.isModified(IPerson.LAST_NAME_PROPERTY));
Assert.assertFalse(invalidPersonProxy.isModified(IPerson.GENDER_PROPERTY));
final IValidationResult validationResult = invalidPersonProxy.validate();
Assert.assertFalse(validationResult.isValid());
final IValidationMessage worstFirst = validationResult.getWorstFirst();
Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
Assert.assertEquals(MessageType.ERROR, worstFirst.getType());
}
use of org.jowidgets.cap.ui.impl.beans.IPerson in project jo-client-platform by jo-source.
the class BeanProxyImplTest method testCreateTransientPersonWithFactoryDefaults.
@Test
public void testCreateTransientPersonWithFactoryDefaults() {
final IBeanProxyFactoryBuilder<IPerson> factoryBuilder = BeanProxyFactory.builder(IPerson.class);
factoryBuilder.setBeanTypeId(IPerson.class);
factoryBuilder.setAttributes(personAttributes);
final Map<String, Object> defaultValues = new HashMap<String, Object>();
defaultValues.put(IPerson.NAME_PROPERTY, PERSON_NAME);
defaultValues.put(IPerson.LAST_NAME_PROPERTY, PERSON_LAST_NAME);
factoryBuilder.setDefaultValuesForTransientBeans(defaultValues);
final IPerson person = factoryBuilder.build().createTransientProxy().getBean();
Assert.assertEquals(PERSON_NAME, person.getName());
Assert.assertEquals(PERSON_LAST_NAME, person.getLastname());
}
use of org.jowidgets.cap.ui.impl.beans.IPerson in project jo-client-platform by jo-source.
the class BeanProxyImplTest method createPersonBeanForm.
private IBeanForm<IPerson> createPersonBeanForm(final ValueHolder<IInputControl<String>> nameControl, final ValueHolder<IInputControl<String>> lastNameControl, final ValueHolder<IValidationResultLabel> nameValidationlabel, final ValueHolder<IValidationResultLabel> lastnameValidationlabel) {
final IFrame rootFrame = Toolkit.createRootFrame(BPF.frame());
final IBeanFormBluePrint<IPerson> beanFormBp = CapUiToolkit.bluePrintFactory().beanForm(IPerson.class, personAttributes.getAttributes());
beanFormBp.setEditModeLayouter(createPersonBeanFormLayouter(nameControl, lastNameControl, nameValidationlabel, lastnameValidationlabel));
final IBeanForm<IPerson> result = rootFrame.add(beanFormBp);
rootFrame.setVisible(true);
return result;
}
Aggregations