6f38f24f10c02e3e6dac9c7147fb24104f2ba9db
[controller.git] / opendaylight / netconf / netconf-notifications-impl / src / test / java / org / opendaylight / controller / netconf / notifications / impl / ops / GetTest.java
1 /*
2  * Copyright (c) 2015 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.notifications.impl.ops;
10
11 import static org.junit.Assert.assertTrue;
12
13 import com.google.common.collect.Lists;
14 import java.io.IOException;
15 import org.custommonkey.xmlunit.Diff;
16 import org.custommonkey.xmlunit.XMLUnit;
17 import org.junit.Test;
18 import org.opendaylight.controller.netconf.notifications.impl.ops.Get;
19 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.StreamsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey;
25 import org.w3c.dom.Document;
26 import org.xml.sax.SAXException;
27
28 public class GetTest {
29
30     @Test
31     public void testSerializeStreamsSubtree() throws Exception {
32         final StreamsBuilder streamsBuilder = new StreamsBuilder();
33         final StreamBuilder streamBuilder = new StreamBuilder();
34         final StreamNameType base = new StreamNameType("base");
35         streamBuilder.setName(base);
36         streamBuilder.setKey(new StreamKey(base));
37         streamBuilder.setDescription("description");
38         streamBuilder.setReplaySupport(false);
39         streamsBuilder.setStream(Lists.newArrayList(streamBuilder.build()));
40         final Streams streams = streamsBuilder.build();
41
42         final Document response = getBlankResponse();
43         Get.serializeStreamsSubtree(response, streams);
44         final Diff diff = XMLUnit.compareXML(XmlUtil.toString(response),
45                 "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
46                 "<data>\n" +
47                 "<netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">\n" +
48                 "<streams>\n" +
49                 "<stream>\n" +
50                 "<name>base</name>\n" +
51                 "<description>description</description>\n" +
52                 "<replaySupport>false</replaySupport>\n" +
53                 "</stream>\n" +
54                 "</streams>\n" +
55                 "</netconf>\n" +
56                 "</data>\n" +
57                 "</rpc-reply>\n");
58
59         assertTrue(diff.toString(), diff.identical());
60     }
61
62     private Document getBlankResponse() throws IOException, SAXException {
63
64         return XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" +
65                 "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
66                 "<data>\n" +
67                 "</data>\n" +
68                 "</rpc-reply>");
69     }
70 }