|
10 | 10 | *******************************************************************************/
|
11 | 11 | package org.eclipse.rcptt.core.tests.model;
|
12 | 12 |
|
13 |
| -import static org.junit.Assert.assertEquals; |
14 |
| -import static org.junit.Assert.assertTrue; |
| 13 | +import static org.junit.Assert.*; |
15 | 14 |
|
16 | 15 | import org.eclipse.core.resources.IProject;
|
17 | 16 | import org.eclipse.core.resources.IProjectDescription;
|
18 | 17 | import org.eclipse.core.resources.IWorkspace;
|
19 | 18 | import org.eclipse.core.resources.ResourcesPlugin;
|
20 | 19 | import org.eclipse.core.runtime.CoreException;
|
21 | 20 | import org.eclipse.core.runtime.NullProgressMonitor;
|
| 21 | +import org.eclipse.rcptt.core.Scenarios; |
| 22 | +import org.eclipse.rcptt.core.model.IElementChangedListener; |
| 23 | +import org.eclipse.rcptt.core.model.IQ7NamedElement; |
22 | 24 | import org.eclipse.rcptt.core.model.IQ7Project;
|
23 | 25 | import org.eclipse.rcptt.core.model.ITestCase;
|
24 | 26 | import org.eclipse.rcptt.core.model.ModelException;
|
@@ -74,23 +76,48 @@ public void testNewTestcaseAppear() throws ModelException {
|
74 | 76 |
|
75 | 77 | copy.commitWorkingCopy(true, new NullProgressMonitor());
|
76 | 78 | assertEquals("new test case name", testcase.getElementName());
|
77 |
| - |
78 | 79 | }
|
79 |
| - |
80 |
| - public void _testWorkingCopyForNewResource() throws ModelException { |
| 80 | + |
| 81 | + @Test |
| 82 | + public void deleteEditedResource() throws CoreException, InterruptedException { |
81 | 83 | IQ7Project prj = q7project;
|
82 |
| - ITestCase testcase = prj.getRootFolder().getTestCase("newTestCase.test"); |
83 |
| - assertTrue(!testcase.exists()); |
84 |
| - ITestCase copy = (ITestCase) testcase |
85 |
| - .getWorkingCopy(new NullProgressMonitor()); |
86 |
| - |
87 |
| - copy.setElementName("new test case name"); |
88 |
| - copy.setTags("tag0"); |
89 |
| - |
90 |
| - assertEquals("new test case name", copy.getElementName()); |
91 |
| - |
92 |
| - copy.commitWorkingCopy(true, new NullProgressMonitor()); |
93 |
| - assertEquals("new test case name", testcase.getElementName()); |
94 |
| - |
| 84 | + IElementChangedListener listener = event -> { |
| 85 | + for (IQ7NamedElement i : event.getDelta().getNamedElements()) { |
| 86 | + try { |
| 87 | + i.getDescription(); // causes element info revival |
| 88 | + } catch (ModelException e) { |
| 89 | + // Does not exist |
| 90 | + } |
| 91 | + } |
| 92 | + }; |
| 93 | + RcpttCore.addElementChangedListener(listener); |
| 94 | + try { |
| 95 | + for (int i = 0; i < 1000; i++) { |
| 96 | + ITestCase testcase = prj.getRootFolder().createTestCase("mytestcase"+i,true, new NullProgressMonitor()); |
| 97 | + |
| 98 | + ITestCase copy = (ITestCase) testcase |
| 99 | + .getWorkingCopy(new NullProgressMonitor()); |
| 100 | + assertTrue(testcase.exists()); |
| 101 | + PROJECT.getFile(testcase.getName()).delete(true, null); |
| 102 | + try { |
| 103 | + testcase.getElementName(); |
| 104 | + } catch (ModelException e) { |
| 105 | + // Does not exist |
| 106 | + } |
| 107 | + try { |
| 108 | + copy.getElementName(); |
| 109 | + } catch (ModelException e) { |
| 110 | + // Does not exist |
| 111 | + } |
| 112 | + copy.discardWorkingCopy(); |
| 113 | + System.gc(); |
| 114 | + NO_ERRORS.assertNoErrors(); |
| 115 | + assertFalse(testcase.exists()); |
| 116 | + } |
| 117 | + } finally { |
| 118 | + RcpttCore.removeElementChangedListener(listener); |
| 119 | + } |
95 | 120 | }
|
| 121 | + |
| 122 | + |
96 | 123 | }
|
0 commit comments