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;
14 import java.util.Objects;
16 import java.util.function.Function;
17 import java.util.stream.Collectors;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
20 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
21 import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.Root;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.RootBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRoot;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRootBuilder;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
32 public class Bug3090MultiKeyList extends AbstractDataTreeChangeListenerTest {
33 private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
36 protected Set<YangModuleInfo> getModuleInfos() throws Exception {
37 return ImmutableSet.of(BindingReflections.getModuleInfo(Root.class));
41 public void listWithMultiKeyTest() {
42 final List<ListInRoot> listInRoots = new ArrayList<>();
43 for (int i = 0; i < 10; i++) {
44 listInRoots.add(new ListInRootBuilder()
45 .setLeafA("leaf a" + i)
46 .setLeafC("leaf c" + i)
47 .setLeafB("leaf b" + i)
52 final Root root = new RootBuilder().setListInRoot(listInRoots).build();
54 final TestListener<Root> listener = createListener(LogicalDatastoreType.CONFIGURATION, ROOT_PATH,
55 match(ModificationType.WRITE, ROOT_PATH, Objects::isNull,
56 (Function<Root, Boolean>) dataAfter -> checkData(root, dataAfter)));
58 final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
59 readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root);
60 assertCommit(readWriteTransaction.submit());
65 private static boolean checkData(final Root expected, final Root actual) {
70 Set<ListInRoot> expListInRoot = new HashSet<>(expected.getListInRoot());
71 Set<ListInRoot> actualListInRoot = actual.getListInRoot().stream()
72 .map(list -> new ListInRootBuilder(list).build()).collect(Collectors.toSet());
73 return expListInRoot.equals(actualListInRoot);