Make ConstraintMetaDefition attributes Optional
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / MustAndWhenStmtTest.java
index 2392cf4d95c6fc5522aa166882eca735a34f76a6..8ddabcebbdaac655bbb30f65b92b4a624ff336a9 100644 (file)
@@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
 import java.util.Iterator;
+import java.util.Optional;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -42,7 +43,7 @@ public class MustAndWhenStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("must-test", null);
+        final Module testModule = result.findModules("must-test").iterator().next();
         assertNotNull(testModule);
 
         final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
@@ -55,17 +56,20 @@ public class MustAndWhenStmtTest {
 
         final Iterator<MustDefinition> mustsIterator = musts.iterator();
         MustDefinition mustStmt = mustsIterator.next();
-        assertThat(mustStmt.getXpath().toString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and " +
-                "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
-        assertThat(mustStmt.getErrorMessage(), anyOf(is("An ethernet MTU must be 1500"), is("An atm MTU must be 64 " +
-                ".. 17966")));
-        assertThat(mustStmt.getErrorAppTag(), anyOf(is("An ethernet error"), is("An atm error")));
+        assertThat(mustStmt.getXpath().toString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and "
+                + "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
+        assertThat(mustStmt.getErrorMessage(), anyOf(is(Optional.of("An ethernet MTU must be 1500")),
+            is(Optional.of("An atm MTU must be 64 .. 17966"))));
+        assertThat(mustStmt.getErrorAppTag(), anyOf(is(Optional.of("An ethernet error")),
+            is(Optional.of("An atm error"))));
         mustStmt = mustsIterator.next();
-        assertThat(mustStmt.getXpath().toString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and " +
-                "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
-        assertThat(mustStmt.getErrorMessage(), anyOf(is("An ethernet MTU must be 1500"), is("An atm MTU must be 64 " +
-                ".. 17966")));
-        assertThat(mustStmt.getErrorAppTag(), anyOf(is("An ethernet error"), is("An atm error")));
+        assertThat(mustStmt.getXpath().toString(), anyOf(
+            is("ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)"),
+            is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
+        assertThat(mustStmt.getErrorMessage(), anyOf(is(Optional.of("An ethernet MTU must be 1500")),
+            is(Optional.of("An atm MTU must be 64 .. 17966"))));
+        assertThat(mustStmt.getErrorAppTag(), anyOf(is(Optional.of("An ethernet error")),
+            is(Optional.of("An atm error"))));
     }
 
     @Test
@@ -76,11 +80,13 @@ public class MustAndWhenStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("when-test", null);
+        final Module testModule = result.findModules("when-test").iterator().next();
         assertNotNull(testModule);
 
-        final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "test-container"));
+        final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
+            QName.create(testModule.getQNameModule(), "test-container"));
         assertNotNull(container);
-        assertEquals("conditional-leaf = 'autumn-leaf'", container.getConstraints().getWhenCondition().toString());
+        assertEquals("conditional-leaf = 'autumn-leaf'", container.getConstraints().getWhenCondition()
+            .get().toString());
     }
 }