Path: blob/master/test/jdk/java/beans/XMLEncoder/Test4631471.java
41152 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4631471 697246826* @summary Tests DefaultTreeModel encoding27* @run main/othervm -Djava.security.manager=allow Test463147128* @author Sergey Malenkov, Mark Davidson29*/3031import javax.swing.JTree;32import javax.swing.tree.DefaultMutableTreeNode;33import javax.swing.tree.DefaultTreeModel;34import javax.swing.tree.TreeModel;35import javax.swing.tree.TreeNode;3637public abstract class Test4631471 extends AbstractTest {38public static void main(String[] args) throws Exception {39main();40System.setSecurityManager(new SecurityManager());41main();42}4344private static void main() throws Exception {45// the DefaultMutableTreeNode will archive correctly46new Test4631471() {47protected Object getObject() {48return getRoot();49}50}.test(false);5152// the DefaultTreeModel will also archive correctly53new Test4631471() {54protected Object getObject() {55return getModel();56}57}.test(false);5859// create a new model from the root node60// this simulates the the MetaData ctor:61// registerConstructor("javax.swing.tree.DefaultTreeModel", new String[]{"root"});62new Test4631471() {63protected Object getObject() {64return new DefaultTreeModel((TreeNode) getModel().getRoot());65}66}.test(false);6768// the JTree will archive correctly too69new Test4631471() {70protected Object getObject() {71return getTree();72}73}.test(false);74}7576protected final void validate(Object before, Object after) {77// do not any validation78}7980public static TreeNode getRoot() {81DefaultMutableTreeNode node = new DefaultMutableTreeNode("root");82DefaultMutableTreeNode first = new DefaultMutableTreeNode("first");83DefaultMutableTreeNode second = new DefaultMutableTreeNode("second");84DefaultMutableTreeNode third = new DefaultMutableTreeNode("third");8586first.add(new DefaultMutableTreeNode("1.1"));87first.add(new DefaultMutableTreeNode("1.2"));88first.add(new DefaultMutableTreeNode("1.3"));8990second.add(new DefaultMutableTreeNode("2.1"));91second.add(new DefaultMutableTreeNode("2.2"));92second.add(new DefaultMutableTreeNode("2.3"));9394third.add(new DefaultMutableTreeNode("3.1"));95third.add(new DefaultMutableTreeNode("3.2"));96third.add(new DefaultMutableTreeNode("3.3"));9798node.add(first);99node.add(second);100node.add(third);101102return node;103}104105public static JTree getTree() {106return new JTree(getRoot());107}108109public static TreeModel getModel() {110return getTree().getModel();111}112}113114115