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());
}
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());
}
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());
}
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();
}
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;
}
Aggregations