1 package org.opendaylight.controller.netconf.impl;
\r
3 import static junit.framework.Assert.assertNotNull;
\r
4 import io.netty.buffer.ByteBuf;
\r
5 import io.netty.buffer.Unpooled;
\r
7 import java.util.ArrayList;
\r
8 import java.util.List;
\r
10 import org.junit.Test;
\r
11 import org.opendaylight.controller.netconf.api.NetconfMessage;
\r
12 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
\r
13 import org.opendaylight.controller.netconf.util.xml.ExiParameters;
\r
14 import org.opendaylight.controller.netconf.util.xml.ExiUtil;
\r
15 import org.opendaylight.controller.netconf.util.xml.XmlElement;
\r
19 public class ExiEncodeDecodeTest {
\r
21 public void encodeExi() throws Exception{
\r
23 String startExiString = XmlFileLoader.xmlFileToString("netconfMessages/startExi.xml");
\r
24 assertNotNull(startExiString);
\r
26 NetconfMessage startExiMessage = XmlFileLoader.xmlFileToNetconfMessage(("netconfMessages/startExi.xml"));
\r
27 assertNotNull(startExiMessage);
\r
29 ExiParameters exiParams = new ExiParameters();
\r
30 exiParams.setParametersFromXmlElement(XmlElement.fromDomElement(startExiMessage.getDocument().getDocumentElement()));
\r
31 assertNotNull(exiParams);
\r
33 ByteBuf encodedBuf = Unpooled.buffer();
\r
34 ByteBuf sourceBuf = Unpooled.copiedBuffer(startExiString.getBytes());
\r
35 ExiUtil.encode(sourceBuf, encodedBuf, exiParams);
\r
37 List<Object> newOut = new ArrayList<Object>();
\r
38 ExiUtil.decode(encodedBuf, newOut, exiParams);
\r
40 ByteBuf decodedBuf = (ByteBuf)newOut.get(0);
\r
41 String decodedString = new String(decodedBuf.array(),"UTF-8");
\r
42 assertNotNull(decodedString);
\r