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