2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.impl.test;
10 import com.google.common.collect.ImmutableSet;
11 import java.util.ArrayList;
12 import java.util.HashSet;
13 import java.util.List;
15 import java.util.function.Function;
16 import java.util.stream.Collectors;
17 import org.junit.Test;
18 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
19 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
20 import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.Root;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.RootBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRoot;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRootBuilder;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
28 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
30 public class Bug3090MultiKeyList extends AbstractDataTreeChangeListenerTest {
31 private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
34 protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
35 return ImmutableSet.of(BindingReflections.getModuleInfo(Root.class));
39 public void listWithMultiKeyTest() {
40 final List<ListInRoot> listInRoots = new ArrayList<>();
41 for (int i = 0; i < 10; i++) {
42 listInRoots.add(new ListInRootBuilder()
43 .setLeafA("leaf a" + i)
44 .setLeafC("leaf c" + i)
45 .setLeafB("leaf b" + i)
50 final Root root = new RootBuilder().setListInRoot(listInRoots).build();
52 final TestListener<Root> listener = createListener(LogicalDatastoreType.CONFIGURATION, ROOT_PATH,
53 match(ModificationType.WRITE, ROOT_PATH, dataBefore -> dataBefore == null,
54 (Function<Root, Boolean>) dataAfter -> checkData(root, dataAfter)));
56 final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
57 readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root);
58 assertCommit(readWriteTransaction.submit());
63 private boolean checkData(Root expected, Root actual) {
68 Set<ListInRoot> expListInRoot = new HashSet<>(expected.getListInRoot());
69 Set<ListInRoot> actualListInRoot = actual.getListInRoot().stream()
70 .map(list -> new ListInRootBuilder(list).build()).collect(Collectors.toSet());
71 return expListInRoot.equals(actualListInRoot);