summaryrefslogtreecommitdiffstats
path: root/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/HoneycombReadInfraTest.java
blob: 143317be00ea2a0a10e1f307bb18f01cdd3dde78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/*
 * Copyright (c) 2016 Cisco and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.fd.honeycomb.data.impl;

import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.CheckedFuture;
import io.fd.honeycomb.translate.impl.read.GenericListReader;
import io.fd.honeycomb.translate.impl.read.GenericReader;
import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder;
import io.fd.honeycomb.translate.read.ListReader;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.read.Reader;
import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.util.read.ReflexiveListReaderCustomizer;
import io.fd.honeycomb.translate.util.read.ReflexiveReaderCustomizer;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.exceptions.misusing.MockitoConfigurationException;
import org.mockito.invocation.InvocationOnMock;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.container.with.list.ListInContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.container.with.list.ListInContainerBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.container.with.list.ListInContainerKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.container.with.list.list.in.container.ContainerInList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.container.with.list.list.in.container.ContainerInListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.container.with.list.list.in.container.container.in.list.NestedList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.container.with.list.list.in.container.container.in.list.NestedListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.container.with.list.list.in.container.container.in.list.NestedListKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.simple.container.ComplexAugmentContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.simple.container.ComplexAugmentContainerBuilder;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;

import javax.annotation.Nonnull;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.stream.Collectors;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;

public class HoneycombReadInfraTest extends AbstractInfraTest {

    @Mock
    private ReadContext ctx;
    private ReaderRegistry registry;

    // 1
    private Reader<SimpleContainer, SimpleContainerBuilder> simpleContainerReader =
            mockReader(Ids.SIMPLE_CONTAINER_ID, this::readSimpleContainer, SimpleContainerBuilder.class);
    // 1.1
    private Reader<SimpleAugment, SimpleAugmentBuilder> simpleAugmentReader =
            mockReader(Ids.SIMPLE_AUGMENT_ID, this::readSimpleAugment, SimpleAugmentBuilder.class);
    // 1.2
    // Noop reader(no real attributes)
    private Reader<ComplexAugment, ComplexAugmentBuilder> complexAugmentReader =
            mockReader(Ids.COMPLEX_AUGMENT_ID, HoneycombReadInfraTest::noopRead, ComplexAugmentBuilder.class);
    // 1.2.1
    private Reader<ComplexAugmentContainer, ComplexAugmentContainerBuilder> complexAugmentContainerReader =
            mockReader(Ids.COMPLEX_AUGMENT_CONTAINER_ID, this::readComplexAugmentContainer, ComplexAugmentContainerBuilder.class);
    // 2
    // Noop reader(no real attributes)
    private Reader<ContainerWithList, ContainerWithListBuilder> containerWithListReader =
            mockReader(Ids.CONTAINER_WITH_LIST_ID, HoneycombReadInfraTest::noopRead, ContainerWithListBuilder.class);
    // 2.1
    private ListReader<ListInContainer, ListInContainerKey, ListInContainerBuilder> listInContainerReader =
            mockListReader(Ids.LIST_IN_CONTAINER_ID, this::readListInContainer, this::getListInContainerIds,
                    ListInContainerBuilder.class, ctx);
    // 2.1.1
    private Reader<ContainerInList, ContainerInListBuilder> containerInListReader =
            mockReader(Ids.CONTAINER_IN_LIST_ID, this::readContainerInList, ContainerInListBuilder.class);
    // 2.1.1.1
    private ListReader<NestedList, NestedListKey, NestedListBuilder> nestedListReader =
            mockListReader(Ids.NESTED_LIST_ID, this::readNestedList, this::getNestedListIds,
                    NestedListBuilder.class, ctx);

    @Override
    void postSetup() {
        initReaderRegistry();
    }

    private void initReaderRegistry() {
        registry = new CompositeReaderRegistryBuilder()
                .add(containerWithListReader) // 2
                .addBefore(simpleContainerReader, Ids.CONTAINER_WITH_LIST_ID) // 1
                .add(simpleAugmentReader) // 1.1
                .addAfter(complexAugmentReader, Ids.SIMPLE_AUGMENT_ID) // 1.2
                .add(complexAugmentContainerReader) // 1.2.1
                .add(listInContainerReader) // 2.1
                .add(containerInListReader) // 2.1.1
                .addBefore(nestedListReader, Ids.SIMPLE_AUGMENT_ID) // 2.1.1.1 - Before relationship should be ignored
        .build();
    }

    private Reader<?, ?>[] getOrderedReaders() {
        return new Reader<?, ?>[]{simpleContainerReader, // 1
                simpleAugmentReader, // 1.1
                complexAugmentReader, // 1.2
                complexAugmentContainerReader, // 1.2.1
                containerWithListReader, // 2
                listInContainerReader, // 2.1
                containerInListReader, // 2.1.1
                nestedListReader}; // 2.1.1.1
    }

    @Test
    public void testReadAll() throws Exception {
        final ReadableDataTreeDelegator readableDataTreeDelegator =
                new ReadableDataTreeDelegator(serializer, schemaContext, registry, contextBroker);
        final CheckedFuture<Optional<NormalizedNode<?, ?>>, org.opendaylight.controller.md.sal.common.api.data.ReadFailedException>
                read = readableDataTreeDelegator.read(YangInstanceIdentifier.EMPTY);

        final Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> readAll =
                toBinding(read.checkedGet().get());
        assertThat(readAll.size(), is(2));
        assertTrue(readAll.containsKey(Ids.CONTAINER_WITH_LIST_ID));
        assertEquals(readContainerWithList(), readAll.get(Ids.CONTAINER_WITH_LIST_ID).stream().findFirst().get());
        assertTrue(readAll.containsKey(Ids.SIMPLE_CONTAINER_ID));
        assertEquals(readSimpleContainer(), readAll.get(Ids.SIMPLE_CONTAINER_ID).stream().findFirst().get());

        final Reader<?, ?>[] ordered = getOrderedReaders();
        final InOrder inOrder = inOrder(ordered);

        final List<ListInContainerKey> listInContainerKeys = getListInContainerIds(Ids.LIST_IN_CONTAINER_ID, ctx);

        verifyRootReader(inOrder, simpleContainerReader, Ids.SIMPLE_CONTAINER_ID, SimpleContainerBuilder.class);
        verifyLeafChildReader(inOrder, simpleAugmentReader, Ids.SIMPLE_AUGMENT_ID);
        verifyCompositeChildReader(inOrder, complexAugmentReader, ComplexAugmentBuilder.class, Ids.COMPLEX_AUGMENT_ID);
        verifyLeafChildReader(inOrder, complexAugmentContainerReader, Ids.COMPLEX_AUGMENT_CONTAINER_ID);
        verifyRootReader(inOrder, containerWithListReader, Ids.CONTAINER_WITH_LIST_ID, ContainerWithListBuilder.class);
        verifyCompositeListReader(inOrder, listInContainerReader, Ids.LIST_IN_CONTAINER_ID,
                listInContainerKeys, ListInContainerBuilder.class);

        for (ListInContainerKey k : listInContainerKeys) {
            final InstanceIdentifier<ContainerInList> id =
                    Ids.CONTAINER_WITH_LIST_ID.child(ListInContainer.class, k).child(ContainerInList.class);
            verifyCompositeChildReader(inOrder, containerInListReader, ContainerInListBuilder.class, id);
            final InstanceIdentifier<NestedList> nestedId = id.child(NestedList.class);
            verifyLeafListReader(inOrder, nestedListReader, nestedId);
        }

        for (Reader<?, ?> reader : ordered) {
            verifyNoMoreReadInteractions(reader);
        }
    }

    private <D extends DataObject, B extends Builder<D>> void verifyNoMoreReadInteractions(final Reader<D, B> reader)
            throws ReadFailedException {
        verify(reader, atLeastOnce()).getManagedDataObjectType();
        // Just mark all the isPresent calls as verified
        verify(reader, atMost(100)).isPresent(any(InstanceIdentifier.class), any(), any());
        verifyNoMoreInteractions(reader);
    }

    private <D extends DataObject, B extends Builder<D>> void verifyCompositeChildReader(final InOrder inOrder,
                                                                                         final Reader<D, B> reader,
                                                                                         final Class<B> builderCls,
                                                                                         final InstanceIdentifier<D> id)
            throws ReadFailedException {
        verifyRootReader(inOrder, reader, id, builderCls);
        verify(reader, atLeastOnce()).merge(any(Builder.class), any(id.getTargetType()));
    }

    private <D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>> void verifyCompositeListReader(
            final InOrder inOrder,
            final ListReader<D, K, B> reader,
            final InstanceIdentifier<D> id,
            final List<K> keys,
            final Class<B> builderCls)
            throws ReadFailedException {

        // Id has to be wildcarded, since it was created using InstanceIdentifier.child() method
        inOrder.verify(reader).getAllIds(eq(RWUtils.makeIidLastWildcarded(id)), any(ReadContext.class));
        keys.stream()
                .map(k -> RWUtils.replaceLastInId(id, RWUtils.getCurrentIdItem(id, k)))
                .forEach(keyedId -> {
                    try {
                        verify(reader).getBuilder(keyedId);
                        verify(reader).readCurrentAttributes(eq(keyedId), any(builderCls), any(ReadContext.class));
                    } catch (ReadFailedException e) { throw new RuntimeException(e); }
                });
        verify(reader, atLeastOnce()).merge(any(Builder.class), anyListOf(id.getTargetType()));
    }

    private <D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>> void verifyLeafListReader(
            final InOrder inOrder,
            final ListReader<D, K, B> reader,
            final InstanceIdentifier<D> id)
            throws ReadFailedException {

        // Id has to be wildcarded, since it was created using InstanceIdentifier.child() method
        inOrder.verify(reader).readList(eq(RWUtils.makeIidLastWildcarded(id)), any(ReadContext.class));
        verify(reader, atLeastOnce()).merge(any(Builder.class), anyListOf(id.getTargetType()));
    }

    private <D extends DataObject, B extends Builder<D>> void verifyRootReader(final InOrder inOrder,
                                                                               final Reader<D, B> reader,
                                                                               final InstanceIdentifier<D> id,
                                                                               final Class<B> builderCls)
            throws ReadFailedException {
        inOrder.verify(reader).readCurrentAttributes(eq(id), any(builderCls), any(ReadContext.class));
        verify(reader).getBuilder(id);
    }


    private <D extends DataObject, B extends Builder<D>> void verifyLeafChildReader(final InOrder inOrder,
                                                                                    final Reader<D, B> reader,
                                                                                    final InstanceIdentifier<D>... id)
            throws ReadFailedException {
        for (InstanceIdentifier<D> singleId : id) {
            inOrder.verify(reader).read(eq(singleId), any(ReadContext.class));
            verify(reader, atLeastOnce()).merge(any(Builder.class), any(singleId.getTargetType()));
        }
    }

    static <D extends DataObject, B extends Builder<D>> Reader<D, B> mockReader(InstanceIdentifier<D> id,
                                                                                 CurrentAttributesReader<D, B> currentAttributesReader,
                                                                                 Class<B> builderClass) {
        final Reader<D, B> reflex = new GenericReader<D, B>(id,
                new ReflexiveReaderCustomizer<>(id.getTargetType(), builderClass)) {

            @Override
            public void readCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
                                              @Nonnull final B builder,
                                              @Nonnull final ReadContext ctx)
                    throws ReadFailedException {
                currentAttributesReader.readCurrentAttributes(id, builder, ctx);
            }
        };

        // Simple spy on top of this reflexive reader cannot be used, spy also checks protected methods for invocation
        // but those cannot be verified by mockito
        final Reader<D, B> mock = mock(Reader.class);
        try {
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).read(any(InstanceIdentifier.class), any(ReadContext.class));
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).isPresent(any(InstanceIdentifier.class), any(), any());
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock)
                    .readCurrentAttributes(any(InstanceIdentifier.class), any(builderClass), any(ReadContext.class));
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).merge(any(Builder.class), any(id.getTargetType()));
            doReturn(id).when(mock).getManagedDataObjectType();
            doReturn(builderClass.newInstance()).when(mock).getBuilder(any(InstanceIdentifier.class));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return mock;
    }

    static <D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>> ListReader<D, K, B> mockListReader(
            InstanceIdentifier<D> id,
            CurrentAttributesReader<D, B> currentAttributesReader,
            ListKeysReader<D, K> listKeysReader,
            Class<B> builderClass,
            ReadContext ctx) {

        ListReader<D, K, B> reflex = new GenericListReader<>(id,
                new ReflexiveListReaderCustomizer<D, K, B>(id.getTargetType(), builderClass, listKeysReader.getAllIds(id, ctx)) {

            @Override
            public void readCurrentAttributes(final InstanceIdentifier<D> id, final B builder,
                                              final ReadContext context)
                    throws ReadFailedException {
                currentAttributesReader.readCurrentAttributes(id, builder, context);
            }
        });

        final ListReader<D, K, B> mock = mock(ListReader.class /*, withSettings().verboseLogging()*/);
        try {
            // not using eq(id) instead using any(InstanceIdentifier.class) due to InstanceIdentifier.equals weird behavior
            // with wildcarded instance identifiers for lists
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).read(any(InstanceIdentifier.class), any(ReadContext.class));
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).isPresent(any(InstanceIdentifier.class), any(), any());
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock)
                    .readCurrentAttributes(any(InstanceIdentifier.class), any(builderClass), any(ReadContext.class));
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).merge(any(Builder.class), any(id.getTargetType()));
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).merge(any(Builder.class), anyListOf(id.getTargetType()));
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).getAllIds(any(InstanceIdentifier.class), any(ReadContext.class));
            doAnswer(i -> reflexiveAnswer(reflex, i)).when(mock).readList(any(InstanceIdentifier.class), any(ReadContext.class));
            doReturn(id).when(mock).getManagedDataObjectType();
            doReturn(builderClass.newInstance()).when(mock).getBuilder(any(InstanceIdentifier.class));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return mock;
    }

    private static <D extends DataObject, B extends Builder<D>> Object reflexiveAnswer(final Reader<D, B> instance,
                                                                                final InvocationOnMock i) {
        try {
            return i.getMethod().invoke(instance, i.getArguments());
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new MockitoConfigurationException("Unable to invoke stubbed method invocation: " + i + " on " + instance);
        }
    }

    @FunctionalInterface
    interface CurrentAttributesReader<D extends DataObject, B extends Builder<D>> {
        void readCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
                                   @Nonnull final B builder,
                                   @Nonnull final ReadContext ctx);
    }

    @FunctionalInterface
    interface ListKeysReader<D extends DataObject & Identifiable<K>, K extends Identifier<D>> {
        List<K> getAllIds(@Nonnull final InstanceIdentifier<D> id,
                          @Nonnull final ReadContext ctx);
    }


    private void readSimpleContainer(final InstanceIdentifier<SimpleContainer> id,
                                     final SimpleContainerBuilder b,
                                     final ReadContext readContext) {
        b.setSimpleContainerName("simple");
    }

    private SimpleContainer readSimpleContainer() {
        final SimpleContainerBuilder b = new SimpleContainerBuilder();
        readSimpleContainer(Ids.SIMPLE_CONTAINER_ID, b, ctx);
        b.addAugmentation(SimpleAugment.class, readSimpleAugment());
        b.addAugmentation(ComplexAugment.class,
                new ComplexAugmentBuilder().setComplexAugmentContainer(readComplexAugmentContainer()).build());
        return b.build();
    }

    private void readSimpleAugment(final InstanceIdentifier<SimpleAugment> id,
                                   final SimpleAugmentBuilder b,
                                   final ReadContext readContext) {
        b.setSimpleAugmentLeaf("simple augment");
    }

    private SimpleAugment readSimpleAugment() {
        final SimpleAugmentBuilder b = new SimpleAugmentBuilder();
        readSimpleAugment(Ids.SIMPLE_AUGMENT_ID, b, ctx);
        return b.build();
    }

    private void readComplexAugmentContainer(final InstanceIdentifier<ComplexAugmentContainer> id,
                                             final ComplexAugmentContainerBuilder b,
                                             final ReadContext readContext) {
        b.setSomeLeaf("nested container in augment");
    }

    private ComplexAugmentContainer readComplexAugmentContainer() {
        final ComplexAugmentContainerBuilder b = new ComplexAugmentContainerBuilder();
        readComplexAugmentContainer(Ids.COMPLEX_AUGMENT_CONTAINER_ID, b, ctx);
        return b.build();
    }

    private ContainerWithList readContainerWithList() {
        final ContainerWithListBuilder b = new ContainerWithListBuilder();
        b.setListInContainer(readListInContainer());
        return b.build();
    }

    private List<ListInContainerKey> getListInContainerIds(final InstanceIdentifier<ListInContainer> id,
                                                           final ReadContext readContext) {
        return Lists.newArrayList(1L, 2L)
                .stream()
                .map(ListInContainerKey::new)
                .collect(Collectors.toList());
    }

    private List<NestedListKey> getNestedListIds(final InstanceIdentifier<NestedList> id,
                                                 final ReadContext readContext) {
        return Lists.newArrayList("one", "two")
                .stream()
                .map(NestedListKey::new)
                .collect(Collectors.toList());
    }

    private void readListInContainer(final InstanceIdentifier<ListInContainer> id,
                                     final ListInContainerBuilder b,
                                     final ReadContext readContext) {
        final ListInContainerKey key = id.firstKeyOf(ListInContainer.class);
        b.setId(key.getId());
        final ContainerInListBuilder cilBuilder = new ContainerInListBuilder();
        readContainerInList(id.child(ContainerInList.class), cilBuilder, readContext);
        b.setContainerInList(cilBuilder.build());
    }

    private void readNestedList(final InstanceIdentifier<NestedList> id,
                                final NestedListBuilder b,
                                final ReadContext readContext) {
        final NestedListKey key = id.firstKeyOf(NestedList.class);
        b.setNestedId(key.getNestedId());
        b.setNestedName(key.getNestedId() + "name");
    }

    private void readContainerInList(final InstanceIdentifier<ContainerInList> id,
                                     final ContainerInListBuilder b,
                                     final ReadContext readContext) {
        b.setName(id.firstKeyOf(ListInContainer.class).getId().toString());
        b.setNestedList(getNestedListIds(Ids.NESTED_LIST_ID, ctx).stream()
                .map(key -> id.child(NestedList.class, key))
                .map(nestedId -> {
                    final NestedListBuilder nestedB = new NestedListBuilder();
                    readNestedList(nestedId, nestedB, readContext);
                    return nestedB.build();
                })
                .collect(Collectors.toList()));
    }

    private List<ListInContainer> readListInContainer() {
        return getListInContainerIds(Ids.LIST_IN_CONTAINER_ID, ctx).stream()
                .map(key -> Ids.CONTAINER_WITH_LIST_ID.child(ListInContainer.class, key))
                .map(id -> {
                    final ListInContainerBuilder b = new ListInContainerBuilder();
                    readListInContainer(id, b, ctx);
                    return b.build();
                }).collect(Collectors.toList());
    }

    static <D extends DataObject, B extends Builder<D>> void noopRead(final InstanceIdentifier<D> id, final B b,
                                                                       final ReadContext readContext) {
        // NOOP
    }

}