XmlNodeConverter implements NodeConverter { @Override public NormalizedNode<?, ?> deserialize(final SchemaNode schemaNode, final Reader inputData) throws SerializationException { final XMLStreamReader reader; try { reader = XML_IN_FACTORY.createXMLStreamReader(inputData); } catch (XMLStreamException e) { throw new IllegalArgumentException(e); } final NormalizedNodeResult result = new NormalizedNodeResult(); try (NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); XmlParserStream xmlParser = XmlParserStream.create(streamWriter, this.schemaContext, schemaNode)) { xmlParser.parse(reader); } catch (XMLStreamException | URISyntaxException | IOException | SAXException e) { throw new SerializationException(e); } finally { closeQuietly(reader); } return result.getResult(); } XmlNodeConverter(final SchemaContext schemaContext); @Override Writer serializeData(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode); @Override Writer serializeRpc(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode); @Override NormalizedNode<?, ?> deserialize(final SchemaNode schemaNode, final Reader inputData); static void closeQuietly(final XMLStreamReader xmlStreamReader);  }
@Test public void testDeserializeData_list_single() throws SerializationException { SchemaNode schemaNode = ConverterUtils.getSchemaNode(schemaContext, SAMPLES_NAMESPACE, SAMPLES_REVISION, "sample-list"); NormalizedNode<?, ?> serializedData = bindingSerializer.deserialize(schemaNode, new StringReader(loadResourceAsString("sample-list.xml"))); Assert.assertNotNull(serializedData.toString()); }
@Test public void testDeserializeData_list_multiple() throws SerializationException, URISyntaxException { NormalizedNode<?, ?> serializedData = bindingSerializer.deserialize(schemaContext, new StringReader(loadResourceAsString("sample-list-multiple.xml"))); Assert.assertNotNull(serializedData.toString()); }
@Test public void testDeserializeData() throws Exception { final DataSchemaNode schemaNode = DataSchemaContextTree.from(this.schemaContext) .getChild(YangInstanceIdentifier.of(Toaster.QNAME)).getDataSchemaNode(); NormalizedNode<?, ?> deserializeData = bindingSerializer.deserialize(schemaNode, new StringReader(loadToasterXml())); Assert.assertNotNull(deserializeData); LOG.info(deserializeData.toString()); }
@Test public void testDeserializeRpc_in() throws Exception { Optional<RpcDefinition> loadRpc = ConverterUtils.loadRpc(schemaContext, SIMPLE_IO_RPC_QNAME); String loadMakeToasterInputXml = loadResourceAsString("input-output-rpc-in.xml"); NormalizedNode<?, ?> deserializeRpc = bindingSerializer.deserialize(loadRpc.get().getInput(), new StringReader(loadMakeToasterInputXml)); Assert.assertNotNull(deserializeRpc); LOG.info(deserializeRpc.toString()); }
@Test public void testDeserializeRpc_out() throws Exception { Optional<RpcDefinition> loadRpc = ConverterUtils.loadRpc(schemaContext, SIMPLE_IO_RPC_QNAME); String loadMakeToasterInputXml = loadResourceAsString("input-output-rpc-out.xml"); NormalizedNode<?, ?> deserializeRpc = bindingSerializer.deserialize(loadRpc.get().getOutput(), new StringReader(loadMakeToasterInputXml)); Assert.assertNotNull(deserializeRpc); LOG.info(deserializeRpc.toString()); }
@Test @Ignore public void testSerializeNotification() throws Exception { String notification = loadResourceAsString("notification.xml"); Optional<NotificationDefinition> loadNotification = ConverterUtils.loadNotification(schemaContext, QName.create(TOASTER_NAMESPACE, TOASTER_REVISION, "toasterRestocked")); NormalizedNode<?, ?> nodes = bindingSerializer.deserialize(loadNotification.get(), new StringReader(notification)); Assert.assertNotNull(nodes); }
@Test public void testSerializeData_container() throws SerializationException { final DataSchemaNode schemaNode = DataSchemaContextTree.from(this.schemaContext) .getChild(YangInstanceIdentifier.of(TopLevelContainer.QNAME)).getDataSchemaNode(); NormalizedNode<?, ?> deserializeData = bindingSerializer.deserialize(schemaNode, new StringReader(loadResourceAsString("top-level-container.xml"))); Assert.assertNotNull(deserializeData); LOG.info(deserializeData.toString()); }
@Test public void testSerializeData_container_rpc() throws SerializationException { Optional<RpcDefinition> loadRpc = ConverterUtils.loadRpc(schemaContext, CONTAINER_IO_RPC_QNAME); NormalizedNode<?, ?> deserializeData = bindingSerializer.deserialize(loadRpc.get().getInput(), new StringReader(loadResourceAsString("container-io-rpc.xml"))); Assert.assertNotNull(deserializeData); }