Search in sources :

Example 1 with YangLocationPath

use of org.opendaylight.yangtools.yang.xpath.api.YangLocationPath in project yangtools by opendaylight.

the class PathExpressionParserTest method testCurrentPredicateParsing.

@Test
public void testCurrentPredicateParsing() {
    final YangLocationPath path = ((LocationPathSteps) parser.parseExpression(ctx, "/device_types/device_type[type = current()/../type_text]/desc").getSteps()).getLocationPath();
    assertTrue(path.isAbsolute());
    path.getSteps();
    assertEquals(ImmutableList.of(YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("device_types")), YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("device_type"), ImmutableSet.of(YangBinaryOperator.EQUALS.exprWith(YangQNameExpr.of(UnresolvedQName.unqualified("type")), YangPathExpr.of(YangFunctionCallExpr.of(YangFunction.CURRENT.getIdentifier()), Relative.relative(YangXPathAxis.PARENT.asStep(), YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("type_text"))))))), YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("desc"))), path.getSteps());
}
Also used : YangLocationPath(org.opendaylight.yangtools.yang.xpath.api.YangLocationPath) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) Test(org.junit.Test)

Example 2 with YangLocationPath

use of org.opendaylight.yangtools.yang.xpath.api.YangLocationPath in project yangtools by opendaylight.

the class YT1060Test method before.

@Before
public void before() {
    context = YangParserTestUtils.parseYangResourceDirectory("/yt1060");
    final Module module = context.findModule(CONT.getModule()).get();
    final ContainerSchemaNode cont = (ContainerSchemaNode) module.findDataChildByName(CONT).get();
    final LeafSchemaNode leaf1 = (LeafSchemaNode) cont.findDataChildByName(LEAF1).get();
    path = ((LeafrefTypeDefinition) leaf1.getType()).getPathStatement();
    // Quick checks before we get to the point
    final Steps pathSteps = path.getSteps();
    assertThat(pathSteps, isA(LocationPathSteps.class));
    final YangLocationPath locationPath = ((LocationPathSteps) pathSteps).getLocationPath();
    assertTrue(locationPath.isAbsolute());
    final ImmutableList<Step> steps = locationPath.getSteps();
    assertEquals(2, steps.size());
    steps.forEach(step -> assertThat(step, isA(ResolvedQNameStep.class)));
}
Also used : Steps(org.opendaylight.yangtools.yang.model.api.PathExpression.Steps) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) YangLocationPath(org.opendaylight.yangtools.yang.xpath.api.YangLocationPath) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) ResolvedQNameStep(org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ResolvedQNameStep) Step(org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Step) Module(org.opendaylight.yangtools.yang.model.api.Module) Before(org.junit.Before)

Aggregations

LocationPathSteps (org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps)2 YangLocationPath (org.opendaylight.yangtools.yang.xpath.api.YangLocationPath)2 Before (org.junit.Before)1 Test (org.junit.Test)1 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)1 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1 Steps (org.opendaylight.yangtools.yang.model.api.PathExpression.Steps)1 ResolvedQNameStep (org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ResolvedQNameStep)1 Step (org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Step)1