Merge "Improve documentation of BindingAware{Provider,Consumer}"
[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 InterruptedException, ExecutionException {
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 InterruptedException, ExecutionException {
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 InterruptedException, ExecutionException {
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 InterruptedException, ExecutionException {
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 InterruptedException,
83             ExecutionException;
84
85     @Test
86     public final void replaceTopLevelNestedChanged() throws InterruptedException, ExecutionException {
87         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR)).test(
88                 writeOneTopMultipleNested(FOO, BAZ));
89         customizeTask(task);
90         task.run();
91         replaceTopLevelNestedChanged(task);
92     }
93
94     protected abstract void replaceTopLevelNestedChanged(DatastoreTestTask task) throws InterruptedException,
95             ExecutionException;
96
97     @Test
98     public final void putTopLevelWithTwoNested() throws InterruptedException, ExecutionException {
99
100         DatastoreTestTask task = newTestTask().test(writeOneTopMultipleNested(FOO, BAR, BAZ));
101         customizeTask(task);
102         task.run();
103         putTopLevelWithTwoNested(task);
104     }
105
106     protected abstract void putTopLevelWithTwoNested(DatastoreTestTask task) throws InterruptedException,
107             ExecutionException;
108
109     @Test
110     public final void twoNestedExistsOneIsDeleted() throws InterruptedException, ExecutionException {
111
112         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR, BAZ)).test(
113                 deleteNested(FOO, BAZ));
114         customizeTask(task);
115         task.run();
116         twoNestedExistsOneIsDeleted(task);
117     }
118
119     protected abstract void twoNestedExistsOneIsDeleted(DatastoreTestTask task) throws InterruptedException,
120             ExecutionException;
121
122     @Test
123     public final void nestedListExistsRootDeleted() throws InterruptedException, ExecutionException {
124
125         DatastoreTestTask task = newTestTask().cleanup(null).setup(writeOneTopMultipleNested(FOO, BAR, BAZ))
126                 .test(DatastoreTestTask.simpleDelete(TOP_LEVEL));
127         customizeTask(task);
128         task.run();
129         nestedListExistsRootDeleted(task);
130     }
131
132     protected abstract void nestedListExistsRootDeleted(DatastoreTestTask task) throws InterruptedException,
133             ExecutionException;
134 }