|
Lines 31-38
Link Here
|
| 31 |
import org.eclipse.emf.ecore.EPackage; |
31 |
import org.eclipse.emf.ecore.EPackage; |
| 32 |
import org.eclipse.emf.ecore.resource.Resource; |
32 |
import org.eclipse.emf.ecore.resource.Resource; |
| 33 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
33 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
|
|
34 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
| 34 |
import org.eclipse.emf.ecore.util.InternalEList; |
35 |
import org.eclipse.emf.ecore.util.InternalEList; |
| 35 |
import org.eclipse.emf.transaction.impl.TransactionChangeRecorder; |
36 |
import org.eclipse.emf.transaction.impl.TransactionChangeRecorder; |
|
|
37 |
import org.eclipse.emf.transaction.util.TransactionUtil; |
| 36 |
|
38 |
|
| 37 |
|
39 |
|
| 38 |
/** |
40 |
/** |
|
Lines 151-157
Link Here
|
| 151 |
|
153 |
|
| 152 |
/** |
154 |
/** |
| 153 |
* Tests that the change recorder is correctly propagated to the objects in |
155 |
* Tests that the change recorder is correctly propagated to the objects in |
| 154 |
* a resource when it is loadedwhen loading in a read-write transaction |
156 |
* a resource when it is loaded when loading in a read-write transaction |
| 155 |
* (creating change descriptions). |
157 |
* (creating change descriptions). |
| 156 |
*/ |
158 |
*/ |
| 157 |
public void test_changeRecorderPropagatedOnLoad_writeTX() { |
159 |
public void test_changeRecorderPropagatedOnLoad_writeTX() { |
|
Lines 183-188
Link Here
|
| 183 |
assertFalse(nestedResource2.isLoaded()); |
185 |
assertFalse(nestedResource2.isLoaded()); |
| 184 |
} |
186 |
} |
| 185 |
|
187 |
|
|
|
188 |
/** |
| 189 |
* Tests that disposing an editing domain (and its change recorder) removes |
| 190 |
* the change recorder from all of the current contents of the resource |
| 191 |
* set. |
| 192 |
*/ |
| 193 |
public void test_changeRecorderDispose_161169() { |
| 194 |
startWriting(); |
| 195 |
loadRoot(); |
| 196 |
|
| 197 |
TransactionChangeRecorder recorder = getRecorder(rootResource); |
| 198 |
|
| 199 |
EClass eclass = findClass("root/A", true); //$NON-NLS-1$ |
| 200 |
|
| 201 |
assertSame(recorder, getRecorder(eclass)); |
| 202 |
|
| 203 |
commit(); |
| 204 |
|
| 205 |
domain.dispose(); |
| 206 |
|
| 207 |
try { |
| 208 |
// attempt to change it without a transaction. Should be allowed |
| 209 |
eclass.setName("NewName"); //$NON-NLS-1$ |
| 210 |
} catch (Exception e) { |
| 211 |
e.printStackTrace(); |
| 212 |
fail("Should not have asserted the transaction protocol: " //$NON-NLS-1$ |
| 213 |
+ e.getLocalizedMessage()); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Tests that the change recorder is implicitly removed even from model |
| 219 |
* elements that were not attached to the resource set at the time when |
| 220 |
* the editing domain was disposed. |
| 221 |
*/ |
| 222 |
public void test_changeRecorderDispose_detachedElements_161169() { |
| 223 |
startWriting(); |
| 224 |
loadRoot(); |
| 225 |
|
| 226 |
TransactionChangeRecorder recorder = getRecorder(rootResource); |
| 227 |
|
| 228 |
EClass eclass = findClass("root/A", true); //$NON-NLS-1$ |
| 229 |
|
| 230 |
assertSame(recorder, getRecorder(eclass)); |
| 231 |
|
| 232 |
// detach the EClass |
| 233 |
eclass.getEPackage().getEClassifiers().remove(eclass); |
| 234 |
|
| 235 |
commit(); |
| 236 |
|
| 237 |
domain.dispose(); |
| 238 |
|
| 239 |
try { |
| 240 |
// attempt to change it without a transaction. Should be allowed |
| 241 |
eclass.setName("NewName"); //$NON-NLS-1$ |
| 242 |
} catch (Exception e) { |
| 243 |
e.printStackTrace(); |
| 244 |
fail("Should not have asserted the transaction protocol: " //$NON-NLS-1$ |
| 245 |
+ e.getLocalizedMessage()); |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Tests the new utility for "freeing" resources from the transactional |
| 251 |
* protocol of an editing domain. |
| 252 |
*/ |
| 253 |
public void test_freeDetachedResources_161169() { |
| 254 |
startWriting(); |
| 255 |
loadRoot(); |
| 256 |
|
| 257 |
TransactionChangeRecorder recorder = getRecorder(rootResource); |
| 258 |
|
| 259 |
EClass eclass = findClass("root/A", true); //$NON-NLS-1$ |
| 260 |
|
| 261 |
assertSame(recorder, getRecorder(eclass)); |
| 262 |
|
| 263 |
commit(); |
| 264 |
|
| 265 |
// no transaction protocol on this |
| 266 |
domain.getResourceSet().getResources().remove(rootResource); |
| 267 |
|
| 268 |
// set the resource free |
| 269 |
TransactionUtil.disconnectFromEditingDomain(rootResource); |
| 270 |
|
| 271 |
try { |
| 272 |
// attempt to change it without a transaction. Should be allowed |
| 273 |
eclass.setName("NewName"); //$NON-NLS-1$ |
| 274 |
} catch (Exception e) { |
| 275 |
e.printStackTrace(); |
| 276 |
fail("Should not have asserted the transaction protocol: " //$NON-NLS-1$ |
| 277 |
+ e.getLocalizedMessage()); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* Tests that the new utility frees only the proper contents of the resource. |
| 283 |
*/ |
| 284 |
public void test_freeDetachedResources_properContents_161169() { |
| 285 |
startWriting(); |
| 286 |
loadRoot(); |
| 287 |
|
| 288 |
TransactionChangeRecorder recorder = getRecorder(rootResource); |
| 289 |
|
| 290 |
EClass eclass = findClass("root/A", true); //$NON-NLS-1$ |
| 291 |
EClass nested = findClass("root/nested1/nested2/nested3/D", true); //$NON-NLS-1$ |
| 292 |
|
| 293 |
assertSame(recorder, getRecorder(eclass)); |
| 294 |
|
| 295 |
commit(); |
| 296 |
|
| 297 |
// no transaction protocol on this |
| 298 |
domain.getResourceSet().getResources().remove(rootResource); |
| 299 |
|
| 300 |
// set the root resource free |
| 301 |
TransactionUtil.disconnectFromEditingDomain(rootResource); |
| 302 |
|
| 303 |
try { |
| 304 |
// set the nested resource free |
| 305 |
TransactionUtil.disconnectFromEditingDomain(nestedResource1); |
| 306 |
|
| 307 |
fail("Should have thrown IllegalArgumentException"); //$NON-NLS-1$ |
| 308 |
} catch (IllegalArgumentException e) { |
| 309 |
// pass |
| 310 |
System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$ |
| 311 |
} |
| 312 |
|
| 313 |
try { |
| 314 |
// modify the nested element |
| 315 |
nested.setName("NewName"); //$NON-NLS-1$ |
| 316 |
|
| 317 |
fail("Should have thrown IllegalStateException"); //$NON-NLS-1$ |
| 318 |
} catch (IllegalStateException e) { |
| 319 |
// pass |
| 320 |
System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$ |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
/** |
| 325 |
* Tests the new utility for "freeing" elements from the transactional |
| 326 |
* protocol of an editing domain. |
| 327 |
*/ |
| 328 |
public void test_freeDetachedElements_161169() { |
| 329 |
startWriting(); |
| 330 |
loadRoot(); |
| 331 |
|
| 332 |
TransactionChangeRecorder recorder = getRecorder(rootResource); |
| 333 |
|
| 334 |
EClass eclass = findClass("root/A", true); //$NON-NLS-1$ |
| 335 |
|
| 336 |
assertSame(recorder, getRecorder(eclass)); |
| 337 |
|
| 338 |
// detach some ancestor, just for fun |
| 339 |
EObject container = eclass.eContainer(); |
| 340 |
EcoreUtil.remove(container); |
| 341 |
|
| 342 |
commit(); |
| 343 |
|
| 344 |
// set the element free |
| 345 |
TransactionUtil.disconnectFromEditingDomain(container); |
| 346 |
|
| 347 |
try { |
| 348 |
// attempt to change it without a transaction. Should be allowed |
| 349 |
eclass.setName("NewName"); //$NON-NLS-1$ |
| 350 |
} catch (Exception e) { |
| 351 |
e.printStackTrace(); |
| 352 |
fail("Should not have asserted the transaction protocol: " //$NON-NLS-1$ |
| 353 |
+ e.getLocalizedMessage()); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* Tests that the new utility frees only the proper contents of an element. |
| 359 |
*/ |
| 360 |
public void test_freeDetachedElements_properContents_161169() { |
| 361 |
startWriting(); |
| 362 |
loadRoot(); |
| 363 |
|
| 364 |
TransactionChangeRecorder recorder = getRecorder(rootResource); |
| 365 |
|
| 366 |
EClass eclass = findClass("root/A", true); //$NON-NLS-1$ |
| 367 |
EClass nested = findClass("root/nested1/nested2/nested3/D", true); //$NON-NLS-1$ |
| 368 |
|
| 369 |
assertSame(recorder, getRecorder(eclass)); |
| 370 |
|
| 371 |
// detach some ancestor, just for fun |
| 372 |
EObject container = eclass.eContainer(); |
| 373 |
EcoreUtil.remove(container); |
| 374 |
|
| 375 |
commit(); |
| 376 |
|
| 377 |
try { |
| 378 |
// set the nested element free |
| 379 |
TransactionUtil.disconnectFromEditingDomain(nested); |
| 380 |
|
| 381 |
fail("Should have thrown IllegalArgumentException"); //$NON-NLS-1$ |
| 382 |
} catch (IllegalArgumentException e) { |
| 383 |
// pass |
| 384 |
System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$ |
| 385 |
} |
| 386 |
|
| 387 |
try { |
| 388 |
// modify the nested element |
| 389 |
nested.setName("NewName"); //$NON-NLS-1$ |
| 390 |
|
| 391 |
fail("Should have thrown IllegalStateException"); //$NON-NLS-1$ |
| 392 |
} catch (IllegalStateException e) { |
| 393 |
// pass |
| 394 |
System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$ |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 186 |
// |
398 |
// |
| 187 |
// Framework methods |
399 |
// Framework methods |
| 188 |
// |
400 |
// |