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.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;
36 @RunWith(PowerMockRunner.class)
37 public class EvcDataTreeChangeListenerTest {
39 private EvcDataTreeChangeListener evcDataTreeChangeListener;
42 public void setUp() throws Exception {
43 evcDataTreeChangeListener = mock(EvcDataTreeChangeListener.class, Mockito.CALLS_REAL_METHODS);
46 @SuppressWarnings("unchecked")
48 public void testEvcmgrDataTreeChangeListener() {
49 Collection<DataTreeModification<Link>> collection = new ArrayList<DataTreeModification<Link>>();
50 DataTreeModification<Link> evc = getDataTreeLink(ModificationType.WRITE);
52 evc = getDataTreeLink(ModificationType.DELETE);
54 evc = getDataTreeLink(ModificationType.SUBTREE_MODIFIED);
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));
62 private DataTreeModification<Link> getDataTreeLink(final ModificationType modificationType) {
63 final DataObjectModification<Link> evcDataObjModification = new DataObjectModification<Link>() {
65 public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
66 // TODO Auto-generated method stub
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
76 public <C extends ChildOf<? super Link>> DataObjectModification<C> getModifiedChildContainer(Class<C> arg0) {
77 // TODO Auto-generated method stub
81 public DataObjectModification<? extends DataObject> getModifiedChild(PathArgument arg0) {
82 // TODO Auto-generated method stub
86 public <C extends Augmentation<Link> & DataObject> DataObjectModification<C> getModifiedAugmentation(
88 // TODO Auto-generated method stub
92 public ModificationType getModificationType() {
93 return modificationType;
96 public PathArgument getIdentifier() {
97 // TODO Auto-generated method stub
101 public Class<Link> getDataType() {
102 // TODO Auto-generated method stub
106 public Link getDataBefore() {
107 // TODO Auto-generated method stub
111 public Link getDataAfter() {
112 // TODO Auto-generated method stub
116 DataTreeModification<Link> modifiedEvc = new DataTreeModification<Link>() {
118 public DataTreeIdentifier<Link> getRootPath() {
122 public DataObjectModification<Link> getRootNode() {
123 return evcDataObjModification;