use of com.helger.json.IJsonObject in project phive by phax.
the class PhiveJsonHelperTest method testError.
@Test
public void testError() {
final IError aError = SingleError.builderError().errorID("id1").errorText("fla").errorLocation(new SimpleLocation("res12", 3, 4)).build();
final IJsonObject aJson = PhiveJsonHelper.getJsonError(aError, Locale.US);
assertNotNull(aJson);
final IError aError2 = PhiveJsonHelper.getAsIError(aJson);
assertNotNull(aError2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aError, aError2);
}
use of com.helger.json.IJsonObject in project phive by phax.
the class PhiveJsonHelperTest method testValidationResults.
@Test
public void testValidationResults() {
final IJsonObject aObj = new JsonObject();
final Locale aDisplayLocale = Locale.US;
final VESID aVESID = new VESID("group", "art", "1.0");
final IValidationExecutorSet<?> aVES = new ValidationExecutorSet<>(aVESID, "name", false);
PhiveJsonHelper.applyValidationResultList(aObj, aVES, new CommonsArrayList<>(), aDisplayLocale, 123, null, null);
final String sJson = aObj.getAsJsonString();
assertEquals("{\"ves\":{\"vesid\":\"group:art:1.0\",\"name\":\"name\",\"deprecated\":false}," + "\"success\":true," + "\"interrupted\":false," + "\"mostSevereErrorLevel\":\"SUCCESS\"," + "\"results\":[]," + "\"durationMS\":123}", sJson);
}
use of com.helger.json.IJsonObject 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);
}
use of com.helger.json.IJsonObject in project phive by phax.
the class PhiveRestoredExceptionTest method testNoMessage.
@Test
public void testNoMessage() {
final Exception ex = new IllegalArgumentException();
// to Json
final IJsonObject aObj = PhiveJsonHelper.getJsonStackTrace(ex);
assertNotNull(aObj);
// from Json
final PhiveRestoredException aRSS = PhiveRestoredException.createFromJson(aObj);
assertNotNull(aRSS);
assertEquals("java.lang.IllegalArgumentException", aRSS.getClassName());
assertNull(aRSS.getMessage());
assertTrue(aRSS.getAllStackTraceLines().isNotEmpty());
// Name of this method must occur
assertTrue(aRSS.getAllStackTraceLines().containsAny(x -> x.contains("testNoMessage")));
final IJsonObject aObj2 = aRSS.getAsJson();
assertNotNull(aObj2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aObj, aObj2);
}
use of com.helger.json.IJsonObject in project phase4 by phax.
the class PModePropertyJsonConverter method convertToJson.
@Nonnull
public static IJsonObject convertToJson(@Nonnull final PModeProperty aValue) {
final IJsonObject ret = new JsonObject();
ret.add(NAME, aValue.getName());
if (aValue.hasDescription())
ret.add(DESCRIPTION, aValue.getDescription());
ret.add(DATA_TYPE, aValue.getDataType());
ret.add(MANDATORY, aValue.isMandatory());
return ret;
}
Aggregations