Пример #1
0
  public void testMultiple() throws Exception {
    TestAction testAction = (TestAction) action;
    Collection collection = new ArrayList(2);
    collection.add("hello");
    collection.add("foo");
    testAction.setCollection(collection);
    testAction.setList(
        new String[][] {
          {"hello", "world"},
          {"foo", "bar"},
          {"cat", "dog"}
        });

    SelectTag tag = new SelectTag();
    tag.setPageContext(pageContext);
    tag.setLabel("mylabel");
    tag.setName("collection");
    tag.setList("list");
    tag.setListKey("top[0]");
    tag.setListValue("top[1]");
    tag.setMultiple("true");
    tag.setOnmousedown("alert('onmousedown');");
    tag.setOnmousemove("alert('onmousemove');");
    tag.setOnmouseout("alert('onmouseout');");
    tag.setOnmouseover("alert('onmouseover');");
    tag.setOnmouseup("alert('onmouseup');");

    tag.doStartTag();
    tag.doEndTag();

    verify(SelectTag.class.getResource("Select-2.txt"));
  }
Пример #2
0
  public void testSimpleRoundingCeiling() throws Exception {
    // given
    context.put(ActionContext.LOCALE, Locale.US);

    TestAction testAction = (TestAction) action;
    testAction.setFloatNumber(120.45f);

    NumberTag tag = new NumberTag();
    tag.setPageContext(pageContext);
    tag.setName("floatNumber");
    tag.setRoundingMode("ceiling");

    // when
    tag.doStartTag();
    tag.doEndTag();

    // then
    NumberFormat format = NumberFormat.getInstance((Locale) context.get(ActionContext.LOCALE));
    /*
    TODO lukaszlenart: enable when switched to Java 1.6
    format.setRoundingMode(RoundingMode.CEILING);
    */
    String expected = format.format(120.45f);

    assertEquals(expected, writer.toString());
  }
Пример #3
0
  /**
   * WW-1747 - should be a valid test case for the described issue
   *
   * @throws Exception
   */
  public void testMultipleWithLists() throws Exception {
    TestAction testAction = (TestAction) action;
    Collection collection = new ArrayList(2);

    collection.add(1l);
    collection.add(300000000l);
    testAction.setCollection(collection);

    List selectList = new ArrayList();
    selectList.add(new LongObject(1l, "foo"));
    selectList.add(new LongObject(2l, "bar"));
    selectList.add(new LongObject(300000000l, "foobar"));
    testAction.setList2(selectList);

    SelectTag tag = new SelectTag();
    tag.setPageContext(pageContext);
    tag.setLabel("mylabel");
    tag.setName("collection");
    tag.setList("list2");
    tag.setListKey("id");
    tag.setListValue("value");
    tag.setMultiple("true");
    tag.setOnmousedown("alert('onmousedown');");
    tag.setOnmousemove("alert('onmousemove');");
    tag.setOnmouseout("alert('onmouseout');");
    tag.setOnmouseover("alert('onmouseover');");
    tag.setOnmouseup("alert('onmouseup');");

    tag.doStartTag();
    tag.doEndTag();

    verify(SelectTag.class.getResource("Select-12.txt"));
  }
Пример #4
0
  public void testSimpleWithNulls() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("hello");
    testAction.setList(
        new String[][] {
          {"hello", null},
          {null, "bar"}
        });

    SelectTag tag = new SelectTag();
    tag.setPageContext(pageContext);
    tag.setEmptyOption("true");
    tag.setLabel("mylabel");
    tag.setName("foo");
    tag.setList("list");
    tag.setListKey("top[0]");
    tag.setListValue("top[1]");

    // header stuff
    tag.setHeaderKey("headerKey");
    tag.setHeaderValue("headerValue");

    // empty option
    tag.setEmptyOption("true");

    tag.doStartTag();
    tag.doEndTag();

    verify(SelectTag.class.getResource("Select-9.txt"));
  }
Пример #5
0
  public void testSimpleIntegerWithValueWorkaround() throws Exception {
    TestAction testAction = (TestAction) action;

    IdName hello = new IdName(new Integer(1), "hello");
    IdName world = new IdName(new Integer(2), "world");
    List list2 = new ArrayList();
    list2.add(hello);
    list2.add(world);
    testAction.setList2(list2);

    testAction.setFooInt(new Integer(1));

    SelectTag tag = new SelectTag();
    tag.setPageContext(pageContext);
    tag.setEmptyOption("true");
    tag.setLabel("mylabel");
    tag.setName("fooInt");
    tag.setList("list2");
    tag.setListKey("id");
    tag.setListValue("name");
    tag.setValue("fooInt.toString()");

    // header stuff
    tag.setHeaderKey("headerKey");
    tag.setHeaderValue("headerValue");

    // empty option
    tag.setEmptyOption("true");

    tag.doStartTag();
    tag.doEndTag();

    verify(SelectTag.class.getResource("Select-11.txt"));
  }
Пример #6
0
  public void testExtended() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("hello");
    testAction.setList(
        new String[][] {
          {"hello", "world"},
          {"foo", "bar"}
        });

    SelectTag tag = new SelectTag();
    tag.setPageContext(pageContext);
    tag.setEmptyOption("true");
    tag.setLabel("mylabel");
    tag.setName("foo");
    tag.setList("list");
    tag.setListKey("top[0]");
    tag.setListValue("%{top[0] + ' - ' + top[1]}");

    // header stuff
    tag.setHeaderKey("headerKey");
    tag.setHeaderValue("%{foo + ': headerValue'}");

    // empty option
    tag.setEmptyOption("true");

    tag.doStartTag();
    tag.doEndTag();

    verify(SelectTag.class.getResource("Select-7.txt"));
  }
Пример #7
0
  private void prepareTagGeneric(SelectTag tag) {
    TestAction testAction = (TestAction) action;
    ArrayList collection = new ArrayList();
    collection.add("foo");
    collection.add("bar");
    collection.add("baz");

    testAction.setCollection(collection);

    tag.setList("collection");
  }
Пример #8
0
  public void testSimple_recursionTestNoValue() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("%{1+1}");

    TextFieldTag tag = new TextFieldTag();
    tag.setPageContext(pageContext);
    tag.setLabel("mylabel");
    tag.setName("foo");
    tag.setSize("10");

    tag.doStartTag();
    tag.doEndTag();

    verify(TextFieldTag.class.getResource("Textfield-6.txt"));
  }
Пример #9
0
  public void testButtonSimple() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("bar");

    ResetTag tag = new ResetTag();
    tag.setPageContext(pageContext);
    tag.setType("button");
    tag.setName("myname");
    tag.setValue("%{foo}");

    tag.doStartTag();
    tag.doEndTag();

    verify(TextFieldTag.class.getResource("Reset-3.txt"));
  }
Пример #10
0
  public void testEmptyList() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setList2(new ArrayList());

    SelectTag tag = new SelectTag();
    tag.setName("collection");
    tag.setList("list2");
    tag.setLabel("tmjee_name");

    tag.setPageContext(pageContext);
    tag.doStartTag();
    tag.doEndTag();

    verify(SelectTag.class.getResource("Select-4.txt"));
  }
Пример #11
0
  public void testDefaultValues() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("bar");

    ResetTag tag = new ResetTag();
    tag.setPageContext(pageContext);
    tag.setLabel("mylabel");
    tag.setName("myname");
    tag.setTitle("mytitle");
    tag.setSrc("/images/test.png");

    tag.doStartTag();
    tag.doEndTag();

    verify(TextFieldTag.class.getResource("Reset-2.txt"));
  }
Пример #12
0
  public void testNoLabelFtl() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("bar");

    TextFieldModel model = new TextFieldModel(stack, request, response);
    HashMap params = new HashMap();
    params.put("name", "myname");
    params.put("value", "%{foo}");
    params.put("size", "10");
    params.put("onblur", "blahescape('somevalue');");
    TransformControl control = (TransformControl) model.getWriter(writer, params);
    control.onStart();
    control.afterBody();

    verify(TextFieldTag.class.getResource("Textfield-3.txt"));
  }
Пример #13
0
  public void testNoLabelJsp() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("bar");

    TextFieldTag tag = new TextFieldTag();
    tag.setPageContext(pageContext);
    tag.setName("myname");
    tag.setValue("%{foo}");
    tag.setSize("10");
    tag.setOnblur("blahescape('somevalue');");

    tag.doStartTag();
    tag.doEndTag();

    verify(TextFieldTag.class.getResource("Textfield-3.txt"));
  }
Пример #14
0
  public void testSimple() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("bar");

    ResetTag tag = new ResetTag();
    tag.setPageContext(pageContext);
    tag.setLabel("mylabel");
    tag.setAlign("left");
    tag.setName("myname");
    tag.setValue("%{foo}");

    tag.doStartTag();
    tag.doEndTag();

    verify(TextFieldTag.class.getResource("Reset-1.txt"));
  }
Пример #15
0
  public void testImageWithExpressionSrc() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("bar");

    ResetTag tag = new ResetTag();
    tag.setPageContext(pageContext);
    tag.setType("button");
    tag.setName("myname");
    tag.setLabel("mylabel");
    tag.setValue("%{foo}");
    tag.setSrc("%{getText(\"some.image.from.properties\")}");

    tag.doStartTag();
    tag.doEndTag();

    verify(TextFieldTag.class.getResource("Reset-6.txt"));
  }
Пример #16
0
  public void testErrors() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("bar");

    TextFieldTag tag = new TextFieldTag();
    tag.setPageContext(pageContext);
    tag.setId("myId");
    tag.setLabel("mylabel");
    tag.setName("foo");
    tag.setValue("bar");
    tag.setTitle("mytitle");

    testAction.addFieldError("foo", "bar error message");
    tag.doStartTag();
    tag.doEndTag();

    verify(TextFieldTag.class.getResource("Textfield-2.txt"));
  }
Пример #17
0
  public void testNullList() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setList2(null);

    SelectTag tag = new SelectTag();
    tag.setName("collection");
    tag.setList("list2");
    tag.setLabel("tmjee_name");

    tag.setPageContext(pageContext);
    try {
      tag.doStartTag();
      tag.doEndTag();
      fail("exception should have been thrown value of select tag is null");
    } catch (Exception e) {
      assertTrue(true);
    }
  }
Пример #18
0
  public void testSimpleFloatFormat() throws Exception {
    // given
    context.put(ActionContext.LOCALE, Locale.US);

    TestAction testAction = (TestAction) action;
    testAction.setFloatNumber(120.0f);

    NumberTag tag = new NumberTag();
    tag.setPageContext(pageContext);
    tag.setName("floatNumber");

    // when
    tag.doStartTag();
    tag.doEndTag();

    // then
    assertEquals("120", writer.toString());
  }
Пример #19
0
  public void testSimpleThemeImageUsingMethodOnly() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("bar");

    ResetTag tag = new ResetTag();
    tag.setPageContext(pageContext);
    tag.setTheme("simple");
    tag.setType("button");
    tag.setName("myname");
    tag.setLabel("mylabel");
    tag.setAction(null); // no action
    tag.setMethod("update");
    tag.setAlign("left");

    tag.doStartTag();
    tag.doEndTag();

    verify(TextFieldTag.class.getResource("Reset-9.txt"));
  }
Пример #20
0
  /** Tests WW-455: Select tag template does not work properly for Object like BigDecimal. */
  public void testBigDecimal() throws Exception {
    BigDecimalObject hello = new BigDecimalObject("hello", new BigDecimal(1));
    BigDecimalObject foo = new BigDecimalObject("foo", new BigDecimal(2));

    TestAction testAction = (TestAction) action;

    Collection collection = new ArrayList(2);
    // expect strings to be returned, we're still dealing with HTTP here!
    collection.add("hello");
    collection.add("foo");
    testAction.setCollection(collection);

    List list2 = new ArrayList();
    list2.add(hello);
    list2.add(foo);
    list2.add(new BigDecimalObject("<cat>", new BigDecimal(1.500)));
    testAction.setList2(list2);

    SelectTag tag = new SelectTag();
    tag.setPageContext(pageContext);
    tag.setLabel("mylabel");
    tag.setName("collection");
    tag.setList("list2");
    tag.setListKey("name");
    tag.setListValue("bigDecimal");
    tag.setMultiple("true");
    tag.setTitle("mytitle");
    tag.setOnmousedown("alert('onmousedown');");
    tag.setOnmousemove("alert('onmousemove');");
    tag.setOnmouseout("alert('onmouseout');");
    tag.setOnmouseover("alert('onmouseover');");
    tag.setOnmouseup("alert('onmouseup');");

    tag.doStartTag();
    tag.doEndTag();

    verify(SelectTag.class.getResource("Select-3.txt"));
  }