1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.nuiton.topia.replication;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.junit.After;
30 import org.junit.AfterClass;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.nuiton.topia.TestHelper;
35 import org.nuiton.topia.TopiaContext;
36 import org.nuiton.topia.TopiaContextFactory;
37 import org.nuiton.topia.TopiaException;
38 import org.nuiton.topia.TopiaTestDAOHelper.TopiaTestEntityEnum;
39 import org.nuiton.topia.framework.TopiaContextImplementor;
40 import org.nuiton.topia.persistence.TopiaEntity;
41 import org.nuiton.topia.persistence.TopiaEntityEnum;
42 import org.nuiton.topia.test.entities.Person;
43 import org.nuiton.topia.test.entities.PersonImpl;
44 import org.nuiton.topia.test.entities.Pet;
45 import org.nuiton.topia.test.entities.PetImpl;
46 import org.nuiton.topia.test.entities.Race;
47 import org.nuiton.topia.test.entities.RaceImpl;
48
49 import java.io.File;
50 import java.io.IOException;
51 import java.util.Properties;
52
53
54
55
56
57
58
59
60
61 public class TopiaReplicationServiceImplAllTest extends AbstractTopiaReplicationServiceTest {
62
63
64 private static final Log log = LogFactory.getLog(TopiaReplicationServiceImplTest.class);
65
66 protected static final TopiaEntityEnum[] contracts = {
67 TopiaTestEntityEnum.Person,
68 TopiaTestEntityEnum.Pet,
69 TopiaTestEntityEnum.Race
70 };
71
72 protected static final String entitiesList =
73 PersonImpl.class.getName() + "," +
74 PetImpl.class.getName() + "," +
75 RaceImpl.class.getName();
76
77 static protected Person person, person2;
78
79 static protected Pet pet, pet2, pet3;
80
81 static protected Race race, race2, race3;
82
83 protected static File tesDir;
84
85 @BeforeClass
86 public static void beforeClass() throws IOException {
87 tesDir = TestHelper.getTestBasedir(TopiaReplicationServiceImplAllTest.class);
88 }
89
90 @AfterClass
91 public static void after() throws Exception {
92 AbstractTopiaReplicationServiceTest.after();
93 }
94
95 @Before
96 @Override
97 public void setUp() throws Exception {
98
99 super.setUp();
100
101 person = update(person);
102 person2 = update(person2);
103 pet = update(pet);
104 pet2 = update(pet2);
105 race = update(race);
106 race2 = update(race2);
107 race3 = update(race3);
108 }
109
110 @After
111 @Override
112 public void tearDown() throws Exception {
113 super.tearDown();
114 if (dstCtxt != null && !dstCtxt.isClosed()) {
115 dstCtxt.closeContext();
116 }
117 }
118
119
120
121 @Test
122 @Override
123 public void testDetectTypes() throws Exception {
124
125 detectTypes(race, Race.class);
126 detectTypes(pet, Pet.class, Person.class, Race.class);
127 detectTypes(person, Pet.class, Person.class, Race.class);
128
129 detectTypes(pet2, Pet.class);
130 detectTypes(person2, Person.class);
131 detectTypes(race2, Race.class);
132
133 detectTypes(race3, Race.class);
134 detectTypes(pet3, Pet.class, Race.class);
135 }
136
137
138
139 @Test
140 @Override
141 public void testGetOperation() throws Exception {
142 }
143
144
145
146 @Test
147 @Override
148 public void testDetectAssociations() throws Exception {
149
150 detectAssociations(person, TopiaTestEntityEnum.Person, Person.PROPERTY_PET);
151 detectAssociations(race);
152 detectAssociations(pet);
153
154 detectAssociations(person2);
155 detectAssociations(race2);
156 detectAssociations(pet2);
157
158 }
159
160
161
162 @Test
163 @Override
164 public void testDetectDirectDependencies() throws Exception {
165
166 detectDirectDependencies(person);
167 detectDirectDependencies(race);
168 detectDirectDependencies(pet, TopiaTestEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTestEntityEnum.Pet, Pet.PROPERTY_RACE);
169
170 detectDirectDependencies(person2);
171 detectDirectDependencies(race2);
172 detectDirectDependencies(pet2);
173 }
174
175
176
177 @Test
178 @Override
179 public void testDetectShell() throws Exception {
180
181 detectShell(person, TopiaTestEntityEnum.Pet, TopiaTestEntityEnum.Race);
182 detectShell(race);
183 detectShell(pet, TopiaTestEntityEnum.Person, TopiaTestEntityEnum.Race);
184 detectShell(person2, TopiaTestEntityEnum.Pet, TopiaTestEntityEnum.Race);
185 detectShell(race2);
186 detectShell(pet2, TopiaTestEntityEnum.Person, TopiaTestEntityEnum.Race);
187 }
188
189
190
191 @Test
192 @Override
193 public void testDetectDependencies() throws Exception {
194
195 detectDependencies(null,
196 new TopiaTestEntityEnum[]{TopiaTestEntityEnum.Race}, new TopiaTestEntityEnum[]{TopiaTestEntityEnum.Person}, new TopiaTestEntityEnum[]{TopiaTestEntityEnum.Pet});
197 }
198
199
200
201 @Test
202 @Override
203 public void testDetectObjectsToDettach() throws Exception {
204
205 detectObjectsToDettach(null, TopiaTestEntityEnum.Person, new String[]{Person.PROPERTY_PET});
206 }
207
208
209
210 @Test
211 @Override
212 public void testDetectOperations() throws Exception {
213
214 detectOperations(null);
215 }
216
217
218
219 @Test
220 @Override
221 public void testDoReplicate() throws Exception {
222
223 doReplicateAll();
224
225 }
226
227 @Override
228 protected TopiaContext createDb(String name) throws Exception {
229
230
231
232 Properties config = getH2Properties(name);
233
234 context = TopiaContextFactory.getContext(config);
235
236 TopiaContextImplementor tx = (TopiaContextImplementor) context.beginTransaction();
237
238 person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master");
239 race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I");
240 pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
241
242 person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
243 pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
244 race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II");
245
246 race3 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race III");
247 pet3 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3);
248
249 tx.commitTransaction();
250 tx.closeContext();
251 return context;
252 }
253
254 @Override
255 protected TopiaContext createDb2(String name) throws Exception {
256
257
258
259 Properties config = getH2Properties(name);
260
261 return TopiaContextFactory.getContext(config);
262 }
263
264 @Override
265 protected TopiaEntityEnum[] getContracts() {
266 return contracts;
267 }
268
269 @Override
270 protected Log getLog() {
271 return log;
272 }
273
274 protected Properties getH2Properties(String dbName) throws IOException {
275
276 Properties config = TestHelper.initTopiaContextConfiguration(tesDir, dbName);
277
278
279
280
281 config.setProperty("topia.persistence.classes", entitiesList);
282
283
284
285
286
287
288 config.setProperty(TopiaReplicationServiceImpl.TOPIA_SERVICE_NAME, TopiaReplicationServiceImpl.class.getName());
289
290 return config;
291 }
292
293
294 @Override
295 protected void createModel(TopiaEntity entity) throws TopiaException {
296 model = getModelBuilder().createModelForAll(getContracts());
297 }
298
299 @Override
300 protected void prepareModel(String... ids) throws TopiaException {
301 model = service.prepareForAll(getContracts());
302 }
303
304 }
305
306