use of org.opendaylight.yangtools.yang.model.api.PathExpression in project yangtools by opendaylight.
the class YT1100Test method testChoiceCaseRelativeLeafref.
@Test
public void testChoiceCaseRelativeLeafref() {
final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt1100.yang");
final Module module = context.findModule("yt1100").orElseThrow();
final QNameModule qnm = module.getQNameModule();
final QName foo = QName.create(qnm, "foo");
final QName schedulerNode = QName.create(qnm, "scheduler-node");
final QName childSchedulerNodes = QName.create(qnm, "child-scheduler-nodes");
final QName name = QName.create(qnm, "name");
final DataSchemaNode leaf = module.findDataTreeChild(foo, schedulerNode, childSchedulerNodes, name).orElseThrow();
assertThat(leaf, instanceOf(LeafSchemaNode.class));
final TypeDefinition<?> type = ((LeafSchemaNode) leaf).getType();
assertThat(type, instanceOf(LeafrefTypeDefinition.class));
final PathExpression leafref = ((LeafrefTypeDefinition) type).getPathStatement();
final EffectiveStatement<?, ?> resolvedLeafRef = SchemaInferenceStack.ofDataTreePath(context, foo, schedulerNode, childSchedulerNodes, name).resolvePathExpression(leafref);
assertThat(resolvedLeafRef, instanceOf(LeafSchemaNode.class));
final LeafSchemaNode targetLeaf = (LeafSchemaNode) resolvedLeafRef;
assertEquals(QName.create(qnm, "name"), targetLeaf.getQName());
assertThat(targetLeaf.getType(), instanceOf(StringTypeDefinition.class));
}
use of org.opendaylight.yangtools.yang.model.api.PathExpression in project yangtools by opendaylight.
the class LeafrefTest method testRequireInstanceSubstatement.
@Test
public void testRequireInstanceSubstatement() {
final QName qname = QName.create("test", "my-leafref");
final PathExpression path = mock(PathExpression.class);
final LeafrefTypeBuilder leafrefTypeBuilder = BaseTypes.leafrefTypeBuilder(qname).setPathStatement(path);
assertTrue(leafrefTypeBuilder.build().requireInstance());
leafrefTypeBuilder.setRequireInstance(false);
final LeafrefTypeDefinition falseLeafref = leafrefTypeBuilder.build();
assertFalse(falseLeafref.requireInstance());
leafrefTypeBuilder.setRequireInstance(true);
final LeafrefTypeDefinition trueLeafref = leafrefTypeBuilder.build();
assertTrue(trueLeafref.requireInstance());
final RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> falseBuilder = RestrictedTypes.newLeafrefBuilder(falseLeafref, qname);
assertFalse(falseBuilder.build().requireInstance());
final RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> trueBuilder = RestrictedTypes.newLeafrefBuilder(trueLeafref, qname);
assertTrue(trueBuilder.build().requireInstance());
}
use of org.opendaylight.yangtools.yang.model.api.PathExpression in project yangtools by opendaylight.
the class LeafrefTest method testMethodsOfLeafrefTest.
@Test
public void testMethodsOfLeafrefTest() {
final QName qname = QName.create("test", "List1");
final PathExpression revision = mock(PathExpression.class);
final PathExpression revision2 = mock(PathExpression.class);
final LeafrefTypeDefinition leafref = BaseTypes.leafrefTypeBuilder(qname).setPathStatement(revision).build();
final LeafrefTypeDefinition leafref2 = BaseTypes.leafrefTypeBuilder(qname).setPathStatement(revision2).build();
final LeafrefTypeDefinition leafref3 = BaseTypes.leafrefTypeBuilder(qname).setPathStatement(revision).build();
final LeafrefTypeDefinition leafref4 = leafref;
assertNotNull("Object 'leafref' shouldn't be null.", leafref);
assertNull("Base type of 'leafref' should be null.", leafref.getBaseType());
assertEquals(Optional.empty(), leafref.getUnits());
assertEquals(Optional.empty(), leafref.getDefaultValue());
assertEquals(qname, leafref.getQName());
assertFalse(leafref.getDescription().isPresent());
assertFalse(leafref.getReference().isPresent());
assertEquals("Status of 'leafref' is current.", Status.CURRENT, leafref.getStatus());
assertTrue("Object 'leafref' shouldn't have any unknown schema nodes.", leafref.getUnknownSchemaNodes().isEmpty());
assertEquals("Revision aware XPath of 'leafref' should be '/test:Cont1/test:List1'.", revision, leafref.getPathStatement());
assertNotNull("String representation of 'leafref' shouldn't be null.", leafref.toString());
assertNotEquals("Hash codes of two different object of type Leafref shouldn't be equal.", leafref.hashCode(), leafref2.hashCode());
assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref3));
assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref4));
assertFalse("Objects of type Leafref shouldn't be equal.", leafref.equals(leafref2));
assertFalse("Objects shouldn't be equal.", leafref.equals(null));
assertFalse("Objects shouldn't be equal.", leafref.equals("test"));
}
use of org.opendaylight.yangtools.yang.model.api.PathExpression in project yangtools by opendaylight.
the class TypeTest method leafrefTypeTest.
@Test
public void leafrefTypeTest() {
final PathExpression expr = mock(PathExpression.class);
final LeafrefTypeBuilder leafrefTypeBuilder1 = BaseTypes.leafrefTypeBuilder(Q_NAME);
final LeafrefTypeBuilder leafrefTypeBuilder2 = BaseTypes.leafrefTypeBuilder(Q_NAME);
leafrefTypeBuilder1.setPathStatement(expr);
leafrefTypeBuilder2.setPathStatement(expr);
final BaseLeafrefType baseLeafrefType1 = (BaseLeafrefType) leafrefTypeBuilder1.build();
final BaseLeafrefType baseLeafrefType2 = (BaseLeafrefType) leafrefTypeBuilder1.build();
hashCodeEqualsToStringTest(baseLeafrefType1, baseLeafrefType2);
assertEquals(expr, baseLeafrefType1.getPathStatement());
final DerivedLeafrefType derivedLeafrefType1 = (DerivedLeafrefType) DerivedTypes.derivedTypeBuilder(baseLeafrefType1, Q_NAME).build();
final DerivedLeafrefType derivedLeafrefType2 = (DerivedLeafrefType) DerivedTypes.derivedTypeBuilder(baseLeafrefType2, Q_NAME).build();
hashCodeEqualsToStringTest(derivedLeafrefType1, derivedLeafrefType2);
restrictedBuilderTest(RestrictedTypes.newLeafrefBuilder(baseLeafrefType1, Q_NAME), RestrictedTypes.newLeafrefBuilder(baseLeafrefType2, Q_NAME));
concreteBuilderTest(baseLeafrefType1, derivedLeafrefType1);
}
Aggregations