Bug 8153: Enforce check-style rules for netconf - sal-netconf-connector
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / schema / mapping / NetconfMessageTransformerTest.java
index f0e3966718ff4d5583e2c2f15c11c0a12e0fe5c7..a0c90c7293fa5c20c8b136fafa2d03819eaeb20b 100644 (file)
@@ -126,7 +126,8 @@ public class NetconfMessageTransformerTest {
 
     @Test
     public void testDiscardChangesRequest() throws Exception {
-        final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME), null);
+        final NetconfMessage netconfMessage =
+                netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME), null);
         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<discard"));
         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<rpc"));
         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("message-id"));
@@ -136,70 +137,78 @@ public class NetconfMessageTransformerTest {
     public void tesGetSchemaRequest() throws Exception {
         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(GET_SCHEMA_QNAME),
                 NetconfRemoteSchemaYangSourceProvider.createGetSchemaRequest("module", Optional.of("2012-12-12")));
-        assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                "<get-schema xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
-                "<format>yang</format>\n" +
-                "<identifier>module</identifier>\n" +
-                "<version>2012-12-12</version>\n" +
-                "</get-schema>\n" +
-                "</rpc>");
+        assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                + "<get-schema xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
+                + "<format>yang</format>\n"
+                + "<identifier>module</identifier>\n"
+                + "<version>2012-12-12</version>\n"
+                + "</get-schema>\n"
+                "</rpc>");
     }
 
     @Test
     public void tesGetSchemaResponse() throws Exception {
         final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true));
         final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument(
-                "<rpc-reply message-id=\"101\"\n" +
-                        "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                        "<data\n" +
-                        "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
-                        "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
-                        "Random YANG SCHEMA\n" +
-                        "</xs:schema>\n" +
-                        "</data>\n" +
-                        "</rpc-reply>"
+                "<rpc-reply message-id=\"101\"\n"
+                        + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                        + "<data\n"
+                        + "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
+                        + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
+                        + "Random YANG SCHEMA\n"
+                        + "</xs:schema>\n"
+                        + "</data>\n"
+                        "</rpc-reply>"
         ));
-        final DOMRpcResult compositeNodeRpcResult = netconfMessageTransformer.toRpcResult(response, toPath(GET_SCHEMA_QNAME));
+        final DOMRpcResult compositeNodeRpcResult =
+                netconfMessageTransformer.toRpcResult(response, toPath(GET_SCHEMA_QNAME));
         assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
         assertNotNull(compositeNodeRpcResult.getResult());
-        final DOMSource schemaContent = ((AnyXmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).getValue().iterator().next()).getValue();
-        assertThat(((Element) schemaContent.getNode()).getTextContent(), CoreMatchers.containsString("Random YANG SCHEMA"));
+        final DOMSource schemaContent =
+            ((AnyXmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).getValue().iterator().next()).getValue();
+        assertThat(((Element) schemaContent.getNode()).getTextContent(),
+                CoreMatchers.containsString("Random YANG SCHEMA"));
     }
 
     @Test
     public void testGetConfigResponse() throws Exception {
-        final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" +
-                "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                "<data>\n" +
-                "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
-                "<schemas>\n" +
-                "<schema>\n" +
-                "<identifier>module</identifier>\n" +
-                "<version>2012-12-12</version>\n" +
-                "<format xmlns:x=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">x:yang</format>\n" +
-                "</schema>\n" +
-                "</schemas>\n" +
-                "</netconf-state>\n" +
-                "</data>\n" +
-                "</rpc-reply>"));
+        final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n"
+                + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                + "<data>\n"
+                + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
+                + "<schemas>\n"
+                + "<schema>\n"
+                + "<identifier>module</identifier>\n"
+                + "<version>2012-12-12</version>\n"
+                + "<format xmlns:x=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">x:yang</format>\n"
+                + "</schema>\n"
+                + "</schemas>\n"
+                + "</netconf-state>\n"
+                + "</data>\n"
+                "</rpc-reply>"));
 
         final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true));
-        final DOMRpcResult compositeNodeRpcResult = netconfMessageTransformer.toRpcResult(response, toPath(NETCONF_GET_CONFIG_QNAME));
+        final DOMRpcResult compositeNodeRpcResult =
+                netconfMessageTransformer.toRpcResult(response, toPath(NETCONF_GET_CONFIG_QNAME));
         assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
         assertNotNull(compositeNodeRpcResult.getResult());
 
         final List<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> values = Lists.newArrayList(
-                NetconfRemoteSchemaYangSourceProvider.createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue());
+                NetconfRemoteSchemaYangSourceProvider
+                        .createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue());
 
         final Map<QName, Object> keys = Maps.newHashMap();
         for (final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> value : values) {
             keys.put(value.getNodeType(), value.getValue());
         }
 
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates identifierWithPredicates = new YangInstanceIdentifier.NodeIdentifierWithPredicates(Schema.QNAME, keys);
-        final MapEntryNode schemaNode = Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
+        final YangInstanceIdentifier.NodeIdentifierWithPredicates identifierWithPredicates =
+                new YangInstanceIdentifier.NodeIdentifierWithPredicates(Schema.QNAME, keys);
+        final MapEntryNode schemaNode =
+                Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
 
-        final ContainerNode data = (ContainerNode) ((ContainerNode) compositeNodeRpcResult.getResult()).getChild(toId(NETCONF_DATA_QNAME)).get();
+        final ContainerNode data = (ContainerNode) ((ContainerNode) compositeNodeRpcResult
+                .getResult()).getChild(toId(NETCONF_DATA_QNAME)).get();
         final ContainerNode state = (ContainerNode) data.getChild(toId(NetconfState.QNAME)).get();
         final ContainerNode schemas = (ContainerNode) state.getChild(toId(Schemas.QNAME)).get();
         final MapNode schemaParent = (MapNode) schemas.getChild(toId(Schema.QNAME)).get();
@@ -218,59 +227,68 @@ public class NetconfMessageTransformerTest {
         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_GET_CONFIG_QNAME),
                 NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter));
 
-        assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                "<get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n" +
-                "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
-                "<schemas/>\n" +
-                "</netconf-state>" +
-                "</filter>\n" +
-                "<source>\n" +
-                "<running/>\n" +
-                "</source>\n" +
-                "</get-config>" +
-                "</rpc>");
+        assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                + "<get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n"
+                + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
+                + "<schemas/>\n"
+                + "</netconf-state>"
+                + "</filter>\n"
+                + "<source>\n"
+                + "<running/>\n"
+                + "</source>\n"
+                + "</get-config>"
+                "</rpc>");
     }
 
     @Test
     public void testEditConfigRequest() throws Exception {
         final List<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> values = Lists.newArrayList(
-            NetconfRemoteSchemaYangSourceProvider.createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue());
+                NetconfRemoteSchemaYangSourceProvider
+                        .createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue());
 
         final Map<QName, Object> keys = Maps.newHashMap();
         for (final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> value : values) {
             keys.put(value.getNodeType(), value.getValue());
         }
 
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates identifierWithPredicates = new YangInstanceIdentifier.NodeIdentifierWithPredicates(Schema.QNAME, keys);
-        final MapEntryNode schemaNode = Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
+        final YangInstanceIdentifier.NodeIdentifierWithPredicates identifierWithPredicates =
+                new YangInstanceIdentifier.NodeIdentifierWithPredicates(Schema.QNAME, keys);
+        final MapEntryNode schemaNode =
+                Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
 
-        final YangInstanceIdentifier id = YangInstanceIdentifier.builder().node(NetconfState.QNAME).node(Schemas.QNAME).node(Schema.QNAME).nodeWithKey(Schema.QNAME, keys).build();
-        final DataContainerChild<?, ?> editConfigStructure = createEditConfigStructure(BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext(), id, Optional.<ModifyAction>absent(), Optional.<NormalizedNode<?, ?>>fromNullable(schemaNode));
+        final YangInstanceIdentifier id = YangInstanceIdentifier.builder()
+                .node(NetconfState.QNAME).node(Schemas.QNAME).node(Schema.QNAME)
+                .nodeWithKey(Schema.QNAME, keys).build();
+        final DataContainerChild<?, ?> editConfigStructure =
+                createEditConfigStructure(BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext(), id,
+                        Optional.<ModifyAction>absent(), Optional.<NormalizedNode<?, ?>>fromNullable(schemaNode));
 
         final DataContainerChild<?, ?> target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_QNAME);
 
-        final ContainerNode wrap = NetconfMessageTransformUtil.wrap(NETCONF_EDIT_CONFIG_QNAME, editConfigStructure, target);
-        final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_EDIT_CONFIG_QNAME), wrap);
-
-        assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                "<edit-config>\n" +
-                "<target>\n" +
-                "<candidate/>\n" +
-                "</target>\n" +
-                "<config>\n" +
-                "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
-                "<schemas>\n" +
-                "<schema>\n" +
-                "<identifier>module</identifier>\n" +
-                "<version>2012-12-12</version>\n" +
-                "<format>yang</format>\n" +
-                "</schema>\n" +
-                "</schemas>\n" +
-                "</netconf-state>\n" +
-                "</config>\n" +
-                "</edit-config>\n" +
-                "</rpc>");
+        final ContainerNode wrap =
+                NetconfMessageTransformUtil.wrap(NETCONF_EDIT_CONFIG_QNAME, editConfigStructure, target);
+        final NetconfMessage netconfMessage =
+                netconfMessageTransformer.toRpcRequest(toPath(NETCONF_EDIT_CONFIG_QNAME), wrap);
+
+        assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                + "<edit-config>\n"
+                + "<target>\n"
+                + "<candidate/>\n"
+                + "</target>\n"
+                + "<config>\n"
+                + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
+                + "<schemas>\n"
+                + "<schema>\n"
+                + "<identifier>module</identifier>\n"
+                + "<version>2012-12-12</version>\n"
+                + "<format>yang</format>\n"
+                + "</schema>\n"
+                + "</schemas>\n"
+                + "</netconf-state>\n"
+                + "</config>\n"
+                + "</edit-config>\n"
+                + "</rpc>");
     }
 
     private static void assertSimilarXml(final NetconfMessage netconfMessage, final String xmlContent)
@@ -291,17 +309,17 @@ public class NetconfMessageTransformerTest {
         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_GET_QNAME),
                 NetconfMessageTransformUtil.wrap(NETCONF_GET_QNAME, filter));
 
-        assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
-                "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n" +
-                "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
-                "<capabilities>\n" +
-                "<capability>a:b:c</capability>\n" +
-                "</capabilities>\n" +
-                "</netconf-state>" +
-                "</filter>\n" +
-                "</get>" +
-                "</rpc>");
+        assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
+                + "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n"
+                + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
+                + "<capabilities>\n"
+                + "<capability>a:b:c</capability>\n"
+                + "</capabilities>\n"
+                + "</netconf-state>"
+                + "</filter>\n"
+                + "</get>"
+                "</rpc>");
     }
 
     private static NetconfMessageTransformer getTransformer(final SchemaContext schema) {
@@ -313,17 +331,20 @@ public class NetconfMessageTransformerTest {
         final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument(
                 "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>"
         ));
-        final DOMRpcResult compositeNodeRpcResult = netconfMessageTransformer.toRpcResult(response, toPath(NETCONF_COMMIT_QNAME));
+        final DOMRpcResult compositeNodeRpcResult =
+                netconfMessageTransformer.toRpcResult(response, toPath(NETCONF_COMMIT_QNAME));
         assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
         assertNull(compositeNodeRpcResult.getResult());
     }
 
     public SchemaContext getSchema(final boolean addBase) {
         final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
-        if(addBase) {
+        if (addBase) {
             moduleInfoBackedContext.addModuleInfos(Collections.singleton($YangModuleInfoImpl.getInstance()));
         }
-        moduleInfoBackedContext.addModuleInfos(Collections.singleton(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.$YangModuleInfoImpl.getInstance()));
+        moduleInfoBackedContext
+                .addModuleInfos(Collections.singleton(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
+                        .netconf.monitoring.rev101004.$YangModuleInfoImpl.getInstance()));
         return moduleInfoBackedContext.tryToCreateSchemaContext().get();
     }
 }