📄 ajaxlinktest.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.ajax.markup.html.ajaxLink;import org.apache.wicket.Component;import org.apache.wicket.Page;import org.apache.wicket.WicketTestCase;import org.apache.wicket.behavior.AbstractAjaxBehavior;import org.apache.wicket.util.tester.TagTester;/** * */public class AjaxLinkTest extends WicketTestCase{ /** * Construct. * * @param name */ public AjaxLinkTest(String name) { super(name); } /** * If the AjaxLink is attached to an "a" tag the href value should be replaced with "#" because * we use the onclick to execute the javascript. */ public void testAnchorGetsHrefReplaced() { tester.startPage(AjaxLinkPage.class); TagTester ajaxLink = tester.getTagByWicketId("ajaxLink"); // It was a link to google in the markup, but should be replaced to "#" assertTrue(ajaxLink.getAttributeIs("href", "#")); } /** * Tests setting the request target to a normal page request from an ajax request. */ public void testFromAjaxRequestToNormalPage() { tester.startPage(AjaxLinkPageToNormalPage.class); tester.assertRenderedPage(AjaxLinkPageToNormalPage.class); Page page = tester.getLastRenderedPage(); Component ajaxLink = page.get("ajaxLink"); AbstractAjaxBehavior behavior = (AbstractAjaxBehavior)ajaxLink.getBehaviors().get(0); tester.executeBehavior(behavior); tester.assertRenderedPage(NormalPage.class); } /** * Test that the onclick on ajax link has "return !wcall;" at the end. This ensures that * execution is not turned over to the href attribute, which would then append # to the url. */ public void testJavascriptEndsWithReturn() { tester.startPage(AjaxLinkPage.class); TagTester ajaxLink = tester.getTagByWicketId("ajaxLink"); assertTrue(ajaxLink.getAttributeEndsWith("onclick", "return !wcall;")); } /** * * @throws Exception */ public void testPage_2() throws Exception { executeTest(AjaxPage2.class, "AjaxPage2_ExpectedResult.html"); Page page = tester.getLastRenderedPage(); Component ajaxLink = page.get("ajaxLink"); AbstractAjaxBehavior behavior = (AbstractAjaxBehavior)ajaxLink.getBehaviors().get(0); executedBehavior(AjaxPage2.class, behavior, "AjaxPage2-1_ExpectedResult.html"); } /** * * @throws Exception */ public void testRenderHomePage_1() throws Exception { executeTest(AjaxLinkPage.class, "AjaxLinkPageExpectedResult.html"); } /** * * @throws Exception */ public void testRenderHomePage_2() throws Exception { executeTest(AjaxLinkWithBorderPage.class, "AjaxLinkWithBorderPageExpectedResult.html"); Page page = tester.getLastRenderedPage(); Component ajaxLink = page.get("ajaxLink"); AbstractAjaxBehavior behavior = (AbstractAjaxBehavior)ajaxLink.getBehaviors().get(0); executedBehavior(AjaxPage2.class, behavior, "AjaxLinkWithBorderPage-1ExpectedResult.html"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -