13
13
*******************************************************************************/
14
14
package org .eclipse .core .tests .resources .saveparticipant ;
15
15
16
- import junit .framework .Test ;
17
- import junit .framework .TestSuite ;
18
-
19
- import org .eclipse .core .resources .*;
20
- import org .eclipse .core .runtime .*;
16
+ import static org .eclipse .core .resources .ResourcesPlugin .getWorkspace ;
17
+ import static org .eclipse .core .tests .resources .ResourceTestUtil .assertExistsInFileSystem ;
18
+ import static org .eclipse .core .tests .resources .ResourceTestUtil .assertExistsInWorkspace ;
19
+ import static org .eclipse .core .tests .resources .ResourceTestUtil .buildResources ;
20
+ import static org .eclipse .core .tests .resources .ResourceTestUtil .createInWorkspace ;
21
+ import static org .eclipse .core .tests .resources .ResourceTestUtil .createRandomContentsStream ;
22
+ import static org .eclipse .core .tests .resources .ResourceTestUtil .createTestMonitor ;
23
+ import static org .eclipse .core .tests .resources .ResourceTestUtil .setAutoBuilding ;
24
+ import static org .eclipse .core .tests .resources .ResourceTestUtil .waitForBuild ;
25
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
26
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
27
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
28
+
29
+ import org .eclipse .core .resources .ICommand ;
30
+ import org .eclipse .core .resources .IFile ;
31
+ import org .eclipse .core .resources .IProject ;
32
+ import org .eclipse .core .resources .IProjectDescription ;
33
+ import org .eclipse .core .resources .IResource ;
34
+ import org .eclipse .core .resources .IResourceDelta ;
35
+ import org .eclipse .core .resources .ISaveContext ;
36
+ import org .eclipse .core .resources .IncrementalProjectBuilder ;
37
+ import org .eclipse .core .runtime .CoreException ;
38
+ import org .eclipse .core .runtime .IStatus ;
39
+ import org .eclipse .core .runtime .Platform ;
21
40
import org .eclipse .core .tests .internal .builders .DeltaVerifierBuilder ;
22
41
import org .eclipse .core .tests .resources .regression .SimpleBuilder ;
23
42
import org .eclipse .core .tests .resources .saveparticipant1 .SaveParticipant1Plugin ;
24
43
import org .eclipse .core .tests .resources .saveparticipant2 .SaveParticipant2Plugin ;
25
44
import org .eclipse .core .tests .resources .saveparticipant3 .SaveParticipant3Plugin ;
26
45
import org .osgi .framework .Bundle ;
27
46
import org .osgi .framework .BundleException ;
28
- import static org .eclipse .core .resources .ResourcesPlugin .getWorkspace ;
29
- import static org .eclipse .core .tests .resources .ResourceTestUtil .assertExistsInFileSystem ;
30
- import static org .eclipse .core .tests .resources .ResourceTestUtil .assertExistsInWorkspace ;
31
- import static org .eclipse .core .tests .resources .ResourceTestUtil .createTestMonitor ;
32
- import static org .eclipse .core .tests .resources .ResourceTestUtil .buildResources ;
33
- import static org .eclipse .core .tests .resources .ResourceTestUtil .waitForBuild ;
34
- import static org .eclipse .core .tests .resources .ResourceTestUtil .*;
35
47
36
48
/**
37
49
* This class needs to be used with SaveManager2Test. Basically this
42
54
* @see SaveManager2Test
43
55
* @see SaveManager3Test
44
56
*/
45
- public class SaveManager1Test extends SaveManagerTest {
57
+ public class SaveManager1Test {
58
+
46
59
/**
47
- * Need a zero argument constructor to satisfy the test harness.
48
- * This constructor should not do any real work nor should it be
49
- * called by user code.
60
+ * Create some resources and save the workspace.
50
61
*/
51
- public SaveManager1Test () {
52
- }
62
+ public void testCreateMyProject () throws CoreException {
63
+ IProject project = getWorkspace ().getRoot ().getProject (SaveManagerTest .PROJECT_1 );
64
+ project .create (null );
65
+ project .open (null );
66
+ assertTrue (project .exists ());
67
+ assertTrue (project .isOpen ());
53
68
54
- public SaveManager1Test (String name ) {
55
- super (name );
56
- }
69
+ project .close (null );
70
+ assertTrue (project .exists ());
71
+ assertFalse (project .isOpen ());
72
+
73
+ // when closing and opening the project again, it should still exist
74
+ project = getWorkspace ().getRoot ().getProject (SaveManagerTest .PROJECT_1 );
75
+ project .open (null );
76
+ assertTrue (project .exists ());
77
+ assertTrue (project .isOpen ());
57
78
58
- // copy and paste into the scrapbook
59
- public static void doIt () throws Exception {
60
- String [] testIds = {"saveparticipant.SaveManager1Test" , "saveparticipant.SaveManager2Test" , "saveparticipant.SaveManager3Test" };
61
- for (int i = 0 ; i < testIds .length ; i ++) {
62
- Process p = Runtime .getRuntime ().exec (new String [] {"java" , "org.eclipse.core.tests.harness.launcher.Main" , "-test" , testIds [i ], "-data" , "c:/temp/save_manager" , (i < (testIds .length - 1 ) ? "-nocleanup" : "" )});
63
- p .waitFor ();
64
- java .io .InputStream input = p .getInputStream ();
65
- int c ;
66
- while ((c = input .read ()) != -1 )
67
- System .out .print ((char ) c );
68
- input .close ();
69
- input = p .getErrorStream ();
70
- while ((c = input .read ()) != -1 )
71
- System .out .print ((char ) c );
72
- input .close ();
73
- }
74
- System .exit (-1 );
79
+ // create some children
80
+ IResource [] resources = buildResources (project , SaveManagerTest .defineHierarchy (SaveManagerTest .PROJECT_1 ));
81
+ createInWorkspace (resources );
82
+ assertExistsInFileSystem (resources );
83
+ assertExistsInWorkspace (resources );
84
+
85
+ project .close (null );
86
+ project .open (null );
87
+ assertExistsInFileSystem (resources );
88
+ assertExistsInWorkspace (resources );
75
89
}
76
90
77
- public static Test suite () {
78
- // we do not add the whole class because the order is important
79
- TestSuite suite = new TestSuite ();
80
- suite .addTest (new SaveManager1Test ("saveWorkspace" ));
81
- suite .addTest (new SaveManager1Test ("testCreateMyProject" ));
82
- suite .addTest (new SaveManager1Test ("testCreateProject2" ));
83
- suite .addTest (new SaveManager1Test ("testAddSaveParticipant" ));
84
- suite .addTest (new SaveManager1Test ("testBuilder" ));
85
- suite .addTest (new SaveManager1Test ("saveWorkspace" ));
86
- suite .addTest (new SaveManager1Test ("testPostSave" ));
87
- return suite ;
91
+ /**
92
+ * Create another project and leave it closed for next session.
93
+ */
94
+ public void testCreateProject2 () throws CoreException {
95
+ IProject project = getWorkspace ().getRoot ().getProject (SaveManagerTest .PROJECT_2 );
96
+ project .create (null );
97
+ project .open (null );
98
+ assertTrue (project .exists ());
99
+ assertTrue (project .isOpen ());
100
+
101
+ // create some children
102
+ IResource [] resources = buildResources (project , SaveManagerTest .defineHierarchy (SaveManagerTest .PROJECT_2 ));
103
+ createInWorkspace (resources );
104
+ assertExistsInFileSystem (resources );
105
+ assertExistsInWorkspace (resources );
106
+
107
+ // add a builder to this project
108
+ IProjectDescription description = project .getDescription ();
109
+ ICommand command = description .newCommand ();
110
+ command .setBuilderName (SimpleBuilder .BUILDER_ID );
111
+ description .setBuildSpec (new ICommand [] { command });
112
+ project .setDescription (description , null );
113
+ project .build (IncrementalProjectBuilder .FULL_BUILD , null );
114
+
115
+ project .close (null );
116
+ assertTrue (project .exists ());
117
+ assertFalse (project .isOpen ());
88
118
}
89
119
90
120
public void testAddSaveParticipant () throws Exception {
91
121
// get plugin
92
- Bundle bundle = Platform .getBundle (PI_SAVE_PARTICIPANT_1 );
93
- assertTrue ( "0.1" , bundle != null );
122
+ Bundle bundle = Platform .getBundle (SaveManagerTest . PI_SAVE_PARTICIPANT_1 );
123
+ assertNotNull ( bundle );
94
124
bundle .start ();
95
125
SaveParticipant1Plugin plugin1 = SaveParticipant1Plugin .getInstance ();
96
126
97
127
// prepare plugin to the save operation
98
128
plugin1 .resetDeltaVerifier ();
99
129
IStatus status ;
100
130
status = plugin1 .registerAsSaveParticipant ();
101
- assertTrue ("Registering save participant failed with message: " + status .getMessage (), status . isOK ());
131
+ assertTrue (status . isOK (), "Registering save participant failed with message: " + status .getMessage ());
102
132
plugin1 .setExpectedSaveKind (ISaveContext .FULL_SAVE );
103
133
104
134
// SaveParticipant2Plugin
105
- bundle = Platform .getBundle (PI_SAVE_PARTICIPANT_2 );
106
- assertTrue ( "5.1" , bundle != null );
135
+ bundle = Platform .getBundle (SaveManagerTest . PI_SAVE_PARTICIPANT_2 );
136
+ assertNotNull ( bundle );
107
137
bundle .start ();
108
138
SaveParticipant2Plugin plugin2 = SaveParticipant2Plugin .getInstance ();
109
139
110
140
// prepare plugin to the save operation
111
141
plugin2 .getDeltaVerifier ().reset ();
112
142
status = plugin2 .registerAsSaveParticipant ();
113
- assertTrue ("Registering save participant failed with message: " + status .getMessage (), status . isOK ());
143
+ assertTrue (status . isOK (), "Registering save participant failed with message: " + status .getMessage ());
114
144
plugin1 .setExpectedSaveKind (ISaveContext .FULL_SAVE );
115
145
116
146
// SaveParticipant3Plugin
117
- bundle = Platform .getBundle (PI_SAVE_PARTICIPANT_3 );
118
- assertTrue ( "7.1" , bundle != null );
147
+ bundle = Platform .getBundle (SaveManagerTest . PI_SAVE_PARTICIPANT_3 );
148
+ assertNotNull ( bundle );
119
149
bundle .start ();
120
150
SaveParticipant3Plugin plugin3 = SaveParticipant3Plugin .getInstance ();
121
151
122
152
status = plugin3 .registerAsSaveParticipant ();
123
- assertTrue ("Registering save participant failed with message: " + status .getMessage (), status .isOK ());
124
- }
125
-
126
- /**
127
- * Create another project and leave it closed for next session.
128
- */
129
- public void testAnotherProject () throws CoreException {
130
- IProject project = getWorkspace ().getRoot ().getProject (PROJECT_1 );
131
- project .create (null );
132
- project .open (null );
133
- assertTrue ("0.1" , project .exists ());
134
- assertTrue ("0.2" , project .isOpen ());
135
-
136
- project .close (null );
137
- assertTrue ("1.1" , project .exists ());
138
- assertTrue ("1.2" , !project .isOpen ());
139
-
140
- // when closing and opening the project again, it should still exist
141
- project = getWorkspace ().getRoot ().getProject (PROJECT_1 );
142
- project .open (null );
143
- assertTrue ("2.1" , project .exists ());
144
- assertTrue ("2.2" , project .isOpen ());
145
-
146
- // create some children
147
- IResource [] resources = buildResources (project , defineHierarchy (PROJECT_1 ));
148
- createInWorkspace (resources );
149
- assertExistsInFileSystem (resources );
150
- assertExistsInWorkspace (resources );
151
-
152
- project .close (null );
153
- project .open (null );
154
- assertExistsInFileSystem (resources );
155
- assertExistsInWorkspace (resources );
156
-
157
- getWorkspace ().save (true , null );
153
+ assertTrue (status .isOK (), "Registering save participant failed with message: " + status .getMessage ());
158
154
}
159
155
160
156
public void testBuilder () throws CoreException {
161
- IProject project = getWorkspace ().getRoot ().getProject (PROJECT_1 );
162
- assertTrue ("0.0" , project .isAccessible ());
157
+ IProject project = getWorkspace ().getRoot ().getProject (SaveManagerTest . PROJECT_1 );
158
+ assertTrue (project .isAccessible ());
163
159
164
160
setAutoBuilding (true );
165
161
// Create and set a build spec for the project
@@ -180,82 +176,22 @@ public void testBuilder() throws CoreException {
180
176
verifier .addExpectedChange (added , project , IResourceDelta .ADDED , 0 );
181
177
added .create (createRandomContentsStream (), true , null );
182
178
waitForBuild ();
183
- assertTrue ("3.2" , verifier .wasAutoBuild ());
184
- assertTrue ("3.3" , verifier .isDeltaValid ());
179
+ assertTrue (verifier .wasAutoBuild ());
180
+ assertTrue (verifier .isDeltaValid ());
185
181
// remove the file because we don't want it to affect any other delta in the test
186
182
added .delete (true , false , null );
187
183
}
188
184
189
- /**
190
- * Create some resources and save the workspace.
191
- */
192
- public void testCreateMyProject () throws CoreException {
193
- IProject project = getWorkspace ().getRoot ().getProject (PROJECT_1 );
194
- project .create (null );
195
- project .open (null );
196
- assertTrue ("0.1" , project .exists ());
197
- assertTrue ("0.2" , project .isOpen ());
198
-
199
- project .close (null );
200
- assertTrue ("1.1" , project .exists ());
201
- assertTrue ("1.2" , !project .isOpen ());
202
-
203
- // when closing and opening the project again, it should still exist
204
- project = getWorkspace ().getRoot ().getProject (PROJECT_1 );
205
- project .open (null );
206
- assertTrue ("2.1" , project .exists ());
207
- assertTrue ("2.2" , project .isOpen ());
208
-
209
- // create some children
210
- IResource [] resources = buildResources (project , defineHierarchy (PROJECT_1 ));
211
- createInWorkspace (resources );
212
- assertExistsInFileSystem (resources );
213
- assertExistsInWorkspace (resources );
214
-
215
- project .close (null );
216
- project .open (null );
217
- assertExistsInFileSystem (resources );
218
- assertExistsInWorkspace (resources );
219
- }
220
-
221
- /**
222
- * Create another project and leave it closed for next session.
223
- */
224
- public void testCreateProject2 () throws CoreException {
225
- IProject project = getWorkspace ().getRoot ().getProject (PROJECT_2 );
226
- project .create (null );
227
- project .open (null );
228
- assertTrue ("0.1" , project .exists ());
229
- assertTrue ("0.2" , project .isOpen ());
230
-
231
- // create some children
232
- IResource [] resources = buildResources (project , defineHierarchy (PROJECT_2 ));
233
- createInWorkspace (resources );
234
- assertExistsInFileSystem (resources );
235
- assertExistsInWorkspace (resources );
236
-
237
- // add a builder to this project
238
- IProjectDescription description = project .getDescription ();
239
- ICommand command = description .newCommand ();
240
- command .setBuilderName (SimpleBuilder .BUILDER_ID );
241
- description .setBuildSpec (new ICommand [] {command });
242
- project .setDescription (description , null );
243
- project .build (IncrementalProjectBuilder .FULL_BUILD , null );
244
-
245
- project .close (null );
246
- assertTrue ("5.1" , project .exists ());
247
- assertTrue ("5.2" , !project .isOpen ());
248
- }
249
-
250
185
public void testPostSave () throws BundleException {
251
186
// get plugin
252
- Bundle bundle = Platform .getBundle (PI_SAVE_PARTICIPANT_1 );
253
- assertTrue ( "0.1" , bundle != null );
187
+ Bundle bundle = Platform .getBundle (SaveManagerTest . PI_SAVE_PARTICIPANT_1 );
188
+ assertNotNull ( bundle );
254
189
bundle .start ();
255
190
SaveParticipant1Plugin plugin = SaveParticipant1Plugin .getInstance ();
256
191
257
192
// look at the plugin save lifecycle
258
193
IStatus status = plugin .getSaveLifecycleLog ();
259
- assertTrue ("Getting lifecycle log failed with message: " + status .getMessage (), status . isOK ());
194
+ assertTrue (status . isOK (), "Getting lifecycle log failed with message: " + status .getMessage ());
260
195
}
196
+
261
197
}
0 commit comments