Search in sources :

Example 6 with PathExpression

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));
}
Also used : LeafrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition) PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) StringTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 7 with PathExpression

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());
}
Also used : LeafrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition) PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) QName(org.opendaylight.yangtools.yang.common.QName) Test(org.junit.Test)

Example 8 with PathExpression

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"));
}
Also used : LeafrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition) PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) QName(org.opendaylight.yangtools.yang.common.QName) Test(org.junit.Test)

Example 9 with PathExpression

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);
}
Also used : PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) Test(org.junit.Test)

Aggregations

PathExpression (org.opendaylight.yangtools.yang.model.api.PathExpression)9 Test (org.junit.Test)7 QName (org.opendaylight.yangtools.yang.common.QName)5 LeafrefTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition)5 LocationPathSteps (org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps)3 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)2 Module (org.opendaylight.yangtools.yang.model.api.Module)2 TypedDataSchemaNode (org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode)2 Objects.requireNonNull (java.util.Objects.requireNonNull)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)1 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)1 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)1 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)1 DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 GroupingDefinition (org.opendaylight.yangtools.yang.model.api.GroupingDefinition)1 DerefSteps (org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps)1 Steps (org.opendaylight.yangtools.yang.model.api.PathExpression.Steps)1