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.

FieldNameWhichConflictsWithGettersTest.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.design;
  17. import java.io.ByteArrayOutputStream;
  18. import java.io.IOException;
  19. import org.jsoup.Jsoup;
  20. import org.jsoup.nodes.Document;
  21. import org.jsoup.nodes.Element;
  22. import org.junit.Assert;
  23. import org.junit.Test;
  24. import com.vaadin.annotations.DesignRoot;
  25. import com.vaadin.ui.Label;
  26. import com.vaadin.ui.TextField;
  27. import com.vaadin.ui.VerticalLayout;
  28. import com.vaadin.ui.declarative.Design;
  29. import com.vaadin.ui.declarative.DesignContext;
  30. public class FieldNameWhichConflictsWithGettersTest {
  31. @DesignRoot("MyVerticalLayout.html")
  32. public static class MyVerticalLayout extends VerticalLayout {
  33. private Label caption;
  34. private TextField description;
  35. public MyVerticalLayout() {
  36. Design.read(this);
  37. }
  38. }
  39. @Test
  40. public void readWithConflictingFields() {
  41. MyVerticalLayout v = new MyVerticalLayout();
  42. Assert.assertNotNull(v.caption);
  43. Assert.assertNotNull(v.description);
  44. }
  45. @Test
  46. public void writeWithConflictingFields() throws IOException {
  47. VerticalLayout v = new VerticalLayout();
  48. Label l = new Label();
  49. l.setId("caption");
  50. TextField tf = new TextField();
  51. v.addComponents(l, tf);
  52. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  53. DesignContext context = new DesignContext();
  54. context.setComponentLocalId(tf, "description");
  55. context.setRootComponent(v);
  56. Design.write(context, baos);
  57. String str = baos.toString("UTF-8");
  58. Document doc = Jsoup.parse(str);
  59. Element body = doc.body();
  60. Element captionElement = body.getElementById("caption");
  61. Assert.assertNotNull(captionElement);
  62. Assert.assertEquals("vaadin-label", captionElement.tagName());
  63. Element descriptionElement = captionElement.nextElementSibling();
  64. Assert.assertNotNull(descriptionElement);
  65. Assert.assertEquals("vaadin-text-field", descriptionElement.tagName());
  66. Assert.assertEquals("description", descriptionElement.attr("_id"));
  67. }
  68. }