Add missing license headers
[groupbasedpolicy.git] / renderers / iovisor / src / test / java / org / opendaylight / groupbasedpolicy / renderer / iovisor / endpoint / EndpointListenerCovrgTest.java
1 /*\r
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\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
7  */\r
8 package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;\r
9 \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
13 \r
14 import java.util.Set;\r
15 \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
27 \r
28 public class EndpointListenerCovrgTest {\r
29 \r
30     private EndpointListener listener;\r
31     private DataObjectModification<EndpointL3> rootNode;\r
32     private Set<DataTreeModification<EndpointL3>> changes;\r
33 \r
34     private InstanceIdentifier<EndpointL3> rootIdentifier;\r
35 \r
36     @SuppressWarnings("unchecked")\r
37     @Before\r
38     public void init() {\r
39         DataBroker dataProvider = mock(DataBroker.class);\r
40 \r
41         EndpointManager endpointManager = mock(EndpointManager.class);\r
42         listener = spy(new EndpointListener(dataProvider, endpointManager));\r
43 \r
44         EndpointL3 endpointL3 = mock(EndpointL3.class);\r
45 \r
46         rootNode = mock(DataObjectModification.class);\r
47         rootIdentifier = IidFactory.l3EndpointsIidWildcard();\r
48         DataTreeIdentifier<EndpointL3> rootPath =\r
49                 new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, rootIdentifier);\r
50 \r
51         DataTreeModification<EndpointL3> change = mock(DataTreeModification.class);\r
52 \r
53         when(change.getRootNode()).thenReturn(rootNode);\r
54         when(change.getRootPath()).thenReturn(rootPath);\r
55 \r
56         changes = ImmutableSet.of(change);\r
57 \r
58         when(rootNode.getDataBefore()).thenReturn(endpointL3);\r
59         when(rootNode.getDataAfter()).thenReturn(endpointL3);\r
60     }\r
61 \r
62     @Test\r
63     public void testOnWrite() {\r
64         when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
65 \r
66         listener.onDataTreeChanged(changes);\r
67     }\r
68 \r
69     @Test(expected = UnsupportedOperationException.class)\r
70     public void testOnDelete() {\r
71         when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
72 \r
73         listener.onDataTreeChanged(changes);\r
74     }\r
75 \r
76     @Test\r
77     public void testOnSubtreeModified() {\r
78         when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
79 \r
80         listener.onDataTreeChanged(changes);\r
81     }\r
82 \r
83 }\r