Search in sources :

Example 11 with SimpleLocation

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());
}
Also used : Locale(java.util.Locale) SimpleLocation(com.helger.commons.location.SimpleLocation) MockRuntimeException(com.helger.commons.exception.mock.MockRuntimeException) Test(org.junit.Test)

Example 12 with SimpleLocation

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());
}
Also used : Locale(java.util.Locale) SimpleLocation(com.helger.commons.location.SimpleLocation) Test(org.junit.Test)

Example 13 with SimpleLocation

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);
}
Also used : Builder(com.helger.commons.error.SingleError.Builder) IErrorLevel(com.helger.commons.error.level.IErrorLevel) ValidationEventLocator(javax.xml.bind.ValidationEventLocator) SimpleLocation(com.helger.commons.location.SimpleLocation)

Aggregations

SimpleLocation (com.helger.commons.location.SimpleLocation)13 Nonnull (javax.annotation.Nonnull)5 IError (com.helger.commons.error.IError)4 Test (org.junit.Test)4 SingleError (com.helger.commons.error.SingleError)3 IErrorLevel (com.helger.commons.error.level.IErrorLevel)3 ErrorList (com.helger.commons.error.list.ErrorList)3 ConstantHasErrorText (com.helger.commons.error.text.ConstantHasErrorText)3 IJsonObject (com.helger.json.IJsonObject)3 SVRLResourceError (com.helger.schematron.svrl.SVRLResourceError)3 ValueEnforcer (com.helger.commons.ValueEnforcer)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 ILocation (com.helger.commons.location.ILocation)2 Wrapper (com.helger.commons.wrapper.Wrapper)2 IValidationArtefact (com.helger.phive.api.artefact.IValidationArtefact)2 ValidationResult (com.helger.phive.api.result.ValidationResult)2 SVRLFailedAssert (com.helger.schematron.svrl.SVRLFailedAssert)2 SchematronOutputType (com.helger.schematron.svrl.jaxb.SchematronOutputType)2 Locale (java.util.Locale)2