Use moved BindingReflections
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / 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.controller.md.sal.binding.impl.test;
9
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.Set;
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.mdsal.binding.spec.reflect.BindingReflections;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.Root;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.RootBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRoot;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRootBuilder;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
29
30 public class Bug3090MultiKeyList extends AbstractDataTreeChangeListenerTest {
31     private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
32
33     @Override
34     protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
35         return ImmutableSet.of(BindingReflections.getModuleInfo(Root.class));
36     }
37
38     @Test
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)
46                 .build()
47             );
48         }
49
50         final Root root = new RootBuilder().setListInRoot(listInRoots).build();
51
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)));
55
56         final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
57         readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root);
58         assertCommit(readWriteTransaction.submit());
59
60         listener.verify();
61     }
62
63     private boolean checkData(Root expected, Root actual) {
64         if (actual == null) {
65             return false;
66         }
67
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);
72     }
73 }