⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 radiogrouptest.java

📁 Wicket一个开发Java Web应用程序框架。它使得开发web应用程序变得容易而轻松。 Wicket利用一个POJO data beans组件使得它可以与任何持久层技术相结合。
💻 JAVA
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.wicket.markup.html.form;import java.io.Serializable;import org.apache.wicket.RequestCycle;import org.apache.wicket.WicketRuntimeException;import org.apache.wicket.WicketTestCase;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.model.CompoundPropertyModel;import org.apache.wicket.model.Model;import org.apache.wicket.protocol.http.MockPage;/** * Test for RadioGroup and Radio components *  * @author igor *  */public class RadioGroupTest extends WicketTestCase{	/**	 * @param name	 */	public RadioGroupTest(String name)	{		super(name);	}	/**	 * mock model object with an embedded property used to test compound property model	 * 	 * @author igor	 * 	 */	public static class MockModelObject implements Serializable	{		private static final long serialVersionUID = 1L;		private String prop1;		private String prop2;		/**		 * @return prop1		 */		public String getProp1()		{			return prop1;		}		/**		 * @param prop1		 */		public void setProp1(String prop1)		{			this.prop1 = prop1;		}		/**		 * @return prop2		 */		public String getProp2()		{			return prop2;		}		/**		 * @param prop2		 */		public void setProp2(String prop2)		{			this.prop2 = prop2;		}	}	/**	 * test component form processing	 */	// TODO (Eelco) This is an aweful test. Why is 'mock page' (which isn't a	// real mock, but just some arbitrary page) used rather than a page with	// markup that corresponds to the component structure that is build up?	// Components and markup go together in Wicket, period.	public void testFormProcessing()	{		// setup some values we will use for testing as well as a test model		final String radio1 = "radio1-selection";		// object used to test compound property model		MockModelObject modelObject = new MockModelObject();		// object used to test regular model		Model model = new Model();		// set up necessary objects to emulate a form submission		RequestCycle cycle = tester.createRequestCycle();		// this could have been any page it seems. see comment at method		MockPage page = new MockPage();		// create component hierarchy		final Form form = new Form("form", new CompoundPropertyModel(modelObject))		{			private static final long serialVersionUID = 1L;			public String getMarkupId()			{				// hack for the fact that this test doesn't relate to any markup				return "foo";			}		};		final RadioGroup group = new RadioGroup("prop1");		final WebMarkupContainer container = new WebMarkupContainer("container");		final Radio choice1 = new Radio("radio1", new Model(radio1));		final Radio choice2 = new Radio("prop2");		final RadioGroup group2 = new RadioGroup("group2", model);		final Radio choice3 = new Radio("radio3", new Model(radio1));		page.add(form);		form.add(group);		group.add(container);		container.add(choice1);		group.add(choice2);		form.add(group2);		group2.add(choice3);		// test mock form submissions		modelObject.setProp1(radio1);		form.onFormSubmitted();		assertTrue("group: running with nothing selected - model must be set to null", modelObject				.getProp1() == null);		assertTrue("group2: running with nothing selected - model must be set to null", model				.getObject() == null);		tester.getServletRequest().setParameter(group.getInputName(), choice1.getValue());		tester.getServletRequest().setParameter(group2.getInputName(), choice3.getValue());		form.onFormSubmitted();		assertEquals("group: running with choice1 selected - model must be set to value of radio1",				modelObject.getProp1(), choice1.getModelObject());		assertEquals(				"group2: running with choice3 selected - model must be set to value of radio1",				model.getObject(), choice3.getModelObject());		tester.getServletRequest().setParameter(group.getInputName(), choice2.getValue());		form.onFormSubmitted();		assertEquals("group: running with choice2 selected - model must be set to value of radio2",				modelObject.getProp1(), choice2.getModelObject());		tester.getServletRequest().setParameter(group2.getInputName(), choice1.getValue());		try		{			form.onFormSubmitted();			fail("group2: ran with an invalid choice selected but did not fail");		}		catch (WicketRuntimeException e)		{		}	}	/**	 * test component rendering	 * 	 * @throws Exception	 */	public void testRendering() throws Exception	{		executeTest(RadioGroupTestPage1.class, "RadioGroupTestPage1_expected.html");		try		{			executeTest(RadioGroupTestPage2.class, "");			fail("the rendering of page above must fail because radio2 component is not under any group");		}		catch (WicketRuntimeException e)		{			if (e.getMessage().indexOf(					"Radio component [1:form:radio2] cannot find its parent RadioGroup") < 0)			{				fail("failed with wrong exception");			}		}	}	/**	 * Regression test for markup parsing of radio buttons. Tests issue #1465676.	 * 	 * @throws Exception	 */	public void testRadioGroupTestPage3() throws Exception	{		// this test fails. You can make the test pass by closing the input tags		// this was not the case in beta1		executeTest(RadioGroupTestPage3.class, "RadioGroupTestPage3_expected.html");	}	/**	 * @throws Exception	 */	public void testDisabledRadioGroup() throws Exception	{		executeTest(RadioGroupDisabledTestPage.class, "RadioGroupDisabledTestPage_expected.html");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -