author | malenkov |
Mon, 29 Apr 2013 16:42:22 +0400 | |
changeset 17148 | bb5fff33bf49 |
parent 6106 | c5ba8eff9aca |
child 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
6106
c5ba8eff9aca
6972468: Security manager should be used for tests in java/beans/XMLEncoder
malenkov
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
6106
c5ba8eff9aca
6972468: Security manager should be used for tests in java/beans/XMLEncoder
malenkov
parents:
5506
diff
changeset
|
26 |
* @bug 4631471 6972468 |
2 | 27 |
* @summary Tests DefaultTreeModel encoding |
28 |
* @author Sergey Malenkov, Mark Davidson |
|
29 |
*/ |
|
30 |
||
31 |
import javax.swing.JTree; |
|
32 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
33 |
import javax.swing.tree.DefaultTreeModel; |
|
34 |
import javax.swing.tree.TreeModel; |
|
35 |
import javax.swing.tree.TreeNode; |
|
36 |
||
37 |
public abstract class Test4631471 extends AbstractTest { |
|
38 |
public static void main(String[] args) throws Exception { |
|
6106
c5ba8eff9aca
6972468: Security manager should be used for tests in java/beans/XMLEncoder
malenkov
parents:
5506
diff
changeset
|
39 |
main(); |
c5ba8eff9aca
6972468: Security manager should be used for tests in java/beans/XMLEncoder
malenkov
parents:
5506
diff
changeset
|
40 |
System.setSecurityManager(new SecurityManager()); |
c5ba8eff9aca
6972468: Security manager should be used for tests in java/beans/XMLEncoder
malenkov
parents:
5506
diff
changeset
|
41 |
main(); |
c5ba8eff9aca
6972468: Security manager should be used for tests in java/beans/XMLEncoder
malenkov
parents:
5506
diff
changeset
|
42 |
} |
c5ba8eff9aca
6972468: Security manager should be used for tests in java/beans/XMLEncoder
malenkov
parents:
5506
diff
changeset
|
43 |
|
c5ba8eff9aca
6972468: Security manager should be used for tests in java/beans/XMLEncoder
malenkov
parents:
5506
diff
changeset
|
44 |
private static void main() throws Exception { |
2 | 45 |
// the DefaultMutableTreeNode will archive correctly |
46 |
new Test4631471() { |
|
47 |
protected Object getObject() { |
|
48 |
return getRoot(); |
|
49 |
} |
|
50 |
}.test(false); |
|
51 |
||
52 |
// the DefaultTreeModel will also archive correctly |
|
53 |
new Test4631471() { |
|
54 |
protected Object getObject() { |
|
55 |
return getModel(); |
|
56 |
} |
|
57 |
}.test(false); |
|
58 |
||
59 |
// create a new model from the root node |
|
60 |
// this simulates the the MetaData ctor: |
|
61 |
// registerConstructor("javax.swing.tree.DefaultTreeModel", new String[]{"root"}); |
|
62 |
new Test4631471() { |
|
63 |
protected Object getObject() { |
|
64 |
return new DefaultTreeModel((TreeNode) getModel().getRoot()); |
|
65 |
} |
|
66 |
}.test(false); |
|
67 |
||
68 |
// the JTree will archive correctly too |
|
69 |
new Test4631471() { |
|
70 |
protected Object getObject() { |
|
71 |
return getTree(); |
|
72 |
} |
|
73 |
}.test(false); |
|
74 |
} |
|
75 |
||
76 |
protected final void validate(Object before, Object after) { |
|
77 |
// do not any validation |
|
78 |
} |
|
79 |
||
80 |
public static TreeNode getRoot() { |
|
81 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("root"); |
|
82 |
DefaultMutableTreeNode first = new DefaultMutableTreeNode("first"); |
|
83 |
DefaultMutableTreeNode second = new DefaultMutableTreeNode("second"); |
|
84 |
DefaultMutableTreeNode third = new DefaultMutableTreeNode("third"); |
|
85 |
||
86 |
first.add(new DefaultMutableTreeNode("1.1")); |
|
87 |
first.add(new DefaultMutableTreeNode("1.2")); |
|
88 |
first.add(new DefaultMutableTreeNode("1.3")); |
|
89 |
||
90 |
second.add(new DefaultMutableTreeNode("2.1")); |
|
91 |
second.add(new DefaultMutableTreeNode("2.2")); |
|
92 |
second.add(new DefaultMutableTreeNode("2.3")); |
|
93 |
||
94 |
third.add(new DefaultMutableTreeNode("3.1")); |
|
95 |
third.add(new DefaultMutableTreeNode("3.2")); |
|
96 |
third.add(new DefaultMutableTreeNode("3.3")); |
|
97 |
||
98 |
node.add(first); |
|
99 |
node.add(second); |
|
100 |
node.add(third); |
|
101 |
||
102 |
return node; |
|
103 |
} |
|
104 |
||
105 |
public static JTree getTree() { |
|
106 |
return new JTree(getRoot()); |
|
107 |
} |
|
108 |
||
109 |
public static TreeModel getModel() { |
|
110 |
return getTree().getModel(); |
|
111 |
} |
|
112 |
} |