Fix checkstyle in yang-parser-impl and enable enforcement
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / DeviationResolutionTest.java
index cb2f8cacbc355a5d21f4a4039b1c09af1c5520b0..bbbd277611326c41825aca43bf4d522b25a48d00 100644 (file)
@@ -18,9 +18,9 @@ import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResour
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
-import java.util.Date;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -44,11 +44,7 @@ public class DeviationResolutionTest {
                 "/deviation-resolution-test/deviation-not-supported");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-01-20");
-
-        final Module importedModule = schemaContext.findModuleByName("imported", revision);
-        assertNotNull(importedModule);
-
+        final Module importedModule = schemaContext.findModule("imported", Revision.valueOf("2017-01-20")).get();
         final ContainerSchemaNode myContA = (ContainerSchemaNode) importedModule.getDataChildByName(
                 QName.create(importedModule.getQNameModule(), "my-cont-a"));
         assertNotNull(myContA);
@@ -76,9 +72,7 @@ public class DeviationResolutionTest {
                 sourceForResource("/deviation-resolution-test/deviation-add/bar.yang"));
         assertNotNull(schemaContext);
 
-        final Module barModule = schemaContext.findModuleByName("bar", QName.parseRevision("2017-01-20"));
-        assertNotNull(barModule);
-
+        final Module barModule = schemaContext.findModule("bar", Revision.valueOf("2017-01-20")).get();
         final LeafListSchemaNode myLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
                 QName.create(barModule.getQNameModule(), "my-leaf-list"));
         assertNotNull(myLeafList);
@@ -122,9 +116,7 @@ public class DeviationResolutionTest {
                 sourceForResource("/deviation-resolution-test/deviation-replace/bar.yang"));
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-01-20");
-
-        final Module barModule = schemaContext.findModuleByName("bar", revision);
+        final Module barModule = schemaContext.findModule("bar", Revision.valueOf("2017-01-20")).get();
         assertNotNull(barModule);
 
         final LeafSchemaNode myLeaf = (LeafSchemaNode) barModule.getDataChildByName(
@@ -187,11 +179,7 @@ public class DeviationResolutionTest {
                 sourceForResource("/deviation-resolution-test/deviation-delete/bar.yang"));
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-01-20");
-
-        final Module barModule = schemaContext.findModuleByName("bar", revision);
-        assertNotNull(barModule);
-
+        final Module barModule = schemaContext.findModule("bar", Revision.valueOf("2017-01-20")).get();
         final LeafSchemaNode myLeaf = (LeafSchemaNode) barModule.getDataChildByName(
                 QName.create(barModule.getQNameModule(), "my-leaf"));
         assertNotNull(myLeaf);
@@ -273,8 +261,8 @@ public class DeviationResolutionTest {
         } catch (final ReactorException ex) {
             final Throwable cause = ex.getCause();
             assertTrue(cause instanceof InferenceException);
-            assertTrue(cause.getMessage().startsWith("(bar?revision=2017-01-20)my-cont is not a valid deviation " +
-                    "target for substatement (urn:ietf:params:xml:ns:yang:yin:1)max-elements."));
+            assertTrue(cause.getMessage().startsWith("(bar?revision=2017-01-20)my-cont is not a valid deviation "
+                    "target for substatement (urn:ietf:params:xml:ns:yang:yin:1)max-elements."));
         }
     }
 
@@ -288,8 +276,8 @@ public class DeviationResolutionTest {
         } catch (final ReactorException ex) {
             final Throwable cause = ex.getCause().getCause();
             assertTrue(cause instanceof InferenceException);
-            assertTrue(cause.getMessage().startsWith("Deviation target 'Absolute{path=[(bar?revision=2017-01-20)" +
-                    "invalid, (bar?revision=2017-01-20)path]}' not found"));
+            assertTrue(cause.getMessage().startsWith("Deviation target 'Absolute{path=[(bar?revision=2017-01-20)"
+                    "invalid, (bar?revision=2017-01-20)path]}' not found"));
         }
     }
 
@@ -303,9 +291,9 @@ public class DeviationResolutionTest {
         } catch (final ReactorException ex) {
             final Throwable cause = ex.getCause();
             assertTrue(cause instanceof InferenceException);
-            assertTrue(cause.getMessage().startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang" +
-                    ":yin:1)config to target node (bar?revision=2017-01-20)my-leaf because it is already defined in" +
-                    " target and can appear only once."));
+            assertTrue(cause.getMessage().startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
+                    + ":yin:1)config to target node (bar?revision=2017-01-20)my-leaf because it is already defined in"
+                    " target and can appear only once."));
         }
     }
 
@@ -319,9 +307,9 @@ public class DeviationResolutionTest {
         } catch (final ReactorException ex) {
             final Throwable cause = ex.getCause();
             assertTrue(cause instanceof InferenceException);
-            assertTrue(cause.getMessage().startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang" +
-                    ":yin:1)default to target node (bar?revision=2017-01-20)my-leaf because it is already defined in" +
-                    " target and can appear only once."));
+            assertTrue(cause.getMessage().startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
+                    + ":yin:1)default to target node (bar?revision=2017-01-20)my-leaf because it is already defined in"
+                    " target and can appear only once."));
         }
     }
 
@@ -335,9 +323,9 @@ public class DeviationResolutionTest {
         } catch (final ReactorException ex) {
             final Throwable cause = ex.getCause();
             assertTrue(cause instanceof InferenceException);
-            assertTrue(cause.getMessage().startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang" +
-                    ":yin:1)default to target node (bar?revision=2017-02-01)my-used-leaf because it is already " +
-                    "defined in target and can appear only once."));
+            assertTrue(cause.getMessage().startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
+                    + ":yin:1)default to target node (bar?revision=2017-02-01)my-used-leaf because it is already "
+                    "defined in target and can appear only once."));
         }
     }
 
@@ -351,13 +339,14 @@ public class DeviationResolutionTest {
         } catch (final ReactorException ex) {
             final Throwable cause = ex.getCause();
             assertTrue(cause instanceof InferenceException);
-            assertTrue(cause.getMessage().startsWith("Deviation cannot replace substatement " +
-                    "(urn:ietf:params:xml:ns:yang:yin:1)units in target node (bar?revision=2017-01-20)my-leaf " +
-                    "because it does not exist in target node."));
+            assertTrue(cause.getMessage().startsWith("Deviation cannot replace substatement "
+                    + "(urn:ietf:params:xml:ns:yang:yin:1)units in target node (bar?revision=2017-01-20)my-leaf "
+                    "because it does not exist in target node."));
         }
     }
 
     @Test
+    @SuppressWarnings("checkstyle:regexpSinglelineJava")
     public void shouldLogInvalidDeviateReplaceAttempt() throws Exception {
         final PrintStream stdout = System.out;
         final ByteArrayOutputStream output = new ByteArrayOutputStream();
@@ -370,13 +359,14 @@ public class DeviationResolutionTest {
                 sourceForResource("/deviation-resolution-test/deviation-replace/bar-invalid-2.yang"));
 
         testLog = output.toString();
-        assertTrue(testLog.contains("Deviation cannot replace substatement (urn:ietf:params:xml:ns:yang:yin:1)default" +
-                " in target leaf-list (bar?revision=2017-01-20)my-leaf-list because a leaf-list can have multiple " +
-                "default statements."));
         System.setOut(stdout);
+        assertTrue(testLog.contains("Deviation cannot replace substatement (urn:ietf:params:xml:ns:yang:yin:1)default"
+                + " in target leaf-list (bar?revision=2017-01-20)my-leaf-list because a leaf-list can have multiple "
+                + "default statements."));
     }
 
     @Test
+    @SuppressWarnings("checkstyle:regexpSinglelineJava")
     public void shouldLogInvalidDeviateDeleteAttempt() throws Exception {
         final PrintStream stdout = System.out;
         final ByteArrayOutputStream output = new ByteArrayOutputStream();
@@ -389,10 +379,10 @@ public class DeviationResolutionTest {
                 sourceForResource("/deviation-resolution-test/deviation-delete/bar-invalid.yang"));
 
         testLog = output.toString();
-        assertTrue(testLog.contains("Deviation cannot delete substatement (urn:ietf:params:xml:ns:yang:yin:1)units " +
-                "with argument 'seconds' in target node (bar?revision=2017-01-20)my-leaf because it does not exist " +
-                "in the target node."));
         System.setOut(stdout);
+        assertTrue(testLog.contains("Deviation cannot delete substatement (urn:ietf:params:xml:ns:yang:yin:1)units "
+                + "with argument 'seconds' in target node (bar?revision=2017-01-20)my-leaf because it does not exist "
+                + "in the target node."));
     }
 
     @Test