@Test public void testParsableByValues() throws Exception { final Configuration config = configurationFactory.getConfig(getFile(BASE_DIR + "config.yaml")); PJsonObject requestData = loadJsonRequestData(); Template template = config.getTemplate("main"); Values values = new Values("test", requestData, template, config.getDirectory(), httpClientFactory, config.getDirectory()); assertEquals("s1", getValue(values.getObject("json", JsonDataSource.class), "a.b", String.class)); }
@Override public Object getValue( @Nonnull final Template template, @Nonnull final String attributeName, @Nonnull final PObject requestJsonAttributes) { final String json; final Object value = requestJsonAttributes.opt(attributeName); if (value == null) { json = "null"; } else if (value instanceof JSONObject) { json = value.toString(); } else { final String message = "Expected a JSON Object as the value for the element with the path: '" + requestJsonAttributes.getPath(attributeName) + "' but instead " + "got a '" + value.getClass().toString() + "'"; throw new IllegalArgumentException(message); } try { final JsonDataSource result = new JsonDataSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))); result.next(); return result; } catch (JRException e) { throw new RuntimeException("Error while parsing " + requestJsonAttributes.getPath(attributeName) + " as json", e); } }
JsonDatasourceAttribute implements Attribute { @Override public Object getValue( @Nonnull final Template template, @Nonnull final String attributeName, @Nonnull final PObject requestJsonAttributes) { final String json; final Object value = requestJsonAttributes.opt(attributeName); if (value == null) { json = "null"; } else if (value instanceof JSONObject) { json = value.toString(); } else { final String message = "Expected a JSON Object as the value for the element with the path: '" + requestJsonAttributes.getPath(attributeName) + "' but instead " + "got a '" + value.getClass().toString() + "'"; throw new IllegalArgumentException(message); } try { final JsonDataSource result = new JsonDataSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))); result.next(); return result; } catch (JRException e) { throw new RuntimeException("Error while parsing " + requestJsonAttributes.getPath(attributeName) + " as json", e); } } }
JsonDatasourceAttribute implements Attribute { @Override public Object getValue( @Nonnull final Template template, @Nonnull final String attributeName, @Nonnull final PObject requestJsonAttributes) { final String json; final Object value = requestJsonAttributes.opt(attributeName); if (value == null) { json = "null"; } else if (value instanceof JSONObject) { json = value.toString(); } else { final String message = "Expected a JSON Object as the value for the element with the path: '" + requestJsonAttributes.getPath(attributeName) + "' but instead " + "got a '" + value.getClass().toString() + "'"; throw new IllegalArgumentException(message); } try { final JsonDataSource result = new JsonDataSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))); result.next(); return result; } catch (JRException e) { throw new RuntimeException("Error while parsing " + requestJsonAttributes.getPath(attributeName) + " as json", e); } }  }
JsonDatasourceAttribute implements Attribute { @Override public Object getValue( @Nonnull final Template template, @Nonnull final String attributeName, @Nonnull final PObject requestJsonAttributes) { final String json; final Object value = requestJsonAttributes.opt(attributeName); if (value == null) { json = "null"; } else if (value instanceof JSONObject) { json = value.toString(); } else { final String message = "Expected a JSON Object as the value for the element with the path: '" + requestJsonAttributes.getPath(attributeName) + "' but instead " + "got a '" + value.getClass().toString() + "'"; throw new IllegalArgumentException(message); } try { final JsonDataSource result = new JsonDataSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))); result.next(); return result; } catch (JRException e) { throw new RuntimeException("Error while parsing " + requestJsonAttributes.getPath(attributeName) + " as json", e); } }  @Override void printClientConfig(final JSONWriter json, final Template template); @Override void setConfigName(final String name); @Override Class getValueType(); @Override Object getValue(
            @Nonnull final Template template, @Nonnull final String attributeName,
            @Nonnull final PObject requestJsonAttributes); @Override void validate(final List<Throwable> validationErrors, final Configuration configuration); }
JsonDatasourceAttribute implements Attribute { @Override public Object getValue( @Nonnull final Template template, @Nonnull final String attributeName, @Nonnull final PObject requestJsonAttributes) { final String json; final Object value = requestJsonAttributes.opt(attributeName); if (value == null) { json = "null"; } else if (value instanceof JSONObject) { json = value.toString(); } else { final String message = "Expected a JSON Object as the value for the element with the path: '" + requestJsonAttributes.getPath(attributeName) + "' but instead " + "got a '" + value.getClass().toString() + "'"; throw new IllegalArgumentException(message); } try { final JsonDataSource result = new JsonDataSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))); result.next(); return result; } catch (JRException e) { throw new RuntimeException("Error while parsing " + requestJsonAttributes.getPath(attributeName) + " as json", e); } }  @Override void printClientConfig(final JSONWriter json, final Template template); @Override void setConfigName(final String name); @Override Class getValueType(); @Override Object getValue(
            @Nonnull final Template template, @Nonnull final String attributeName,
            @Nonnull final PObject requestJsonAttributes); @Override void validate(final List<Throwable> validationErrors, final Configuration configuration);  }