Path: blob/master/test/jdk/java/beans/XMLDecoder/spec/TestObject.java
41155 views
/*1* Copyright (c) 2008, 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* @summary Tests <object> element26* @run main/othervm -Djava.security.manager=allow TestObject27* @author Sergey Malenkov28*/2930import java.beans.XMLDecoder;31import javax.swing.JButton;32import javax.swing.JLabel;33import javax.swing.JPanel;34import javax.swing.SwingConstants;3536public final class TestObject extends AbstractTest {37public static final String XML // TODO38= "<java>\n"39+ " <object class=\"javax.swing.JPanel\">\n"40+ " <void method=\"add\">\n"41+ " <object id=\"button\" class=\"javax.swing.JButton\">\n"42+ " <string>button</string>\n"43+ " <void property=\"verticalAlignment\">\n"44+ " <object field=\"CENTER\" class=\"javax.swing.SwingConstants\"/>\n"45+ " </void>\n"46+ " </object>\n"47+ " </void>\n"48+ " <void method=\"add\">\n"49+ " <object class=\"javax.swing.JLabel\">\n"50+ " <string>label</string>\n"51+ " <void property=\"labelFor\">\n"52+ " <object idref=\"button\"/>\n"53+ " </void>\n"54+ " </object>\n"55+ " </void>\n"56+ " </object>\n"57+ "</java>";5859public static void main(String[] args) {60new TestObject().test(true);61}6263@Override64protected void validate(XMLDecoder decoder) {65JPanel panel = (JPanel) decoder.readObject();66if (2 != panel.getComponents().length) {67throw new Error("unexpected component count");68}69JButton button = (JButton) panel.getComponents()[0];70if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML71throw new Error("unexpected button text");72}73if (SwingConstants.CENTER != button.getVerticalAlignment()) {74throw new Error("unexpected vertical alignment");75}76JLabel label = (JLabel) panel.getComponents()[1];77if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML78throw new Error("unexpected label text");79}80if (button != label.getLabelFor()) {81throw new Error("unexpected component");82}83}84}858687