Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/Test4631471.java
38812 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* @author Sergey Malenkov, Mark Davidson28*/2930import javax.swing.JTree;31import javax.swing.tree.DefaultMutableTreeNode;32import javax.swing.tree.DefaultTreeModel;33import javax.swing.tree.TreeModel;34import javax.swing.tree.TreeNode;3536public abstract class Test4631471 extends AbstractTest {37public static void main(String[] args) throws Exception {38main();39System.setSecurityManager(new SecurityManager());40main();41}4243private static void main() throws Exception {44// the DefaultMutableTreeNode will archive correctly45new Test4631471() {46protected Object getObject() {47return getRoot();48}49}.test(false);5051// the DefaultTreeModel will also archive correctly52new Test4631471() {53protected Object getObject() {54return getModel();55}56}.test(false);5758// create a new model from the root node59// this simulates the the MetaData ctor:60// registerConstructor("javax.swing.tree.DefaultTreeModel", new String[]{"root"});61new Test4631471() {62protected Object getObject() {63return new DefaultTreeModel((TreeNode) getModel().getRoot());64}65}.test(false);6667// the JTree will archive correctly too68new Test4631471() {69protected Object getObject() {70return getTree();71}72}.test(false);73}7475protected final void validate(Object before, Object after) {76// do not any validation77}7879public static TreeNode getRoot() {80DefaultMutableTreeNode node = new DefaultMutableTreeNode("root");81DefaultMutableTreeNode first = new DefaultMutableTreeNode("first");82DefaultMutableTreeNode second = new DefaultMutableTreeNode("second");83DefaultMutableTreeNode third = new DefaultMutableTreeNode("third");8485first.add(new DefaultMutableTreeNode("1.1"));86first.add(new DefaultMutableTreeNode("1.2"));87first.add(new DefaultMutableTreeNode("1.3"));8889second.add(new DefaultMutableTreeNode("2.1"));90second.add(new DefaultMutableTreeNode("2.2"));91second.add(new DefaultMutableTreeNode("2.3"));9293third.add(new DefaultMutableTreeNode("3.1"));94third.add(new DefaultMutableTreeNode("3.2"));95third.add(new DefaultMutableTreeNode("3.3"));9697node.add(first);98node.add(second);99node.add(third);100101return node;102}103104public static JTree getTree() {105return new JTree(getRoot());106}107108public static TreeModel getModel() {109return getTree().getModel();110}111}112113114