1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.store; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Test; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
@version |
29 |
|
@since |
30 |
|
|
|
|
| 57.1% |
Uncovered Elements: 6 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
31 |
|
public class ProvidingTransactionRunnableTest |
32 |
|
{ |
33 |
|
private static final String DB_CONNECTION = "Hello, I'm a database connection!"; |
34 |
|
|
35 |
|
private static final String DATA_A1 = "hello world"; |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
37 |
1 |
@Test... |
38 |
|
public void dataSharingTest() throws Exception |
39 |
|
{ |
40 |
1 |
DBStartableTransactionRunnable run = new DBStartableTransactionRunnable(); |
41 |
1 |
ProvidingTransactionRunnable<DBTransaction, MyInterfaceWithDataA1> tr1 = new TR1(); |
42 |
1 |
tr1.runIn(run); |
43 |
1 |
TransactionRunnable<DBTransaction> tr2 = new TR2(); |
44 |
1 |
TransactionRunnable<MyInterfaceWithDataA1> tr2WithNewCapabilities = tr2.runIn(tr1.asProvider()); |
45 |
|
|
46 |
1 |
new TR3().runIn(tr2WithNewCapabilities); |
47 |
|
|
48 |
1 |
run.start(); |
49 |
|
} |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
51 |
0 |
public void providingTest() throws Exception... |
52 |
|
{ |
53 |
0 |
DBStartableTransactionRunnable run = new DBStartableTransactionRunnable(); |
54 |
0 |
ProvidingTransactionRunnable<DBTransaction, MyInterfaceWithDataA1> tr1 = new TR1(); |
55 |
0 |
tr1.runIn(run); |
56 |
0 |
new TR3().runIn(tr1.asProvider()); |
57 |
0 |
run.start(); |
58 |
|
} |
59 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
60 |
|
public static interface DBTransaction |
61 |
|
{ |
62 |
|
String getConnection(); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
|
public static class MyDBTransaction implements DBTransaction |
66 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
3 |
public String getConnection()... |
68 |
|
{ |
69 |
3 |
return DB_CONNECTION; |
70 |
|
} |
71 |
|
} |
72 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
73 |
|
public static interface MyInterfaceWithDataA1 extends DBTransaction |
74 |
|
{ |
75 |
|
String getDataA1(); |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.75 |
|
78 |
|
public static class ImplementationWithDataA1 implements MyInterfaceWithDataA1 |
79 |
|
{ |
80 |
|
private final DBTransaction DBTrans; |
81 |
|
|
82 |
|
private final String dataA1; |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
84 |
3 |
public ImplementationWithDataA1(final DBTransaction transact, final String dataA1)... |
85 |
|
{ |
86 |
3 |
this.DBTrans = transact; |
87 |
3 |
this.dataA1 = dataA1; |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
1 |
public String getDataA1()... |
91 |
|
{ |
92 |
1 |
return this.dataA1; |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
2 |
public String getConnection()... |
96 |
|
{ |
97 |
2 |
return this.DBTrans.getConnection(); |
98 |
|
} |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
|
public static class DBStartableTransactionRunnable extends StartableTransactionRunnable<DBTransaction> |
102 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
4 |
@Override... |
104 |
|
protected DBTransaction getProvidedContext() |
105 |
|
{ |
106 |
4 |
return new MyDBTransaction(); |
107 |
|
} |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
110 |
|
public static class TR1 extends ProvidingTransactionRunnable<DBTransaction, MyInterfaceWithDataA1> |
111 |
|
{ |
112 |
|
private String dataA1; |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
114 |
1 |
@Override... |
115 |
|
protected void onRun() |
116 |
|
{ |
117 |
1 |
Assert.assertEquals("DB Connection was not correct in TR1", |
118 |
|
DB_CONNECTION, this.getContext().getConnection()); |
119 |
1 |
this.dataA1 = DATA_A1; |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
3 |
@Override... |
123 |
|
protected MyInterfaceWithDataA1 getProvidedContext() |
124 |
|
{ |
125 |
3 |
return new ImplementationWithDataA1(this.getContext(), this.dataA1); |
126 |
|
} |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
129 |
|
public class TR2 extends TransactionRunnable<DBTransaction> |
130 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
1 |
protected void onRun()... |
132 |
|
{ |
133 |
1 |
Assert.assertEquals("DB Connection was not correct in TR2", |
134 |
|
DB_CONNECTION, this.getContext().getConnection()); |
135 |
|
} |
136 |
|
} |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.5 |
|
138 |
|
public class TR3 extends TransactionRunnable<MyInterfaceWithDataA1> |
139 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
140 |
1 |
protected void onRun()... |
141 |
|
{ |
142 |
1 |
Assert.assertEquals("Data A1 was not correct in TR3", |
143 |
|
DATA_A1, this.getContext().getDataA1()); |
144 |
1 |
Assert.assertEquals("DB Connection was not correct in TR3", |
145 |
|
DB_CONNECTION, this.getContext().getConnection()); |
146 |
|
} |
147 |
|
} |
148 |
|
} |