use of com.helger.phive.api.executorset.IValidationExecutorSet in project phive by phax.
the class PhiveJsonHelperTest method testValidationResultsBackAndForth.
@Test
public void testValidationResultsBackAndForth() {
// Register
final ValidationExecutorSetRegistry<IValidationSourceXML> aRegistry = new ValidationExecutorSetRegistry<>();
final VESID aVESID = new VESID("group", "art", "1.0");
final ValidationExecutorSet<IValidationSourceXML> aVES = new ValidationExecutorSet<>(aVESID, "name", false);
aVES.addExecutor(ValidationExecutorXSD.create(new ClassPathResource("test/schema1.xsd")));
aRegistry.registerValidationExecutorSet(aVES);
// Validate
final ValidationResultList aVRL = ValidationExecutionManager.executeValidation(aVES, ValidationSourceXML.create(new ClassPathResource("test/schema1.xml")));
assertTrue(aVRL.containsAtLeastOneError());
// To JSON
final Locale aDisplayLocale = Locale.US;
final IJsonObject aObj = new JsonObject();
PhiveJsonHelper.applyValidationResultList(aObj, aVES, aVRL, aDisplayLocale, 123, null, null);
// And back
final IValidationExecutorSet<IValidationSourceXML> aVES2 = PhiveJsonHelper.getAsVES(aRegistry, aObj);
assertNotNull(aVES2);
assertSame(aVES, aVES2);
final ValidationResultList aVRL2 = PhiveJsonHelper.getAsValidationResultList(aObj);
assertNotNull(aVRL2);
// direct equals doesn't work, because of the restored exception
assertEquals(aVRL.size(), aVRL2.size());
assertEquals(1, aVRL.size());
assertEquals(aVRL.get(0).getErrorList().size(), aVRL2.get(0).getErrorList().size());
// and forth
final IJsonObject aObj2 = new JsonObject();
PhiveJsonHelper.applyValidationResultList(aObj2, aVES2, aVRL2, aDisplayLocale, 123, null, null);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aObj, aObj2);
}
use of com.helger.phive.api.executorset.IValidationExecutorSet 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);
}
Aggregations