--- /dev/null
+package org.opendaylight.controller.sal.connect.netconf;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.opendaylight.controller.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+import org.w3c.dom.Document;
+
+/**
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class NetconfToNotificationTest {
+
+ NetconfMessageTransformer messageTransformer;
+
+ NetconfMessage userNotification;
+
+ @Before
+ public void setup() throws Exception {
+ final List<InputStream> modelsToParse = Collections.singletonList(getClass().getResourceAsStream("/schemas/user-notification.yang"));
+ final YangContextParser parser = new YangParserImpl();
+ final Set<Module> modules = parser.parseYangModelsFromStreams(modelsToParse);
+ assertTrue(!modules.isEmpty());
+ final SchemaContext schemaContext = parser.resolveSchemaContext(modules);
+ assertNotNull(schemaContext);
+
+ messageTransformer = new NetconfMessageTransformer();
+ messageTransformer.onGlobalContextUpdated(schemaContext);
+
+ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ InputStream notifyPayloadStream = getClass().getResourceAsStream("/notification-payload.xml");
+ assertNotNull(notifyPayloadStream);
+
+ final Document doc = XmlUtil.readXmlToDocument(notifyPayloadStream);
+ assertNotNull(doc);
+ userNotification = new NetconfMessage(doc);
+ }
+
+ @Test
+ public void test() throws Exception {
+ final CompositeNode root = messageTransformer.toNotification(userNotification);
+
+ assertNotNull(root);
+ assertEquals(6, root.size());
+ assertEquals("user-visited-page", root.getKey().getLocalName());
+ }
+}
--- /dev/null
+<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
+<eventTime>2014-07-08T11:20:48UTC</eventTime>
+<user-visited-page xmlns="org:opendaylight:notification:test:ns:yang:user-notification">
+ <ui:incoming-user xmlns:ui="org:opendaylight:notification:test:ns:yang:user-notification">ui:public-user</ui:incoming-user>
+ <ip-address>172.23.29.104</ip-address>
+ <mac>00:11:00:ff:dd:02</mac>
+ <browser-id>Chrome 35.0.1916.153 m</browser-id>
+ <region>
+ <name>Slovakia</name>
+ <time-zone>UTC/GMT+2</time-zone>
+ </region>
+ <visiting-date>2014-07-08 11:20:48</visiting-date>
+</user-visited-page>
+</notification>
\ No newline at end of file
--- /dev/null
+module user-notification {
+ yang-version 1;
+ namespace "org:opendaylight:notification:test:ns:yang:user-notification";
+ prefix "user";
+
+ organization "Cisco Systems";
+ contact "Lukas Sedlak";
+ description "Test model for testing notifications";
+
+ revision "2014-07-08" {
+ description "Initial revision";
+ }
+
+ identity user-identity {
+ description "Identity of user incoming to Web Page";
+ }
+
+ identity public-user {
+ base user-identity;
+ description "Identity of random public non-registered user";
+ }
+
+ notification user-visited-page {
+ leaf incoming-user {
+ type identityref {
+ base "user-identity";
+ }
+ }
+
+ leaf ip-address {
+ type string;
+ }
+
+ leaf mac {
+ type string;
+ }
+
+ leaf browser-id {
+ type string;
+ }
+
+ container region {
+ leaf name {
+ type string;
+ }
+
+ leaf time-zone {
+ type string;
+ }
+ }
+
+ leaf visiting-date {
+ type string;
+ }
+ }
+}
\ No newline at end of file