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;
31 public class Bug3090MultiKeyList extends AbstractDataTreeChangeListenerTest {
32 private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
35 protected Set<YangModuleInfo> getModuleInfos() throws Exception {
36 return ImmutableSet.of(BindingReflections.getModuleInfo(Root.class));
40 public void listWithMultiKeyTest() {
41 final List<ListInRoot> listInRoots = new ArrayList<>();
42 for (int i = 0; i < 10; i++) {
43 listInRoots.add(new ListInRootBuilder()
44 .setLeafA("leaf a" + i)
45 .setLeafC("leaf c" + i)
46 .setLeafB("leaf b" + i)
51 final Root root = new RootBuilder().setListInRoot(listInRoots).build();
53 final TestListener<Root> listener = createListener(LogicalDatastoreType.CONFIGURATION, ROOT_PATH,
54 match(ModificationType.WRITE, ROOT_PATH, Objects::isNull,
55 (Function<Root, Boolean>) dataAfter -> checkData(root, dataAfter)));
57 final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
58 readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root);
59 assertCommit(readWriteTransaction.submit());
64 private static boolean checkData(final Root expected, final Root actual) {
69 Set<ListInRoot> expListInRoot = new HashSet<>(expected.getListInRoot());
70 Set<ListInRoot> actualListInRoot = actual.getListInRoot().stream()
71 .map(list -> new ListInRootBuilder(list).build()).collect(Collectors.toSet());
72 return expListInRoot.equals(actualListInRoot);