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