2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.netconf.impl;
\r
10 import static junit.framework.Assert.assertNotNull;
\r
11 import io.netty.buffer.ByteBuf;
\r
12 import io.netty.buffer.Unpooled;
\r
14 import java.util.ArrayList;
\r
15 import java.util.List;
\r
17 import org.junit.Test;
\r
18 import org.opendaylight.controller.netconf.api.NetconfMessage;
\r
19 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
\r
20 import org.opendaylight.controller.netconf.util.xml.ExiParameters;
\r
21 import org.opendaylight.controller.netconf.util.xml.ExiUtil;
\r
22 import org.opendaylight.controller.netconf.util.xml.XmlElement;
\r
26 public class ExiEncodeDecodeTest {
\r
28 public void encodeExi() throws Exception{
\r
30 String startExiString = XmlFileLoader.xmlFileToString("netconfMessages/startExi.xml");
\r
31 assertNotNull(startExiString);
\r
33 NetconfMessage startExiMessage = XmlFileLoader.xmlFileToNetconfMessage(("netconfMessages/startExi.xml"));
\r
34 assertNotNull(startExiMessage);
\r
36 ExiParameters exiParams = new ExiParameters();
\r
37 exiParams.setParametersFromXmlElement(XmlElement.fromDomElement(startExiMessage.getDocument().getDocumentElement()));
\r
38 assertNotNull(exiParams);
\r
40 ByteBuf encodedBuf = Unpooled.buffer();
\r
41 ByteBuf sourceBuf = Unpooled.copiedBuffer(startExiString.getBytes());
\r
42 ExiUtil.encode(sourceBuf, encodedBuf, exiParams);
\r
44 List<Object> newOut = new ArrayList<Object>();
\r
45 ExiUtil.decode(encodedBuf, newOut, exiParams);
\r
47 ByteBuf decodedBuf = (ByteBuf)newOut.get(0);
\r
48 String decodedString = new String(decodedBuf.array(),"UTF-8");
\r
49 assertNotNull(decodedString);
\r