manually cherry pick this patch https://git.opendaylight.org/gerrit/#/c/34579/
[unimgr.git] / impl / src / test / java / org / opendaylight / unimgr / impl / EvcDataTreeChangeListenerTest.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.Link;
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 @RunWith(PowerMockRunner.class)
37 public class EvcDataTreeChangeListenerTest {
38
39     private EvcDataTreeChangeListener evcDataTreeChangeListener;
40
41     @Before
42     public void setUp() throws Exception {
43         evcDataTreeChangeListener = mock(EvcDataTreeChangeListener.class, Mockito.CALLS_REAL_METHODS);
44     }
45
46     @SuppressWarnings("unchecked")
47     @Test
48     public void testEvcmgrDataTreeChangeListener() {
49         Collection<DataTreeModification<Link>> collection = new ArrayList<DataTreeModification<Link>>();
50         DataTreeModification<Link> evc = getDataTreeLink(ModificationType.WRITE);
51         collection.add(evc);
52         evc = getDataTreeLink(ModificationType.DELETE);
53         collection.add(evc);
54         evc = getDataTreeLink(ModificationType.SUBTREE_MODIFIED);
55         collection.add(evc);
56         evcDataTreeChangeListener.onDataTreeChanged(collection);
57         verify(evcDataTreeChangeListener, times(1)).add(any(DataTreeModification.class));
58         verify(evcDataTreeChangeListener, times(1)).remove(any(DataTreeModification.class));
59         verify(evcDataTreeChangeListener, times(1)).update(any(DataTreeModification.class));
60     }
61
62     private DataTreeModification<Link> getDataTreeLink(final ModificationType modificationType) {
63         final DataObjectModification<Link> evcDataObjModification = new DataObjectModification<Link>() {
64             @Override
65             public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
66                 // TODO Auto-generated method stub
67                 return null;
68             }
69             @Override
70             public <C extends Identifiable<K> & ChildOf<? super Link>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
71                     Class<C> arg0, K arg1) {
72                 // TODO Auto-generated method stub
73                 return null;
74             }
75             @Override
76             public <C extends ChildOf<? super Link>> DataObjectModification<C> getModifiedChildContainer(Class<C> arg0) {
77                 // TODO Auto-generated method stub
78                 return null;
79             }
80             @Override
81             public DataObjectModification<? extends DataObject> getModifiedChild(PathArgument arg0) {
82                 // TODO Auto-generated method stub
83                 return null;
84             }
85             @Override
86             public <C extends Augmentation<Link> & DataObject> DataObjectModification<C> getModifiedAugmentation(
87                     Class<C> arg0) {
88                 // TODO Auto-generated method stub
89                 return null;
90             }
91             @Override
92             public ModificationType getModificationType() {
93                 return modificationType;
94             }
95             @Override
96             public PathArgument getIdentifier() {
97                 // TODO Auto-generated method stub
98                 return null;
99             }
100             @Override
101             public Class<Link> getDataType() {
102                 // TODO Auto-generated method stub
103                 return null;
104             }
105             @Override
106             public Link getDataBefore() {
107                 // TODO Auto-generated method stub
108                 return null;
109             }
110             @Override
111             public Link getDataAfter() {
112                 // TODO Auto-generated method stub
113                 return null;
114             }
115         };
116         DataTreeModification<Link> modifiedEvc = new DataTreeModification<Link>() {
117             @Override
118             public DataTreeIdentifier<Link> getRootPath() {
119                 return null;
120             }
121             @Override
122             public DataObjectModification<Link> getRootNode() {
123                 return evcDataObjModification;
124             }
125         };
126         return modifiedEvc;
127     }
128
129 }