Remove netconf from commons/opendaylight pom
[controller.git] / opendaylight / netconf / netconf-netty-util / src / test / java / org / opendaylight / controller / netconf / nettyutil / handler / NetconfHelloMessageToXMLEncoderTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.nettyutil.handler;
10
11 import static org.hamcrest.CoreMatchers.containsString;
12 import static org.hamcrest.CoreMatchers.not;
13 import static org.junit.Assert.assertThat;
14
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import io.netty.channel.ChannelHandlerContext;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.config.util.xml.XmlUtil;
23 import org.opendaylight.controller.netconf.api.NetconfMessage;
24 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage;
25 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
26
27 public class NetconfHelloMessageToXMLEncoderTest {
28
29     @Mock
30     private ChannelHandlerContext ctx;
31
32     @Before
33     public void setUp() throws Exception {
34         MockitoAnnotations.initMocks(this);
35     }
36
37     @Test
38     public void testEncode() throws Exception {
39         final NetconfMessage msg = new NetconfHelloMessage(XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"),
40                 NetconfHelloMessageAdditionalHeader.fromString("[tomas;10.0.0.0:10000;tcp;client;]"));
41         final ByteBuf destination = Unpooled.buffer();
42         new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, destination);
43
44         final String encoded = new String(destination.array());
45         assertThat(encoded, containsString("[tomas;10.0.0.0:10000;tcp;client;]"));
46         assertThat(encoded, containsString("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
47     }
48
49     @Test
50     public void testEncodeNoHeader() throws Exception {
51         final NetconfMessage msg = new NetconfHelloMessage(XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
52         final ByteBuf destination = Unpooled.buffer();
53         new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, destination);
54
55         final String encoded = new String(destination.array());
56         assertThat(encoded, not(containsString("[tomas;10.0.0.0:10000;tcp;client;]")));
57         assertThat(encoded, containsString("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
58     }
59
60     @Test(expected = IllegalStateException.class)
61     public void testEncodeNotHello() throws Exception {
62         final NetconfMessage msg = new NetconfMessage(XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
63         new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, null);
64     }
65 }