Fix CS warnings in sal-clustering-commons and enable enforcement
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / node / NormalizedNodeToNodeCodecTest.java
index ac8fa418fcc65c61af21fa06735c66f06a047859..2521d997f5ffa4cc4a7c3e7357f7a52f78406cf2 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.cluster.datastore.node;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+
 import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
@@ -25,142 +26,116 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class NormalizedNodeToNodeCodecTest {
-  private SchemaContext schemaContext;
-
-  @Before
-  public void setUp() {
-    schemaContext = TestModel.createTestContext();
-    assertNotNull("Schema context must not be null.", schemaContext);
-  }
-
-  private static YangInstanceIdentifier instanceIdentifierFromString(String s) {
-      return PathUtils.toYangInstanceIdentifier(s);
-  }
-
-  @Test
-  public void testNormalizeNodeAttributesToProtoBuffNode() {
-    final NormalizedNode<?, ?> documentOne = TestModel.createTestContainer();
-    String id =
-        "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test"
-            + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)outer-list"
-            + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)outer-list[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=2}]"
-            + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id";
-
-    NormalizedNodeGetter normalizedNodeGetter = new NormalizedNodeGetter(id);
-    new NormalizedNodeNavigator(normalizedNodeGetter).navigate(
-        PathUtils.toString(YangInstanceIdentifier.EMPTY), documentOne);
+    private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeToNodeCodecTest.class);
 
-    // Validate the value of id can be retrieved from the normalized node
-    NormalizedNode<?, ?> output = normalizedNodeGetter.getOutput();
-    assertNotNull(output);
+    private SchemaContext schemaContext;
 
+    @Before
+    public void setUp() {
+        schemaContext = TestModel.createTestContext();
+        assertNotNull("Schema context must not be null.", schemaContext);
+    }
 
-    NormalizedNodeToNodeCodec codec =
-        new NormalizedNodeToNodeCodec(schemaContext);
-    long start = System.currentTimeMillis();
-    Container container =
-        codec.encode(output);
-    long end = System.currentTimeMillis();
+    private static YangInstanceIdentifier instanceIdentifierFromString(String str) {
+        return PathUtils.toYangInstanceIdentifier(str);
+    }
 
-    System.out.println("Timetaken to encode :"+(end-start));
+    @Test
+    public void testNormalizeNodeAttributesToProtoBuffNode() {
+        final NormalizedNode<?, ?> documentOne = TestModel.createTestContainer();
+        String id = "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test"
+            + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)outer-list"
+            + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)outer-list["
+            + "{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=2}]"
+            + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id";
 
-    assertNotNull(container);
+        NormalizedNodeGetter normalizedNodeGetter = new NormalizedNodeGetter(id);
+        new NormalizedNodeNavigator(normalizedNodeGetter).navigate(PathUtils.toString(YangInstanceIdentifier.EMPTY),
+                documentOne);
 
-    // Decode the normalized node from the ProtocolBuffer form
-    // first get the node representation of normalized node
-    final Node node = container.getNormalizedNode();
+        // Validate the value of id can be retrieved from the normalized node
+        NormalizedNode<?, ?> output = normalizedNodeGetter.getOutput();
+        assertNotNull(output);
 
-    start = System.currentTimeMillis();
-    NormalizedNode<?, ?> normalizedNode =
-        codec.decode(node);
-    end = System.currentTimeMillis();
+        NormalizedNodeToNodeCodec codec = new NormalizedNodeToNodeCodec();
+        long start = System.currentTimeMillis();
+        Container container = codec.encode(output);
+        long end = System.currentTimeMillis();
 
-    System.out.println("Timetaken to decode :"+(end-start));
+        LOG.info("Time taken to encode: {}", end - start);
 
-    assertEquals(normalizedNode.getValue().toString(), output.getValue()
-        .toString());
-  }
+        assertNotNull(container);
 
-  @Test
-  public void testThatANormalizedNodeToProtoBuffNodeEncodeDecode()
-      throws Exception {
-    final NormalizedNode<?, ?> documentOne = TestModel.createTestContainer();
+        // Decode the normalized node from the ProtocolBuffer form
+        // first get the node representation of normalized node
+        final Node node = container.getNormalizedNode();
 
-    final NormalizedNodeToNodeCodec normalizedNodeToNodeCodec =
-        new NormalizedNodeToNodeCodec(schemaContext);
+        start = System.currentTimeMillis();
+        NormalizedNode<?, ?> normalizedNode = codec.decode(node);
+        end = System.currentTimeMillis();
 
-    Container container =
-        normalizedNodeToNodeCodec.encode(documentOne);
+        LOG.info("Time taken to decode: {}", end - start);
 
+        assertEquals(normalizedNode.getValue().toString(), output.getValue().toString());
+    }
 
-    final NormalizedNode<?, ?> decode =
-        normalizedNodeToNodeCodec
-            .decode(
-                container.getNormalizedNode());
-    assertNotNull(decode);
+    @Test
+    public void testThatANormalizedNodeToProtoBuffNodeEncodeDecode() throws Exception {
+        final NormalizedNode<?, ?> documentOne = TestModel.createTestContainer();
 
-    // let us ensure that the return decode normalized node encode returns same container
-    Container containerResult =
-        normalizedNodeToNodeCodec.encode(decode);
+        final NormalizedNodeToNodeCodec normalizedNodeToNodeCodec = new NormalizedNodeToNodeCodec();
 
-    // check first level children are proper
-    List<Node> childrenResult =
-        containerResult.getNormalizedNode().getChildList();
-    List<Node> childrenOriginal = container.getNormalizedNode().getChildList();
+        Container container = normalizedNodeToNodeCodec.encode(documentOne);
 
-    System.out.println("-------------------------------------------------");
+        final NormalizedNode<?, ?> decode = normalizedNodeToNodeCodec.decode(container.getNormalizedNode());
+        assertNotNull(decode);
 
-    System.out.println(childrenOriginal.toString());
+        // let us ensure that the return decode normalized node encode returns
+        // same container
+        Container containerResult = normalizedNodeToNodeCodec.encode(decode);
 
-    System.out.println("-------------------------------------------------");
+        // check first level children are proper
+        List<Node> childrenResult = containerResult.getNormalizedNode().getChildList();
+        List<Node> childrenOriginal = container.getNormalizedNode().getChildList();
 
-    System.out.println(childrenResult.toString());
+        LOG.info("\n-------------------------------------------------\n" + childrenOriginal
+                + "\n-------------------------------------------------\n" + childrenResult);
 
-    boolean bFound;
-    for (Node resultChild : childrenResult) {
-      bFound = false;
-      for (Node originalChild : childrenOriginal) {
+        boolean found;
+        for (Node resultChild : childrenResult) {
+            found = false;
+            for (Node originalChild : childrenOriginal) {
 
-        YangInstanceIdentifier.PathArgument result = NormalizedNodeSerializer.deSerialize(
-              containerResult.getNormalizedNode(),
-              resultChild.getPathArgument());
+                YangInstanceIdentifier.PathArgument result = NormalizedNodeSerializer
+                        .deSerialize(containerResult.getNormalizedNode(), resultChild.getPathArgument());
 
-          YangInstanceIdentifier.PathArgument original = NormalizedNodeSerializer.deSerialize(
-              container.getNormalizedNode(),
-              originalChild.getPathArgument());
+                YangInstanceIdentifier.PathArgument original = NormalizedNodeSerializer
+                        .deSerialize(container.getNormalizedNode(), originalChild.getPathArgument());
 
-        if (original.equals(result)
-            && resultChild.getIntType() == resultChild.getIntType()) {
-          bFound = true;
-          break;
+                if (original.equals(result) && resultChild.getIntType() == resultChild.getIntType()) {
+                    found = true;
+                    break;
+                }
+            }
+            assertTrue(found);
         }
-      }
-      assertTrue(bFound);
-    }
-
-  }
-
-  @Test
-  public void addAugmentations() {
-    String stringId =
-        "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test"
-            + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)augmented-list"
-            + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)augmented-list[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=1}]";
 
-    YangInstanceIdentifier identifier = instanceIdentifierFromString(stringId);
-
-    MapEntryNode uno = TestModel.createAugmentedListEntry(1, "Uno");
+    }
 
-    NormalizedNodeToNodeCodec codec =
-        new NormalizedNodeToNodeCodec(schemaContext);
+    @Test
+    public void addAugmentations() {
+        MapEntryNode uno = TestModel.createAugmentedListEntry(1, "Uno");
 
-    Container encode = codec.encode(uno);
+        NormalizedNodeToNodeCodec codec = new NormalizedNodeToNodeCodec();
 
-    System.out.println(encode.getNormalizedNode());
+        Container encode = codec.encode(uno);
 
-    codec.decode(encode.getNormalizedNode());
-  }
+        LOG.info(encode.getNormalizedNode().toString());
 
+        codec.decode(encode.getNormalizedNode());
+    }
 }