2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;
\r
10 import static org.mockito.Mockito.mock;
\r
11 import static org.mockito.Mockito.spy;
\r
12 import static org.mockito.Mockito.when;
\r
14 import java.util.Set;
\r
16 import com.google.common.collect.ImmutableSet;
\r
17 import org.junit.Before;
\r
18 import org.junit.Test;
\r
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
\r
20 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
\r
21 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
\r
22 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
\r
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
\r
24 import org.opendaylight.groupbasedpolicy.util.IidFactory;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
\r
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
\r
28 public class EndpointListenerCovrgTest {
\r
30 private EndpointListener listener;
\r
31 private DataObjectModification<EndpointL3> rootNode;
\r
32 private Set<DataTreeModification<EndpointL3>> changes;
\r
34 private InstanceIdentifier<EndpointL3> rootIdentifier;
\r
36 @SuppressWarnings("unchecked")
\r
38 public void init() {
\r
39 DataBroker dataProvider = mock(DataBroker.class);
\r
41 EndpointManager endpointManager = mock(EndpointManager.class);
\r
42 listener = spy(new EndpointListener(dataProvider, endpointManager));
\r
44 EndpointL3 endpointL3 = mock(EndpointL3.class);
\r
46 rootNode = mock(DataObjectModification.class);
\r
47 rootIdentifier = IidFactory.l3EndpointsIidWildcard();
\r
48 DataTreeIdentifier<EndpointL3> rootPath =
\r
49 new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, rootIdentifier);
\r
51 DataTreeModification<EndpointL3> change = mock(DataTreeModification.class);
\r
53 when(change.getRootNode()).thenReturn(rootNode);
\r
54 when(change.getRootPath()).thenReturn(rootPath);
\r
56 changes = ImmutableSet.of(change);
\r
58 when(rootNode.getDataBefore()).thenReturn(endpointL3);
\r
59 when(rootNode.getDataAfter()).thenReturn(endpointL3);
\r
63 public void testOnWrite() {
\r
64 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
\r
66 listener.onDataTreeChanged(changes);
\r
69 @Test(expected = UnsupportedOperationException.class)
\r
70 public void testOnDelete() {
\r
71 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
\r
73 listener.onDataTreeChanged(changes);
\r
77 public void testOnSubtreeModified() {
\r
78 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
\r
80 listener.onDataTreeChanged(changes);
\r