1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertNotNull; |
24 |
|
|
25 |
|
import java.io.File; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Date; |
28 |
|
import java.util.List; |
29 |
|
|
30 |
|
import org.testng.Assert; |
31 |
|
import org.testng.annotations.AfterClass; |
32 |
|
import org.testng.annotations.AfterMethod; |
33 |
|
import org.testng.annotations.BeforeClass; |
34 |
|
import org.testng.annotations.BeforeMethod; |
35 |
|
import org.testng.annotations.Test; |
36 |
|
|
37 |
|
import jalview.bin.Cache; |
38 |
|
import jalview.bin.Jalview; |
39 |
|
import jalview.gui.QuitHandler.QResponse; |
40 |
|
import jalview.io.DataSourceType; |
41 |
|
import jalview.io.FileFormat; |
42 |
|
import jalview.io.FileLoader; |
43 |
|
import jalview.project.Jalview2XML; |
44 |
|
|
45 |
|
@Test(singleThreaded = true) |
|
|
| 98.4% |
Uncovered Elements: 2 (123) |
Complexity: 15 |
Complexity Density: 0.14 |
|
46 |
|
public class QuitHandlerTest |
47 |
|
{ |
48 |
|
private static String saveProjectFile = "test-output/tempSaveFile.jvp"; |
49 |
|
|
50 |
|
private static String saveFastaFile = "test-output/tempSaveFile.fa"; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
52 |
1 |
@BeforeClass(alwaysRun = true)... |
53 |
|
public void setUpJvOptionPane() |
54 |
|
{ |
55 |
1 |
JvOptionPane.setInteractiveMode(false); |
56 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
57 |
1 |
Jalview2XML.setDebugDelaySave(3); |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
@throws |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
63 |
1 |
@BeforeClass(alwaysRun = true)... |
64 |
|
public static void setUpBeforeClass() throws Exception |
65 |
|
{ |
66 |
1 |
Cache.loadProperties("test/jalview/gui/quitProps.jvprops"); |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
1 |
Date oneHourFromNow = new Date( |
73 |
|
System.currentTimeMillis() + 3600 * 1000); |
74 |
1 |
Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow); |
75 |
|
|
76 |
1 |
Jalview.main( |
77 |
|
new String[] |
78 |
|
{ "--nowebservicediscovery", "--nosplash", "--nonews" }); |
79 |
|
} |
80 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
81 |
1 |
@AfterClass(alwaysRun = true)... |
82 |
|
public static void resetProps() |
83 |
|
{ |
84 |
|
|
85 |
1 |
QuitHandler.setResponse(QResponse.NULL); |
86 |
|
|
87 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
88 |
|
|
89 |
1 |
if (Desktop.instance != null) |
90 |
1 |
Desktop.instance.closeAll_actionPerformed(null); |
91 |
|
|
92 |
1 |
Jalview2XML.setDebugDelaySave(20); |
93 |
|
|
94 |
1 |
Cache.loadProperties("test/jalview/testProps.jvprops"); |
95 |
|
} |
96 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
97 |
7 |
@BeforeMethod(alwaysRun = true)... |
98 |
|
public static void tearDownAfterClass() throws Exception |
99 |
|
{ |
100 |
|
|
101 |
7 |
QuitHandler.setResponse(QResponse.NULL); |
102 |
|
|
103 |
7 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
104 |
|
|
105 |
7 |
if (Desktop.instance != null) |
106 |
7 |
Desktop.instance.closeAll_actionPerformed(null); |
107 |
|
|
108 |
7 |
Cache.setProperty("DEBUG_DELAY_SAVE", "false"); |
109 |
7 |
Jalview2XML.setDebugDelaySave(3); |
110 |
|
|
111 |
7 |
Desktop.instance.setProjectFile(new File(saveProjectFile)); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
114 |
7 |
@AfterMethod(alwaysRun = true)... |
115 |
|
public static void cleanup() |
116 |
|
{ |
117 |
|
|
118 |
7 |
List<String> files = new ArrayList<>(); |
119 |
7 |
files.add(saveProjectFile); |
120 |
7 |
files.add(saveFastaFile); |
121 |
7 |
for (String filename : files) |
122 |
|
{ |
123 |
14 |
File file = new File(filename); |
124 |
14 |
if (file.exists()) |
125 |
|
{ |
126 |
3 |
file.delete(); |
127 |
|
} |
128 |
|
} |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
131 |
1 |
@Test(groups = { "Functional" }, singleThreaded = true, priority = 1)... |
132 |
|
public void testInstantQuit() throws Exception |
133 |
|
{ |
134 |
1 |
String inFile = "examples/uniref50.fa"; |
135 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, |
136 |
|
DataSourceType.FILE); |
137 |
1 |
assertNotNull(af, "Didn't read input file " + inFile); |
138 |
|
|
139 |
1 |
long start = System.currentTimeMillis(); |
140 |
|
|
141 |
|
|
142 |
1 |
Jalview2XML.setDebugDelaySave(3); |
143 |
1 |
Cache.setProperty("DEBUG_DELAY_SAVE", "true"); |
144 |
|
|
145 |
|
|
146 |
1 |
QResponse response = QuitHandler.getQuitResponse(true); |
147 |
1 |
long end = System.currentTimeMillis(); |
148 |
|
|
149 |
1 |
Assert.assertEquals(response, QResponse.QUIT); |
150 |
1 |
Assert.assertTrue(end - start < 500, |
151 |
|
"Quit-with-no-save-needed took too long (" + (end - start) |
152 |
|
+ "ms)"); |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
155 |
1 |
@Test(groups = { "Functional" }, singleThreaded = true, priority = 10)... |
156 |
|
public void testWaitForSaveQuit() throws Exception |
157 |
|
{ |
158 |
1 |
String inFile = "examples/uniref50.fa"; |
159 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, |
160 |
|
DataSourceType.FILE); |
161 |
1 |
assertNotNull(af, "Didn't read input file " + inFile); |
162 |
|
|
163 |
1 |
long start = System.currentTimeMillis(); |
164 |
|
|
165 |
|
|
166 |
1 |
Jalview2XML.setDebugDelaySave(3); |
167 |
1 |
Cache.setProperty("DEBUG_DELAY_SAVE", "true"); |
168 |
1 |
Desktop.instance.saveState_actionPerformed(false); |
169 |
|
|
170 |
|
|
171 |
1 |
Thread.sleep(500); |
172 |
|
|
173 |
|
|
174 |
1 |
QResponse response = QuitHandler.getQuitResponse(true); |
175 |
1 |
long end = System.currentTimeMillis(); |
176 |
|
|
177 |
1 |
Assert.assertEquals(response, QResponse.QUIT); |
178 |
1 |
Assert.assertTrue(end - start > 2900, |
179 |
|
"Quit-whilst-saving was too short (" + (end - start) + "ms)"); |
180 |
|
} |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
182 |
1 |
@Test(groups = { "Functional" }, singleThreaded = true, priority = 9)... |
183 |
|
public void testSavedProjectChanges() throws Exception |
184 |
|
{ |
185 |
1 |
String inFile = "examples/uniref50.fa"; |
186 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, |
187 |
|
DataSourceType.FILE); |
188 |
1 |
assertNotNull(af, "Didn't read input file " + inFile); |
189 |
1 |
AlignViewport viewport = af.getViewport(); |
190 |
|
|
191 |
1 |
viewport.setSavedUpToDate(false); |
192 |
1 |
Jalview2XML.setStateSavedUpToDate(false); |
193 |
|
|
194 |
|
|
195 |
1 |
Cache.setProperty("DEBUG_DELAY_SAVE", "false"); |
196 |
1 |
af.saveAlignment(saveProjectFile, FileFormat.Jalview); |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.NO_OPTION); |
202 |
1 |
QResponse response = QuitHandler.getQuitResponse(true); |
203 |
|
|
204 |
|
|
205 |
1 |
Assert.assertEquals(response, QResponse.QUIT); |
206 |
|
} |
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
208 |
1 |
@Test(groups = { "Functional" }, singleThreaded = true, priority = 9)... |
209 |
|
public void testSavedAlignmentChanges() throws Exception |
210 |
|
{ |
211 |
1 |
String inFile = "examples/uniref50.fa"; |
212 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, |
213 |
|
DataSourceType.FILE); |
214 |
1 |
assertNotNull(af, "Didn't read input file " + inFile); |
215 |
1 |
AlignViewport viewport = af.getViewport(); |
216 |
|
|
217 |
1 |
viewport.setSavedUpToDate(false); |
218 |
1 |
Jalview2XML.setStateSavedUpToDate(false); |
219 |
|
|
220 |
|
|
221 |
1 |
Cache.setProperty("DEBUG_DELAY_SAVE", "false"); |
222 |
1 |
af.saveAlignment(saveFastaFile, FileFormat.Fasta); |
223 |
|
|
224 |
|
|
225 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.NO_OPTION); |
226 |
1 |
QResponse response = QuitHandler.getQuitResponse(true); |
227 |
|
|
228 |
|
|
229 |
1 |
Assert.assertEquals(response, QResponse.QUIT); |
230 |
|
} |
231 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
232 |
1 |
@Test(groups = { "Functional" }, singleThreaded = true, priority = 1)... |
233 |
|
public void testUnsavedChanges() throws Exception |
234 |
|
{ |
235 |
1 |
String inFile = "examples/uniref50.fa"; |
236 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, |
237 |
|
DataSourceType.FILE); |
238 |
1 |
assertNotNull(af, "Didn't read input file " + inFile); |
239 |
1 |
AlignViewport viewport = af.getViewport(); |
240 |
|
|
241 |
1 |
viewport.setSavedUpToDate(false); |
242 |
1 |
Jalview2XML.setStateSavedUpToDate(false); |
243 |
|
|
244 |
|
|
245 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.NO_OPTION); |
246 |
1 |
QResponse response = QuitHandler.getQuitResponse(true); |
247 |
|
|
248 |
1 |
Assert.assertEquals(response, QResponse.CANCEL_QUIT); |
249 |
|
} |
250 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
251 |
1 |
@Test(groups = { "Functional" }, singleThreaded = true, priority = 1)... |
252 |
|
public void testNoGUIUnsavedChanges() throws Exception |
253 |
|
{ |
254 |
1 |
String inFile = "examples/uniref50.fa"; |
255 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, |
256 |
|
DataSourceType.FILE); |
257 |
1 |
assertNotNull(af, "Didn't read input file " + inFile); |
258 |
1 |
AlignViewport viewport = af.getViewport(); |
259 |
|
|
260 |
1 |
viewport.setSavedUpToDate(false); |
261 |
1 |
Jalview2XML.setStateSavedUpToDate(false); |
262 |
|
|
263 |
|
|
264 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.NO_OPTION); |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
1 |
QResponse response = QuitHandler.getQuitResponse(false); |
274 |
|
|
275 |
1 |
Assert.assertEquals(response, QResponse.QUIT); |
276 |
|
} |
277 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
278 |
1 |
@Test(groups = { "Functional" }, singleThreaded = true, priority = 11)... |
279 |
|
public void testForceQuit() throws Exception |
280 |
|
{ |
281 |
1 |
String inFile = "examples/uniref50.fa"; |
282 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, |
283 |
|
DataSourceType.FILE); |
284 |
1 |
assertNotNull(af, "Didn't read input file " + inFile); |
285 |
|
|
286 |
1 |
long start = System.currentTimeMillis(); |
287 |
|
|
288 |
|
|
289 |
1 |
Jalview2XML.setDebugDelaySave(10); |
290 |
1 |
Cache.setProperty("DEBUG_DELAY_SAVE", "true"); |
291 |
1 |
Desktop.instance.saveState_actionPerformed(false); |
292 |
|
|
293 |
|
|
294 |
1 |
Thread.sleep(100); |
295 |
|
|
296 |
|
|
297 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.YES_OPTION); |
298 |
1 |
QResponse response = QuitHandler.getQuitResponse(true, |
299 |
|
QuitHandler.defaultOkQuit, () -> { |
300 |
|
|
301 |
2 |
jalview.bin.Console.debug( |
302 |
|
"Setting FORCE_QUIT without actually quitting"); |
303 |
2 |
QuitHandler.setResponse(QResponse.FORCE_QUIT); |
304 |
|
}, QuitHandler.defaultCancelQuit); |
305 |
1 |
long end = System.currentTimeMillis(); |
306 |
|
|
307 |
1 |
Assert.assertEquals(response, QResponse.FORCE_QUIT); |
308 |
|
|
309 |
1 |
Assert.assertTrue(end - start > 1000, |
310 |
|
"Force-Quit-whilst-saving was too short (" + (end - start) |
311 |
|
+ "ms)"); |
312 |
|
|
313 |
1 |
Assert.assertTrue(end - start < 9090, |
314 |
|
"Force-Quit-whilst-saving was too long (" + (end - start) |
315 |
|
+ "ms)"); |
316 |
|
|
317 |
|
} |
318 |
|
|
319 |
|
} |