Package org.apache.wicket.markup.html.border

Source Code of org.apache.wicket.markup.html.border.BoxBorderTest

/*
* 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.border;

import org.apache.wicket.Application;
import org.apache.wicket.Page;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.WicketTestCase;
import org.apache.wicket.markup.MarkupException;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.protocol.http.MockHttpServletRequest;
import org.apache.wicket.settings.IMarkupSettings;

/**
* Test the component: PageView
*
* @author Juergen Donnerstag
*/
public class BoxBorderTest extends WicketTestCase
{
  /**
   * Create the test.
   *
   * @param name
   *            The test name
   */
  public BoxBorderTest(String name)
  {
    super(name);
  }

  /**
   * Test a simply page containing the debug component
   *
   * @throws Exception
   */
  public void test1() throws Exception
  {
    executeTest(BoxBorderTestPage_1.class, "BoxBorderTestPage_ExpectedResult_1.html");
  }

  /**
   * Test a simply page containing the debug component
   *
   * @throws Exception
   */
  public void test2() throws Exception
  {
    executeTest(BoxBorderTestPage_2.class, "BoxBorderTestPage_ExpectedResult_2.html");
  }

  /**
   * Test a simply page containing the debug component
   *
   * @throws Exception
   */
  @SuppressWarnings( { "unchecked" })
  public void test3() throws Exception
  {
    executeTest(BoxBorderTestPage_3.class, "BoxBorderTestPage_ExpectedResult_3.html");

    Border border = (Border)tester.getLastRenderedPage().get("border");
    assertNotNull(border);
    Form<?> form = (Form<?>)tester.getLastRenderedPage().get("border:myForm");

    TextField<String> input = (TextField<String>)tester.getLastRenderedPage()
      .get("border:name");
    assertEquals("", input.getDefaultModelObjectAsString());

    tester.setupRequestAndResponse();

    MockHttpServletRequest mockRequest = tester.getServletRequest();
    mockRequest.setRequestToComponent(form);
    mockRequest.setParameter(input.getInputName(), "jdo");

    tester.processRequestCycle();

    input = (TextField<String>)tester.getLastRenderedPage().get("border:name");
    assertEquals("jdo", input.getDefaultModelObjectAsString());
  }

  /**
   * Test to ensure MarkupException is thrown when Markup and Object hierarchy does not match with
   * a Border involved.
   *
   * @throws Exception
   */
  public void test4() throws Exception
  {
    Class<? extends Page> pageClass = BorderTestHierarchyPage_4.class;

    System.out.println("=== " + pageClass.getName() + " ===");

    MarkupException markupException = null;
    try
    {
      tester.startPage(pageClass);
    }
    catch (MarkupException e)
    {
      markupException = e;
    }

    assertNotNull("Markup does not match component hierarchy, but exception not thrown.",
      markupException);
  }

  /**
   * Test to ensure border render wrapped settings functions properly.
   *
   * @throws Exception
   */
  public void testRenderWrapped() throws Exception
  {
    executeTest(BorderRenderWrappedTestPage_1.class,
      "BorderRenderWrappedTestPage_ExpectedResult_1.html");
  }

  /**
   * Test a simply page containing the debug component
   *
   * @throws Exception
   */
  public void test5() throws Exception
  {
    executeTest(BoxBorderTestPage_5.class, "BoxBorderTestPage_ExpectedResult_5.html");
  }

  /**
   * Test a simply page containing the debug component
   *
   * @throws Exception
   */
  public void test6() throws Exception
  {
    executeTest(BoxBorderTestPage_6.class, "BoxBorderTestPage_ExpectedResult_6.html");
  }

  /**
   * Test a simply page containing the debug component
   *
   * @throws Exception
   */
  public void test7() throws Exception
  {
    final IMarkupSettings markupSettings = Application.get().getMarkupSettings();
    markupSettings.setCompressWhitespace(true);
    markupSettings.setStripComments(true);
    markupSettings.setStripWicketTags(true);
    markupSettings.setStripXmlDeclarationFromOutput(true);

    executeTest(BoxBorderTestPage_1.class, "BoxBorderTestPage_ExpectedResult_7.html");
  }

  /**
   * Test a simply page containing the debug component
   *
   * @throws Exception
   */
  public void test8() throws Exception
  {
    executeTest(BoxBorderTestPage_8.class, "BoxBorderTestPage_ExpectedResult_8.html");
  }

  /**
   * Test a simply page containing the debug component
   *
   * @throws Exception
   */
  public void test9() throws Exception
  {
    executeTest(BoxBorderTestPage_9.class, "BoxBorderTestPage_ExpectedResult_9.html");
  }

  /**
   * @throws Exception
   */
  public void test10() throws Exception
  {
    Exception e = null;
    try
    {
      executeTest(BoxBorderTestPage_10.class, "BoxBorderTestPage_ExpectedResult_10.html");
    }
    catch (WicketRuntimeException ex)
    {
      if (ex.getMessage().startsWith("The border tag must be an open tag."))
      {
        e = ex;
      }
    }
    assertNotNull(
      "Expected a WicketRuntimeException. Border tag must be open tags. Open-close tags are not allowed",
      e);
  }
}
TOP

Related Classes of org.apache.wicket.markup.html.border.BoxBorderTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.