Bug 8153: Enforce check-style rules for netconf - netconf-util
[netconf.git] / netconf / netconf-util / src / test / java / org / opendaylight / netconf / util / messages / NetconfMessageUtilTest.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.netconf.util.messages;
10
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.Collection;
15 import org.junit.Test;
16 import org.opendaylight.netconf.api.NetconfMessage;
17 import org.opendaylight.netconf.util.test.XmlFileLoader;
18 import org.w3c.dom.Document;
19
20 public class NetconfMessageUtilTest {
21     @Test
22     public void testNetconfMessageUtil() throws Exception {
23         Document okMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml");
24         assertTrue(NetconfMessageUtil.isOKMessage(new NetconfMessage(okMessage)));
25         assertFalse(NetconfMessageUtil.isErrorMessage(new NetconfMessage(okMessage)));
26
27         Document errorMessage = XmlFileLoader
28                 .xmlFileToDocument("netconfMessages/communicationError/testClientSendsRpcReply_expectedResponse.xml");
29         assertTrue(NetconfMessageUtil.isErrorMessage(new NetconfMessage(errorMessage)));
30         assertFalse(NetconfMessageUtil.isOKMessage(new NetconfMessage(errorMessage)));
31
32         Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/client_hello.xml");
33         Collection<String> caps =
34                 NetconfMessageUtil.extractCapabilitiesFromHello(new NetconfMessage(helloMessage).getDocument());
35         assertTrue(caps.contains("urn:ietf:params:netconf:base:1.0"));
36         assertTrue(caps.contains("urn:ietf:params:netconf:base:1.1"));
37     }
38 }