Deprecate all MD-SAL APIs
[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.Objects;
15 import java.util.Set;
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;
30
31 @Deprecated
32 public class Bug3090MultiKeyList extends AbstractDataTreeChangeListenerTest {
33     private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
34
35     @Override
36     protected Set<YangModuleInfo> getModuleInfos() throws Exception {
37         return ImmutableSet.of(BindingReflections.getModuleInfo(Root.class));
38     }
39
40     @Test
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)
48                 .build()
49             );
50         }
51
52         final Root root = new RootBuilder().setListInRoot(listInRoots).build();
53
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)));
57
58         final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
59         readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root);
60         assertCommit(readWriteTransaction.submit());
61
62         listener.verify();
63     }
64
65     private static boolean checkData(final Root expected, final Root actual) {
66         if (actual == null) {
67             return false;
68         }
69
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);
74     }
75 }