Search in sources :

Example 1 with ConstantHasErrorText

use of com.helger.commons.error.text.ConstantHasErrorText in project phive by phax.

the class PhiveJsonHelperTest method testSVRLError.

@Test
public void testSVRLError() {
    final IError aError = new SVRLResourceError(EErrorLevel.ERROR, "id2", "field1", new SimpleLocation("res12", 3, 4), new ConstantHasErrorText("bla failed"), null, " my test <>");
    // To Json
    final IJsonObject aJson = PhiveJsonHelper.getJsonError(aError, Locale.US);
    assertNotNull(aJson);
    // And back
    final IError aError2 = PhiveJsonHelper.getAsIError(aJson);
    assertNotNull(aError2);
    // And forth
    final IJsonObject aJson2 = PhiveJsonHelper.getJsonError(aError2, Locale.US);
    assertNotNull(aJson2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aJson, aJson2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aError, aError2);
}
Also used : IJsonObject(com.helger.json.IJsonObject) SVRLResourceError(com.helger.schematron.svrl.SVRLResourceError) SimpleLocation(com.helger.commons.location.SimpleLocation) IError(com.helger.commons.error.IError) ConstantHasErrorText(com.helger.commons.error.text.ConstantHasErrorText) Test(org.junit.Test)

Example 2 with ConstantHasErrorText

use of com.helger.commons.error.text.ConstantHasErrorText in project phive by phax.

the class PhiveJsonHelper method getAsIError.

@Nonnull
public static IError getAsIError(@Nonnull final IJsonObject aObj) {
    final IErrorLevel aErrorLevel = getAsErrorLevel(aObj.getAsString(JSON_ERROR_LEVEL));
    final String sErrorID = aObj.getAsString(JSON_ERROR_ID);
    final String sErrorFieldName = aObj.getAsString(JSON_ERROR_FIELD_NAME);
    // Try new structured version
    ILocation aErrorLocation = getAsErrorLocation(aObj.getAsObject(JSON_ERROR_LOCATION_OBJ));
    if (aErrorLocation == null) {
        final IJsonValue aErrorLocationValue = aObj.getAsValue(JSON_ERROR_LOCATION_STR);
        if (aErrorLocationValue != null) {
            // It's a string - old version
            aErrorLocation = new SimpleLocation(aErrorLocationValue.getAsString());
        }
    }
    final String sErrorText = aObj.getAsString(JSON_ERROR_TEXT);
    final String sTest = aObj.getAsString(JSON_TEST);
    final PhiveRestoredException aLinkedException = PhiveRestoredException.createFromJson(aObj.getAsObject(JSON_EXCEPTION));
    if (sTest != null)
        return new SVRLResourceError(aErrorLevel, sErrorID, sErrorFieldName, aErrorLocation, new ConstantHasErrorText(sErrorText), aLinkedException, sTest);
    return new SingleError(aErrorLevel, sErrorID, sErrorFieldName, aErrorLocation, new ConstantHasErrorText(sErrorText), aLinkedException);
}
Also used : IJsonValue(com.helger.json.IJsonValue) SingleError(com.helger.commons.error.SingleError) ILocation(com.helger.commons.location.ILocation) IErrorLevel(com.helger.commons.error.level.IErrorLevel) SimpleLocation(com.helger.commons.location.SimpleLocation) SVRLResourceError(com.helger.schematron.svrl.SVRLResourceError) ConstantHasErrorText(com.helger.commons.error.text.ConstantHasErrorText) Nonnull(javax.annotation.Nonnull)

Example 3 with ConstantHasErrorText

use of com.helger.commons.error.text.ConstantHasErrorText in project phive by phax.

the class PhiveJsonHelperTest method testSVRLErrorWithException.

@Test
public void testSVRLErrorWithException() {
    final IError aError = new SVRLResourceError(EErrorLevel.ERROR, "id2", "field1", new SimpleLocation("res12", 3, 4), new ConstantHasErrorText("bla failed"), new IllegalStateException("Sthg went wrong"), " my test <>");
    // To Json
    final IJsonObject aJson = PhiveJsonHelper.getJsonError(aError, Locale.US);
    assertNotNull(aJson);
    // And back
    final IError aError2 = PhiveJsonHelper.getAsIError(aJson);
    assertNotNull(aError2);
    // And forth
    final IJsonObject aJson2 = PhiveJsonHelper.getJsonError(aError2, Locale.US);
    assertNotNull(aJson2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aJson, aJson2);
    // The objects differ, because of the different exception types
    assertTrue(aError2.getLinkedException() instanceof PhiveRestoredException);
    if (false)
        CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aError, aError2);
}
Also used : IJsonObject(com.helger.json.IJsonObject) SVRLResourceError(com.helger.schematron.svrl.SVRLResourceError) SimpleLocation(com.helger.commons.location.SimpleLocation) IError(com.helger.commons.error.IError) ConstantHasErrorText(com.helger.commons.error.text.ConstantHasErrorText) Test(org.junit.Test)

Aggregations

ConstantHasErrorText (com.helger.commons.error.text.ConstantHasErrorText)3 SimpleLocation (com.helger.commons.location.SimpleLocation)3 SVRLResourceError (com.helger.schematron.svrl.SVRLResourceError)3 IError (com.helger.commons.error.IError)2 IJsonObject (com.helger.json.IJsonObject)2 Test (org.junit.Test)2 SingleError (com.helger.commons.error.SingleError)1 IErrorLevel (com.helger.commons.error.level.IErrorLevel)1 ILocation (com.helger.commons.location.ILocation)1 IJsonValue (com.helger.json.IJsonValue)1 Nonnull (javax.annotation.Nonnull)1