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