Search in sources :

Example 1 with IPerson

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());
}
Also used : IPerson(org.jowidgets.cap.ui.impl.beans.IPerson) IValidationMessage(org.jowidgets.validation.IValidationMessage) IValidationResult(org.jowidgets.validation.IValidationResult)

Example 2 with IPerson

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());
}
Also used : IPerson(org.jowidgets.cap.ui.impl.beans.IPerson) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with IPerson

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());
}
Also used : IPerson(org.jowidgets.cap.ui.impl.beans.IPerson) IValidationMessage(org.jowidgets.validation.IValidationMessage) IValidationResult(org.jowidgets.validation.IValidationResult) Test(org.junit.Test)

Example 4 with IPerson

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());
}
Also used : IPerson(org.jowidgets.cap.ui.impl.beans.IPerson) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with IPerson

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;
}
Also used : IPerson(org.jowidgets.cap.ui.impl.beans.IPerson) IFrame(org.jowidgets.api.widgets.IFrame)

Aggregations

IPerson (org.jowidgets.cap.ui.impl.beans.IPerson)7 Test (org.junit.Test)5 IValidationResult (org.jowidgets.validation.IValidationResult)4 IValidationMessage (org.jowidgets.validation.IValidationMessage)3 HashMap (java.util.HashMap)2 IFrame (org.jowidgets.api.widgets.IFrame)1