You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextAreaDeclarativeTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.server.component.textarea;
  17. import java.io.IOException;
  18. import org.jsoup.nodes.Element;
  19. import org.jsoup.parser.Tag;
  20. import org.junit.Test;
  21. import com.vaadin.tests.server.component.abstracttextfield.AbstractTextFieldDeclarativeTest;
  22. import com.vaadin.ui.TextArea;
  23. import com.vaadin.ui.declarative.DesignContext;
  24. /**
  25. * Tests declarative support for implementations of {@link TextArea}.
  26. *
  27. * @since 7.4
  28. * @author Vaadin Ltd
  29. */
  30. public class TextAreaDeclarativeTest
  31. extends AbstractTextFieldDeclarativeTest<TextArea> {
  32. @Override
  33. public void valueDeserialization()
  34. throws InstantiationException, IllegalAccessException {
  35. String value = "Hello World!";
  36. String design = String.format("<%s>%s</%s>", getComponentTag(), value,
  37. getComponentTag());
  38. TextArea component = new TextArea();
  39. component.setValue(value);
  40. testRead(design, component);
  41. testWrite(design, component);
  42. }
  43. @Override
  44. public void readOnlyValue()
  45. throws InstantiationException, IllegalAccessException {
  46. String value = "Hello World!";
  47. String design = String.format("<%s readonly>%s</%s>", getComponentTag(),
  48. value, getComponentTag());
  49. TextArea component = new TextArea();
  50. component.setValue(value);
  51. component.setReadOnly(true);
  52. testRead(design, component);
  53. testWrite(design, component);
  54. }
  55. @Test
  56. public void testHtmlEntities() throws IOException {
  57. String design = "<vaadin-text-area>&amp; Test</vaadin-text-area>";
  58. TextArea read = read(design);
  59. assertEquals("& Test", read.getValue());
  60. read.setValue("&amp; Test");
  61. DesignContext dc = new DesignContext();
  62. Element root = new Element(Tag.valueOf("vaadin-text-area"), "");
  63. read.writeDesign(root, dc);
  64. assertEquals("&amp;amp; Test", root.html());
  65. }
  66. @Test
  67. public void remainingAttriburesDeserialization() {
  68. int rows = 11;
  69. boolean wrap = false;
  70. String design = String.format("<%s rows='%s' word-wrap='%s'/>",
  71. getComponentTag(), rows, wrap);
  72. TextArea component = new TextArea();
  73. component.setRows(rows);
  74. component.setWordWrap(wrap);
  75. testRead(design, component);
  76. testWrite(design, component);
  77. }
  78. @Override
  79. protected String getComponentTag() {
  80. return "vaadin-text-area";
  81. }
  82. @Override
  83. protected Class<TextArea> getComponentClass() {
  84. return TextArea.class;
  85. }
  86. }