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