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.controller.netconf.impl;
10 import static junit.framework.Assert.assertNotNull;
12 import org.junit.Test;
13 import org.opendaylight.controller.netconf.api.NetconfMessage;
14 import org.opendaylight.controller.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().getDocumentElement()));
29 assertNotNull(exiParams);
31 ByteBuf encodedBuf = Unpooled.buffer();
32 ByteBuf sourceBuf = Unpooled.copiedBuffer(startExiString.getBytes());
33 ExiUtil.encode(sourceBuf, encodedBuf, exiParams);
35 List<Object> newOut = new ArrayList<Object>();
36 ExiUtil.decode(encodedBuf, newOut, exiParams);
38 ByteBuf decodedBuf = (ByteBuf)newOut.get(0);
39 String decodedString = new String(decodedBuf.array(),"UTF-8");
40 assertNotNull(decodedString);