Hide BindingReflections.getModuleInfo()
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / Bug3090MultiKeyList.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.binding.dom.adapter;
9
10 import java.util.ArrayList;
11 import java.util.HashSet;
12 import java.util.Objects;
13 import java.util.Set;
14 import java.util.stream.Collectors;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
17 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest;
18 import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
19 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.Root;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.RootBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRoot;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRootBuilder;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
26 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
27
28 public class Bug3090MultiKeyList extends AbstractDataTreeChangeListenerTest {
29     private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
30
31     @Override
32     protected Set<YangModuleInfo> getModuleInfos() throws Exception {
33         return Set.of(BindingRuntimeHelpers.getYangModuleInfo(Root.class));
34     }
35
36     @Test
37     public void listWithMultiKeyTest() {
38         final var listInRoots = new ArrayList<ListInRoot>();
39         for (int i = 0; i < 10; i++) {
40             listInRoots.add(new ListInRootBuilder()
41                 .setLeafA("leaf a" + i)
42                 .setLeafC("leaf c" + i)
43                 .setLeafB("leaf b" + i)
44                 .build()
45             );
46         }
47
48         final var root = new RootBuilder().setListInRoot(BindingMap.of(listInRoots)).build();
49
50         try (var collector = createCollector(LogicalDatastoreType.CONFIGURATION, ROOT_PATH)) {
51             collector.verifyModifications();
52
53             final var readWriteTransaction = getDataBroker().newReadWriteTransaction();
54             readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root);
55             assertCommit(readWriteTransaction.commit());
56
57             collector.verifyModifications(match(ModificationType.WRITE, ROOT_PATH, Objects::isNull,
58                 (DataMatcher<Root>) dataAfter -> checkData(root, dataAfter)));
59         }
60     }
61
62     private static boolean checkData(final Root expected, final Root actual) {
63         if (actual == null) {
64             return false;
65         }
66
67         var expListInRoot = new HashSet<>(expected.nonnullListInRoot().values());
68         var actualListInRoot = actual.nonnullListInRoot().values().stream()
69                 .map(list -> new ListInRootBuilder(list).build()).collect(Collectors.toSet());
70         return expListInRoot.equals(actualListInRoot);
71     }
72 }