2 * Copyright (c) 2016 CableLabs 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
9 package org.opendaylight.unimgr.impl;
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;
16 import java.util.ArrayList;
17 import java.util.Collection;
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;
37 @RunWith(PowerMockRunner.class)
38 public class UniDataTreeChangeListenerTest {
40 private UniDataTreeChangeListener uniDataTreeChangeListener;
43 public void setUp() throws Exception {
44 uniDataTreeChangeListener = mock(UniDataTreeChangeListener.class, Mockito.CALLS_REAL_METHODS);
47 @SuppressWarnings("unchecked")
49 public void testUnimgrDataTreeChangeListener() {
50 Collection<DataTreeModification<Node>> collection = new ArrayList<DataTreeModification<Node>>();
51 DataTreeModification<Node> uni = getDataTreeNode(ModificationType.WRITE);
53 uni = getDataTreeNode(ModificationType.DELETE);
55 uni = getDataTreeNode(ModificationType.SUBTREE_MODIFIED);
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));
63 private DataTreeModification<Node> getDataTreeNode(final ModificationType modificationType) {
64 final DataObjectModification<Node> uniDataObjModification = new DataObjectModification<Node>() {
66 public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
67 // TODO Auto-generated method stub
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
77 public <C extends ChildOf<? super Node>> DataObjectModification<C> getModifiedChildContainer(Class<C> arg0) {
78 // TODO Auto-generated method stub
82 public DataObjectModification<? extends DataObject> getModifiedChild(PathArgument arg0) {
83 // TODO Auto-generated method stub
87 public <C extends Augmentation<Node> & DataObject> DataObjectModification<C> getModifiedAugmentation(
89 // TODO Auto-generated method stub
93 public ModificationType getModificationType() {
94 return modificationType;
97 public PathArgument getIdentifier() {
98 // TODO Auto-generated method stub
102 public Class<Node> getDataType() {
103 // TODO Auto-generated method stub
107 public Node getDataBefore() {
108 // TODO Auto-generated method stub
112 public Node getDataAfter() {
113 // TODO Auto-generated method stub
117 DataTreeModification<Node> modifiedUni = new DataTreeModification<Node>() {
119 public DataTreeIdentifier<Node> getRootPath() {
123 public DataObjectModification<Node> getRootNode() {
124 return uniDataObjModification;