23d9b0c3d9b7ca1126ee1cdf2bb2d21a93965e15
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / query / binding / adapter / QueryBuilderTest.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.query.binding.adapter;
9
10 import org.junit.BeforeClass;
11 import org.junit.Test;
12 import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
13 import org.opendaylight.mdsal.binding.api.query.QueryExpression;
14 import org.opendaylight.mdsal.binding.api.query.QueryFactory;
15 import org.opendaylight.mdsal.binding.api.query.QueryStructureException;
16 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
17 import org.opendaylight.mdsal.binding.dom.codec.impl.DefaultBindingCodecTreeFactory;
18 import org.opendaylight.mdsal.binding.generator.impl.DefaultBindingRuntimeGenerator;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedList;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23
24 public class QueryBuilderTest {
25     private static BindingCodecTree CODEC;
26
27     private final QueryFactory factory = new DefaultQueryFactory(CODEC);
28
29     @BeforeClass
30     public static void beforeClass() {
31         CODEC = new DefaultBindingCodecTreeFactory().create(BindingRuntimeHelpers.createRuntimeContext(
32             new DefaultBindingRuntimeGenerator()));
33     }
34
35     @Test
36     public void bar() throws QueryStructureException {
37         final QueryExpression<TopLevelList> query = factory.querySubtree(InstanceIdentifier.builder(Top.class).build())
38                 .extractChild(TopLevelList.class)
39                 .matching()
40                     .childObject(NestedList.class)
41                     .leaf(NestedList::getName).contains("foo")
42                     .and().leaf(TopLevelList::getName).valueEquals("bar")
43                 .build();
44 //
45 //        // Execution start
46 //        final Result<TopLevelList> result = query.getResult();
47 //        // Execution fetch
48 //        final TopLevelList value = result.getValue();
49     }
50 }