Search in sources :

Example 56 with IJsonObject

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);
}
Also used : IJsonObject(com.helger.json.IJsonObject) SimpleLocation(com.helger.commons.location.SimpleLocation) IError(com.helger.commons.error.IError) Test(org.junit.Test)

Example 57 with IJsonObject

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);
}
Also used : Locale(java.util.Locale) ValidationExecutorSet(com.helger.phive.api.executorset.ValidationExecutorSet) IValidationExecutorSet(com.helger.phive.api.executorset.IValidationExecutorSet) VESID(com.helger.phive.api.executorset.VESID) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Test(org.junit.Test)

Example 58 with IJsonObject

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);
}
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 59 with IJsonObject

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);
}
Also used : Assert.assertNull(org.junit.Assert.assertNull) CommonsTestHelper(com.helger.commons.mock.CommonsTestHelper) Assert.assertNotNull(org.junit.Assert.assertNotNull) IJsonObject(com.helger.json.IJsonObject) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertEquals(org.junit.Assert.assertEquals) IJsonObject(com.helger.json.IJsonObject) Test(org.junit.Test)

Example 60 with IJsonObject

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;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Aggregations

IJsonObject (com.helger.json.IJsonObject)79 JsonObject (com.helger.json.JsonObject)44 Nonnull (javax.annotation.Nonnull)41 IJsonArray (com.helger.json.IJsonArray)22 JsonArray (com.helger.json.JsonArray)19 Test (org.junit.Test)15 JsonWriter (com.helger.json.serialize.JsonWriter)12 IJson (com.helger.json.IJson)10 Map (java.util.Map)10 StopWatch (com.helger.commons.timing.StopWatch)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ZonedDateTime (java.time.ZonedDateTime)9 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)7 IError (com.helger.commons.error.IError)7 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)5 Nullable (javax.annotation.Nullable)5 Nonempty (com.helger.commons.annotation.Nonempty)4 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)3