Merge "Fixed possible NPE in flow reconciliation"
[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 /**
17  * Base template for a test suite for testing DataChangeListener functionality.
18  */
19 public abstract class DefaultDataChangeListenerTestSuite extends AbstractDataChangeListenerTest {
20
21     protected static final String FOO_SIBLING = "foo-sibling";
22
23     /**
24      * Callback invoked when the test suite can modify task parameters.
25      *
26      * @param task Update task configuration as needed
27      */
28     abstract protected void customizeTask(DatastoreTestTask task);
29
30     @Test
31     public final void putTopLevelOneNested() throws Exception {
32
33         DatastoreTestTask task = newTestTask().test(writeOneTopMultipleNested(FOO, BAR));
34         customizeTask(task);
35         task.run();
36         putTopLevelOneNested(task);
37     }
38
39     @Test
40     public final void existingTopWriteSibling() throws Exception {
41         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO)).test(
42                 new WriteTransactionCustomizer() {
43                     @Override
44                     public void customize(final DOMStoreReadWriteTransaction tx) {
45                         tx.write(path(FOO_SIBLING), topLevelList(FOO_SIBLING).build());
46                     }
47                 });
48         customizeTask(task);
49         task.run();
50         existingTopWriteSibling(task);
51     }
52
53     protected abstract void existingTopWriteSibling(DatastoreTestTask task) throws InterruptedException, ExecutionException;
54
55
56     @Test
57     public final void existingTopWriteTwoNested() throws Exception {
58         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO)).test(
59                 new WriteTransactionCustomizer() {
60                     @Override
61                     public void customize(final DOMStoreReadWriteTransaction tx) {
62                         tx.write(path(FOO,BAR), nestedList(BAR).build());
63                         tx.write(path(FOO,BAZ), nestedList(BAZ).build());
64                     }
65                 });
66         customizeTask(task);
67         task.run();
68         existingTopWriteTwoNested(task);
69     }
70
71     protected abstract void existingTopWriteTwoNested(DatastoreTestTask task) throws InterruptedException, ExecutionException;
72
73
74     @Test
75     public final void existingOneNestedWriteAdditionalNested() throws Exception {
76         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR)).test(
77                 new WriteTransactionCustomizer() {
78                     @Override
79                     public void customize(final DOMStoreReadWriteTransaction tx) {
80                         tx.write(path(FOO,BAZ), nestedList(BAZ).build());
81                     }
82                 });
83         customizeTask(task);
84         task.run();
85         existingOneNestedWriteAdditionalNested(task);
86     }
87
88     protected abstract void existingOneNestedWriteAdditionalNested(DatastoreTestTask task) throws InterruptedException, ExecutionException;
89
90     protected abstract void putTopLevelOneNested(DatastoreTestTask task) throws Exception;
91
92     @Test
93     public final void replaceTopLevelNestedChanged() throws Exception {
94         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR)).test(
95                 writeOneTopMultipleNested(FOO, BAZ));
96         customizeTask(task);
97         task.run();
98         replaceTopLevelNestedChanged(task);
99     }
100
101     protected abstract void replaceTopLevelNestedChanged(DatastoreTestTask task) throws InterruptedException,
102             ExecutionException;
103
104     @Test
105     public final void putTopLevelWithTwoNested() throws Exception {
106
107         DatastoreTestTask task = newTestTask().test(writeOneTopMultipleNested(FOO, BAR, BAZ));
108         customizeTask(task);
109         task.run();
110         putTopLevelWithTwoNested(task);
111     }
112
113     protected abstract void putTopLevelWithTwoNested(DatastoreTestTask task) throws InterruptedException,
114             ExecutionException;
115
116     @Test
117     public final void twoNestedExistsOneIsDeleted() throws Exception {
118
119         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR, BAZ)).test(
120                 deleteNested(FOO, BAZ));
121         customizeTask(task);
122         task.run();
123         twoNestedExistsOneIsDeleted(task);
124     }
125
126     protected abstract void twoNestedExistsOneIsDeleted(DatastoreTestTask task) throws InterruptedException,
127             ExecutionException;
128
129     @Test
130     public final void nestedListExistsRootDeleted() throws Exception {
131
132         DatastoreTestTask task = newTestTask().cleanup(null).setup(writeOneTopMultipleNested(FOO, BAR, BAZ))
133                 .test(DatastoreTestTask.simpleDelete(TOP_LEVEL));
134         customizeTask(task);
135         task.run();
136         nestedListExistsRootDeleted(task);
137     }
138
139     protected abstract void nestedListExistsRootDeleted(DatastoreTestTask task) throws InterruptedException,
140             ExecutionException;
141 }