Removed getClass comparison if FlowComparator.
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / test / java / org / opendaylight / controller / md / sal / dom / store / impl / DefaultDataChangeListenerTestSuite.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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 package org.opendaylight.controller.md.sal.dom.store.impl;
9
10 import java.util.concurrent.ExecutionException;
11
12 import org.junit.Test;
13 import org.opendaylight.controller.md.sal.dom.store.impl.DatastoreTestTask.WriteTransactionCustomizer;
14 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
15
16 public abstract class DefaultDataChangeListenerTestSuite extends AbstractDataChangeListenerTest {
17
18     protected static final String FOO_SIBLING = "foo-sibling";
19
20     abstract protected void customizeTask(DatastoreTestTask task);
21
22     @Test
23     public final void putTopLevelOneNested() throws Exception {
24
25         DatastoreTestTask task = newTestTask().test(writeOneTopMultipleNested(FOO, BAR));
26         customizeTask(task);
27         task.run();
28         putTopLevelOneNested(task);
29     }
30
31     @Test
32     public final void existingTopWriteSibling() throws Exception {
33         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO)).test(
34                 new WriteTransactionCustomizer() {
35                     @Override
36                     public void customize(final DOMStoreReadWriteTransaction tx) {
37                         tx.write(path(FOO_SIBLING), topLevelList(FOO_SIBLING).build());
38                     }
39                 });
40         customizeTask(task);
41         task.run();
42         existingTopWriteSibling(task);
43     }
44
45     protected abstract void existingTopWriteSibling(DatastoreTestTask task) throws InterruptedException, ExecutionException;
46
47
48     @Test
49     public final void existingTopWriteTwoNested() throws Exception {
50         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO)).test(
51                 new WriteTransactionCustomizer() {
52                     @Override
53                     public void customize(final DOMStoreReadWriteTransaction tx) {
54                         tx.write(path(FOO,BAR), nestedList(BAR).build());
55                         tx.write(path(FOO,BAZ), nestedList(BAZ).build());
56                     }
57                 });
58         customizeTask(task);
59         task.run();
60         existingTopWriteTwoNested(task);
61     }
62
63     protected abstract void existingTopWriteTwoNested(DatastoreTestTask task) throws InterruptedException, ExecutionException;
64
65
66     @Test
67     public final void existingOneNestedWriteAdditionalNested() throws Exception {
68         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR)).test(
69                 new WriteTransactionCustomizer() {
70                     @Override
71                     public void customize(final DOMStoreReadWriteTransaction tx) {
72                         tx.write(path(FOO,BAZ), nestedList(BAZ).build());
73                     }
74                 });
75         customizeTask(task);
76         task.run();
77         existingOneNestedWriteAdditionalNested(task);
78     }
79
80     protected abstract void existingOneNestedWriteAdditionalNested(DatastoreTestTask task) throws InterruptedException, ExecutionException;
81
82     protected abstract void putTopLevelOneNested(DatastoreTestTask task) throws Exception;
83
84     @Test
85     public final void replaceTopLevelNestedChanged() throws Exception {
86         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR)).test(
87                 writeOneTopMultipleNested(FOO, BAZ));
88         customizeTask(task);
89         task.run();
90         replaceTopLevelNestedChanged(task);
91     }
92
93     protected abstract void replaceTopLevelNestedChanged(DatastoreTestTask task) throws InterruptedException,
94             ExecutionException;
95
96     @Test
97     public final void putTopLevelWithTwoNested() throws Exception {
98
99         DatastoreTestTask task = newTestTask().test(writeOneTopMultipleNested(FOO, BAR, BAZ));
100         customizeTask(task);
101         task.run();
102         putTopLevelWithTwoNested(task);
103     }
104
105     protected abstract void putTopLevelWithTwoNested(DatastoreTestTask task) throws InterruptedException,
106             ExecutionException;
107
108     @Test
109     public final void twoNestedExistsOneIsDeleted() throws Exception {
110
111         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR, BAZ)).test(
112                 deleteNested(FOO, BAZ));
113         customizeTask(task);
114         task.run();
115         twoNestedExistsOneIsDeleted(task);
116     }
117
118     protected abstract void twoNestedExistsOneIsDeleted(DatastoreTestTask task) throws InterruptedException,
119             ExecutionException;
120
121     @Test
122     public final void nestedListExistsRootDeleted() throws Exception {
123
124         DatastoreTestTask task = newTestTask().cleanup(null).setup(writeOneTopMultipleNested(FOO, BAR, BAZ))
125                 .test(DatastoreTestTask.simpleDelete(TOP_LEVEL));
126         customizeTask(task);
127         task.run();
128         nestedListExistsRootDeleted(task);
129     }
130
131     protected abstract void nestedListExistsRootDeleted(DatastoreTestTask task) throws InterruptedException,
132             ExecutionException;
133 }