Search in sources :

Example 6 with IValidationResult

use of org.jowidgets.validation.IValidationResult 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 7 with IValidationResult

use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.

the class BeanProxyImplTest method testValidateInvalidPersonAfterValidatorsAdded.

@Test
public void testValidateInvalidPersonAfterValidatorsAdded() {
    final IBeanProxy<IPerson> invalidPersonProxy = createPersonProxy(invalidPersonDto);
    IValidationResult validationResult = invalidPersonProxy.validate();
    Assert.assertTrue(validationResult.isOk());
    // after adding validators, bean must have validation error
    invalidPersonProxy.addBeanPropertyValidators(personValidators);
    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 8 with IValidationResult

use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.

the class BeanProxyImplTest method testValidBeanProxyCreation.

@Test
public void testValidBeanProxyCreation() {
    final IBeanProxy<IPerson> personProxy = createPersonProxy(personDto, personValidators);
    final IPerson person = personProxy.getBean();
    Assert.assertEquals(PERSON_NAME, person.getName());
    Assert.assertEquals(PERSON_LAST_NAME, person.getLastname());
    Assert.assertEquals(PERSON_GENDER, person.getGender());
    Assert.assertFalse(personProxy.isModified(IPerson.NAME_PROPERTY));
    Assert.assertFalse(personProxy.isModified(IPerson.LAST_NAME_PROPERTY));
    Assert.assertFalse(personProxy.isModified(IPerson.GENDER_PROPERTY));
    final IValidationResult validationResult = personProxy.validate();
    Assert.assertTrue(validationResult.isOk());
}
Also used : IPerson(org.jowidgets.cap.ui.impl.beans.IPerson) IValidationResult(org.jowidgets.validation.IValidationResult) Test(org.junit.Test)

Example 9 with IValidationResult

use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.

the class BeanProxyImpl method createValidationResult.

@Override
public IValidationResult createValidationResult() {
    checkDisposed();
    final IValidationResultBuilder builder = ValidationResult.builder();
    final IValidationResult independentResult = independentWorstResult.get();
    if (independentResult != null && !independentResult.isValid()) {
        return independentResult;
    }
    for (final IValidationResult validationResult : validationResults.values()) {
        if (!validationResult.isValid()) {
            return validationResult;
        } else {
            builder.addResult(validationResult);
        }
    }
    return builder.build();
}
Also used : IValidationResultBuilder(org.jowidgets.validation.IValidationResultBuilder) IValidationResult(org.jowidgets.validation.IValidationResult)

Example 10 with IValidationResult

use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.

the class DataModelSaveCommand method getVetoEnabledState.

@Override
IEnabledState getVetoEnabledState(final IDataModel model) {
    if (model.hasExecutions()) {
        return AbstractDataModelCommand.IN_PROCESS_STATE.get();
    }
    final IValidationResult validationResult = model.validate();
    if (!validationResult.isValid()) {
        final IValidationMessage worstFirst = validationResult.getWorstFirst();
        final String context = worstFirst.getContext();
        final String text = worstFirst.getText();
        if (EmptyCheck.isEmpty(context)) {
            return EnabledState.disabled(text);
        } else {
            return EnabledState.disabled(context + ": " + text);
        }
    }
    return EnabledState.ENABLED;
}
Also used : IValidationMessage(org.jowidgets.validation.IValidationMessage) IValidationResult(org.jowidgets.validation.IValidationResult)

Aggregations

IValidationResult (org.jowidgets.validation.IValidationResult)13 IValidationMessage (org.jowidgets.validation.IValidationMessage)5 IPerson (org.jowidgets.cap.ui.impl.beans.IPerson)4 IValidationResultBuilder (org.jowidgets.validation.IValidationResultBuilder)3 Test (org.junit.Test)3 IInputComponentValidationLabelBluePrint (org.jowidgets.api.widgets.blueprint.IInputComponentValidationLabelBluePrint)2 IBeanValidationResult (org.jowidgets.cap.common.api.validation.IBeanValidationResult)2 LinkedList (java.util.LinkedList)1 IValidationResultLabel (org.jowidgets.api.widgets.IValidationResultLabel)1 IDecorator (org.jowidgets.util.IDecorator)1