* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import static org.junit.Assert.assertEquals;
import java.text.ParseException;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.util.ConstraintDefinitions;
import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.impl.DefaultReactors;
import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
public class ConstraintDefinitionsTest {
@Test
public void testConstraintDefinitions() throws ParseException, ReactorException, URISyntaxException, IOException,
YangSyntaxErrorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-
- reactor.addSource(YangStatementStreamSource.create(
- YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang")));
- final SchemaContext schemaContext = reactor.buildEffective();
+ final SchemaContext schemaContext = DefaultReactors.defaultReactor().newBuild()
+ .addSource(YangStatementStreamSource.create(
+ YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang")))
+ .buildEffective();
assertNotNull(schemaContext);
- final Module testModule = schemaContext.findModuleByName("foo",
- SimpleDateFormatUtil.getRevisionFormat().parse("2016-09-20"));
- assertNotNull(testModule);
-
+ final Module testModule = schemaContext.findModule("foo", Revision.of("2016-09-20")).get();
final LeafSchemaNode mandatoryLeaf1 = (LeafSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "mandatory-leaf-1"));
assertNotNull(mandatoryLeaf1);
assertNotNull(mandatoryLeaf3);
ConstraintDefinition constraints3 = mandatoryLeaf3.getConstraints();
- assertNotEquals(ConstraintDefinitions.hashCode(constraints2), ConstraintDefinitions.hashCode(constraints3));
- assertFalse(ConstraintDefinitions.equals(constraints2, constraints3));
+ assertEquals(ConstraintDefinitions.hashCode(constraints2), ConstraintDefinitions.hashCode(constraints3));
+ assertTrue(ConstraintDefinitions.equals(constraints2, constraints3));
final LeafSchemaNode mandatoryLeaf4 = (LeafSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "mandatory-leaf-4"));
final String constraintsString = ConstraintDefinitions.toString(constraints4);
assertEquals("EffectiveConstraintDefinitionImpl{whenCondition=foo = 'bar', mustConstraints=[bar != 'foo'], "
- + "mandatory=true, minElements=50, maxElements=100}", constraintsString);
+ + "minElements=50, maxElements=100}", constraintsString);
}
}
\ No newline at end of file