use of com.helger.commons.location.SimpleLocation in project ph-commons by phax.
the class SingleErrorTest method testAll.
@Test
public void testAll() {
final Locale aDisplayLocale = Locale.US;
final MockRuntimeException ex = new MockRuntimeException("exception msg");
final SingleError aErr = SingleError.builder().errorID("id1").errorFieldName("field").errorLocation(new SimpleLocation("file.xml", 4, 13)).errorText("abc").linkedException(ex).build();
assertEquals(EErrorLevel.ERROR, aErr.getErrorLevel());
assertEquals("id1", aErr.getErrorID());
assertEquals("field", aErr.getErrorFieldName());
assertNotNull(aErr.getErrorLocation());
assertTrue(aErr.getErrorLocation().isAnyInformationPresent());
assertNotNull(aErr.getErrorTexts());
assertEquals("abc", aErr.getErrorText(aDisplayLocale));
assertSame(ex, aErr.getLinkedException());
assertNull(aErr.getLinkedExceptionCause());
assertEquals("exception msg", aErr.getLinkedExceptionMessage());
assertNotNull(aErr.getLinkedExceptionStackTrace());
assertEquals("[error] [id1] in field @ file.xml(4:13) abc (" + ex.getClass().getName() + ": exception msg)", aErr.getAsString(aDisplayLocale));
assertEquals(aErr, SingleError.builder(aErr).build());
}
use of com.helger.commons.location.SimpleLocation in project ph-commons by phax.
the class SingleErrorTest method testLocation.
@Test
public void testLocation() {
final Locale aDisplayLocale = Locale.US;
final SingleError aErr = SingleError.builder().errorLocation(new SimpleLocation("abc", 4, 17)).build();
assertEquals(EErrorLevel.ERROR, aErr.getErrorLevel());
assertNull(aErr.getErrorID());
assertNull(aErr.getErrorFieldName());
assertNotNull(aErr.getErrorLocation());
assertTrue(aErr.getErrorLocation().isAnyInformationPresent());
assertNull(aErr.getErrorTexts());
assertNull(aErr.getErrorText(aDisplayLocale));
assertNull(aErr.getLinkedException());
assertNull(aErr.getLinkedExceptionCause());
assertNull(aErr.getLinkedExceptionMessage());
assertNull(aErr.getLinkedExceptionStackTrace());
assertEquals("[error] @ abc(4:17)", aErr.getAsString(aDisplayLocale));
assertEquals(aErr, SingleError.builder(aErr).build());
}
use of com.helger.commons.location.SimpleLocation in project ph-commons by phax.
the class AbstractValidationEventHandler method handleEvent.
public final boolean handleEvent(@Nonnull final ValidationEvent aEvent) {
final IErrorLevel aErrorLevel = getErrorLevel(aEvent.getSeverity());
final Builder aErrBuilder = SingleError.builder().errorLevel(aErrorLevel);
final ValidationEventLocator aLocator = aEvent.getLocator();
aErrBuilder.errorLocation(new SimpleLocation(getLocationResourceID(aLocator), aLocator != null ? aLocator.getLineNumber() : ILocation.ILLEGAL_NUMBER, aLocator != null ? aLocator.getColumnNumber() : ILocation.ILLEGAL_NUMBER)).errorFieldName(getErrorFieldName(aLocator));
// Message may be null in some cases (e.g. when a linked exception is
// present), but is not allowed to be null!
String sMsg = aEvent.getMessage();
if (sMsg == null) {
if (aEvent.getLinkedException() != null) {
sMsg = aEvent.getLinkedException().getMessage();
if (sMsg == null)
sMsg = "Exception";
} else {
// Does this ever happen????
sMsg = "Validation event";
}
}
aErrBuilder.errorText(sMsg).linkedException(aEvent.getLinkedException());
// call our callback
onEvent(aErrBuilder.build());
// Continue processing?
return continueProcessing(aErrorLevel);
}
Aggregations