Search in sources :

Example 1 with QueryExpression

use of org.opendaylight.mdsal.binding.api.query.QueryExpression in project mdsal by opendaylight.

the class QueryBuilderTest method testFindZeroAlarms.

@Test
public void testFindZeroAlarms() {
    final Stopwatch sw = Stopwatch.createStarted();
    final QueryExpression<Alarms> query = factory.querySubtree(InstanceIdentifier.create(Foo.class)).extractChild(System.class).extractChild(Alarms.class).matching().leaf(Alarms::getId).valueEquals(Uint64.ZERO).build();
    LOG.info("Query built in {}", sw);
    final List<? extends Item<@NonNull Alarms>> items = execute(query).getItems();
    assertEquals(2, items.size());
    List<Alarms> verifiedResult = items.stream().map(Item::object).filter(object -> object.getId().equals(Uint64.ZERO)).collect(Collectors.toList());
    assertNotNull(verifiedResult);
    assertEquals(2, verifiedResult.size());
}
Also used : BindingCodecTree(org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree) Uint64(org.opendaylight.yangtools.yang.common.Uint64) BeforeClass(org.junit.BeforeClass) Stopwatch(com.google.common.base.Stopwatch) QueryResult(org.opendaylight.mdsal.binding.api.query.QueryResult) NestedList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedList) QueryExecutor(org.opendaylight.mdsal.binding.api.query.QueryExecutor) QueryFactory(org.opendaylight.mdsal.binding.api.query.QueryFactory) LoggerFactory(org.slf4j.LoggerFactory) SystemKey(org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.SystemKey) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) Foo(org.opendaylight.yang.gen.v1.mdsal.query.norev.Foo) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Before(org.junit.Before) BindingRuntimeHelpers(org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers) Alarms(org.opendaylight.yang.gen.v1.mdsal.query.norev.second.grp.Alarms) AlarmsBuilder(org.opendaylight.yang.gen.v1.mdsal.query.norev.second.grp.AlarmsBuilder) AfterClass(org.junit.AfterClass) Empty(org.opendaylight.yangtools.yang.common.Empty) Logger(org.slf4j.Logger) BindingMap(org.opendaylight.yangtools.yang.binding.util.BindingMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Collectors(java.util.stream.Collectors) FooBuilder(org.opendaylight.yang.gen.v1.mdsal.query.norev.FooBuilder) QueryExpression(org.opendaylight.mdsal.binding.api.query.QueryExpression) List(java.util.List) Item(org.opendaylight.mdsal.binding.api.query.QueryResult.Item) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) DefaultBindingCodecTreeFactory(org.opendaylight.mdsal.binding.dom.codec.impl.DefaultBindingCodecTreeFactory) SystemBuilder(org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.SystemBuilder) NonNull(org.eclipse.jdt.annotation.NonNull) Assert.assertEquals(org.junit.Assert.assertEquals) System(org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.System) Item(org.opendaylight.mdsal.binding.api.query.QueryResult.Item) Foo(org.opendaylight.yang.gen.v1.mdsal.query.norev.Foo) Stopwatch(com.google.common.base.Stopwatch) Alarms(org.opendaylight.yang.gen.v1.mdsal.query.norev.second.grp.Alarms) System(org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.System) Test(org.junit.Test)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 AfterClass (org.junit.AfterClass)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 QueryExecutor (org.opendaylight.mdsal.binding.api.query.QueryExecutor)1 QueryExpression (org.opendaylight.mdsal.binding.api.query.QueryExpression)1 QueryFactory (org.opendaylight.mdsal.binding.api.query.QueryFactory)1 QueryResult (org.opendaylight.mdsal.binding.api.query.QueryResult)1 Item (org.opendaylight.mdsal.binding.api.query.QueryResult.Item)1 BindingCodecTree (org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree)1 DefaultBindingCodecTreeFactory (org.opendaylight.mdsal.binding.dom.codec.impl.DefaultBindingCodecTreeFactory)1 BindingRuntimeHelpers (org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers)1 Foo (org.opendaylight.yang.gen.v1.mdsal.query.norev.Foo)1 FooBuilder (org.opendaylight.yang.gen.v1.mdsal.query.norev.FooBuilder)1