author | serb |
Fri, 16 Feb 2018 12:24:38 -0800 | |
changeset 49090 | 82c1fe23c469 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
23265 | 1 |
/* |
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/** |
|
25 |
* @test |
|
49090
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
26 |
* @key headful |
23265 | 27 |
* @bug 8030050 |
28 |
* @summary Validate fields on DnD class deserialization |
|
29 |
* @author petr.pchelko@oracle.com |
|
30 |
*/ |
|
31 |
||
32 |
import java.io.File; |
|
33 |
import java.io.FileInputStream; |
|
34 |
import java.io.IOException; |
|
35 |
import java.io.InvalidObjectException; |
|
36 |
import java.io.ObjectInputStream; |
|
37 |
import java.util.stream.Stream; |
|
38 |
||
39 |
public class BadSerializationTest { |
|
40 |
||
41 |
private static final String[] badSerialized = new String[] { |
|
42 |
"badAction", |
|
43 |
"noEvents", |
|
44 |
"nullComponent", |
|
45 |
"nullDragSource", |
|
46 |
"nullOrigin" |
|
47 |
}; |
|
48 |
||
49 |
private static final String goodSerialized = "good"; |
|
50 |
||
51 |
public static void main(String[] args) throws Exception { |
|
52 |
String testSrc = System.getProperty("test.src") + File.separator; |
|
53 |
testReadObject(testSrc + goodSerialized, false); |
|
54 |
Stream.of(badSerialized).forEach(file -> testReadObject(testSrc + file, true)); |
|
55 |
} |
|
56 |
||
57 |
private static void testReadObject(String filename, boolean expectException) { |
|
58 |
Exception exceptionCaught = null; |
|
59 |
try (FileInputStream fileInputStream = new FileInputStream(filename); |
|
60 |
ObjectInputStream ois = new ObjectInputStream(fileInputStream)) { |
|
61 |
ois.readObject(); |
|
62 |
} catch (InvalidObjectException e) { |
|
63 |
exceptionCaught = e; |
|
64 |
} catch (IOException e) { |
|
65 |
throw new RuntimeException("FAILED: IOException", e); |
|
66 |
} catch (ClassNotFoundException e) { |
|
67 |
throw new RuntimeException("FAILED: ClassNotFoundException", e); |
|
68 |
} |
|
69 |
if (exceptionCaught != null && !expectException) { |
|
70 |
throw new RuntimeException("FAILED: UnexpectedException", exceptionCaught); |
|
71 |
} |
|
72 |
if (exceptionCaught == null && expectException) { |
|
73 |
throw new RuntimeException("FAILED: Invalid object was created with no exception"); |
|
74 |
} |
|
75 |
} |
|
76 |
} |