manually cherry pick this patch https://git.opendaylight.org/gerrit/#/c/34579/
[unimgr.git] / impl / src / test / java / org / opendaylight / unimgr / impl / UniDataTreeChangeListenerTest.java
1 /*
2  * Copyright (c) 2016 CableLabs 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
9 package org.opendaylight.unimgr.impl;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15
16 import java.util.ArrayList;
17 import java.util.Collection;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.Mockito;
23 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
24 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
25 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
26 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
28 import org.opendaylight.yangtools.yang.binding.Augmentation;
29 import org.opendaylight.yangtools.yang.binding.ChildOf;
30 import org.opendaylight.yangtools.yang.binding.DataObject;
31 import org.opendaylight.yangtools.yang.binding.Identifiable;
32 import org.opendaylight.yangtools.yang.binding.Identifier;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
34 import org.powermock.modules.junit4.PowerMockRunner;
35
36
37 @RunWith(PowerMockRunner.class)
38 public class UniDataTreeChangeListenerTest {
39
40     private UniDataTreeChangeListener uniDataTreeChangeListener;
41
42     @Before
43     public void setUp() throws Exception {
44         uniDataTreeChangeListener = mock(UniDataTreeChangeListener.class, Mockito.CALLS_REAL_METHODS);
45     }
46
47     @SuppressWarnings("unchecked")
48     @Test
49     public void testUnimgrDataTreeChangeListener() {
50         Collection<DataTreeModification<Node>> collection = new ArrayList<DataTreeModification<Node>>();
51         DataTreeModification<Node> uni = getDataTreeNode(ModificationType.WRITE);
52         collection.add(uni);
53         uni = getDataTreeNode(ModificationType.DELETE);
54         collection.add(uni);
55         uni = getDataTreeNode(ModificationType.SUBTREE_MODIFIED);
56         collection.add(uni);
57         uniDataTreeChangeListener.onDataTreeChanged(collection);
58         verify(uniDataTreeChangeListener, times(1)).add(any(DataTreeModification.class));
59         verify(uniDataTreeChangeListener, times(1)).remove(any(DataTreeModification.class));
60         verify(uniDataTreeChangeListener, times(1)).update(any(DataTreeModification.class));
61     }
62
63     private DataTreeModification<Node> getDataTreeNode(final ModificationType modificationType) {
64         final DataObjectModification<Node> uniDataObjModification = new DataObjectModification<Node>() {
65             @Override
66             public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
67                 // TODO Auto-generated method stub
68                 return null;
69             }
70             @Override
71             public <C extends Identifiable<K> & ChildOf<? super Node>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
72                     Class<C> arg0, K arg1) {
73                 // TODO Auto-generated method stub
74                 return null;
75             }
76             @Override
77             public <C extends ChildOf<? super Node>> DataObjectModification<C> getModifiedChildContainer(Class<C> arg0) {
78                 // TODO Auto-generated method stub
79                 return null;
80             }
81             @Override
82             public DataObjectModification<? extends DataObject> getModifiedChild(PathArgument arg0) {
83                 // TODO Auto-generated method stub
84                 return null;
85             }
86             @Override
87             public <C extends Augmentation<Node> & DataObject> DataObjectModification<C> getModifiedAugmentation(
88                     Class<C> arg0) {
89                 // TODO Auto-generated method stub
90                 return null;
91             }
92             @Override
93             public ModificationType getModificationType() {
94                 return modificationType;
95             }
96             @Override
97             public PathArgument getIdentifier() {
98                 // TODO Auto-generated method stub
99                 return null;
100             }
101             @Override
102             public Class<Node> getDataType() {
103                 // TODO Auto-generated method stub
104                 return null;
105             }
106             @Override
107             public Node getDataBefore() {
108                 // TODO Auto-generated method stub
109                 return null;
110             }
111             @Override
112             public Node getDataAfter() {
113                 // TODO Auto-generated method stub
114                 return null;
115             }
116         };
117         DataTreeModification<Node> modifiedUni = new DataTreeModification<Node>() {
118             @Override
119             public DataTreeIdentifier<Node> getRootPath() {
120                 return null;
121             }
122             @Override
123             public DataObjectModification<Node> getRootNode() {
124                 return uniDataObjModification;
125             }
126         };
127         return modifiedUni;
128     }
129 }