summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils/src/main/java/io/fd
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-10-26 10:14:11 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-10-26 08:48:16 +0000
commitf4600723aa5e0fa99905eacd3338b33728a6c68f (patch)
treeb783639f92d2d3178b5d2503ec46591dcc0e5b17 /infra/translate-utils/src/main/java/io/fd
parent921d1729eb2736c4f9b8b14205436934bcf81813 (diff)
HONEYCOMB-266 - Test data injection with @InjectTestData
Field/Method param injection of data from json files that are bindable/parsable by provided yang schema Change-Id: I726ef5d92e85d93d1e48175287b6192538965dd5 Signed-off-by: Maros Marsalek <mmarsale@cisco.com> Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main/java/io/fd')
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
index d551802e4..3216cac20 100644
--- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
+++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
@@ -39,6 +39,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,11 +80,18 @@ public final class JsonUtils {
*/
public static ContainerNode readJsonRoot(@Nonnull final SchemaContext schemaContext,
@Nonnull final InputStream stream) {
+ // if root node, parent schema == schema context
+ return readJson(schemaContext, stream, schemaContext);
+ }
+
+ public static ContainerNode readJson(@Nonnull final SchemaContext schemaContext,
+ @Nonnull final InputStream stream,
+ @Nonnull final SchemaNode parentSchema) {
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> builder =
Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()));
final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
- try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext)) {
+ try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8));
jsonParser.parse(reader);
} catch (IOException e) {