Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TestReadDesign.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2000-2014 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.absolutelayout;
  17. import java.util.Iterator;
  18. import junit.framework.TestCase;
  19. import org.jsoup.nodes.Attributes;
  20. import org.jsoup.nodes.Element;
  21. import org.jsoup.parser.Tag;
  22. import com.vaadin.server.Sizeable;
  23. import com.vaadin.ui.AbsoluteLayout;
  24. import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
  25. import com.vaadin.ui.Component;
  26. import com.vaadin.ui.declarative.DesignContext;
  27. /**
  28. * Test case for reading AbsoluteLayout from design
  29. *
  30. * @since
  31. * @author Vaadin Ltd
  32. */
  33. public class TestReadDesign extends TestCase {
  34. private AbsoluteLayout root;
  35. @Override
  36. public void setUp() throws Exception {
  37. super.setUp();
  38. root = createLayout();
  39. }
  40. public void testAttributes() {
  41. assertEquals("test-layout", root.getCaption());
  42. Iterator<Component> children = root.iterator();
  43. assertEquals("test-label", children.next().getCaption());
  44. assertEquals("test-button", children.next().getCaption());
  45. }
  46. public void testTopLeftPosition() {
  47. ComponentPosition position = root.getPosition(root.iterator().next());
  48. assertEquals(Sizeable.Unit.PIXELS, position.getTopUnits());
  49. assertEquals(100.0f, position.getTopValue());
  50. assertEquals(Sizeable.Unit.PERCENTAGE, position.getLeftUnits());
  51. assertEquals(50.0f, position.getLeftValue());
  52. }
  53. public void testBottomRightPosition() {
  54. Iterator<Component> children = root.iterator();
  55. children.next();
  56. ComponentPosition position = root.getPosition(children.next());
  57. assertEquals(Sizeable.Unit.PIXELS, position.getBottomUnits());
  58. assertEquals(100.0f, position.getBottomValue());
  59. assertEquals(Sizeable.Unit.PERCENTAGE, position.getRightUnits());
  60. assertEquals(50.0f, position.getRightValue());
  61. }
  62. public void testZIndex() {
  63. ComponentPosition position = root.getPosition(root.iterator().next());
  64. assertEquals(2, position.getZIndex());
  65. }
  66. private AbsoluteLayout createLayout() {
  67. DesignContext ctx = new DesignContext();
  68. Element design = createDesign();
  69. Component child = ctx.readDesign(design);
  70. return (AbsoluteLayout) child;
  71. }
  72. private Element createDesign() {
  73. Attributes rootAttributes = new Attributes();
  74. rootAttributes.put("caption", "test-layout");
  75. Element node = new Element(Tag.valueOf("v-absolute-layout"), "",
  76. rootAttributes);
  77. Attributes firstChildAttributes = new Attributes();
  78. firstChildAttributes.put("caption", "test-label");
  79. firstChildAttributes.put(":top", "100px");
  80. firstChildAttributes.put(":left", "50%");
  81. firstChildAttributes.put(":z-index", "2");
  82. Element firstChild = new Element(Tag.valueOf("v-label"), "",
  83. firstChildAttributes);
  84. node.appendChild(firstChild);
  85. Attributes secondChildAttributes = new Attributes();
  86. secondChildAttributes.put(":bottom", "100px");
  87. secondChildAttributes.put(":right", "50%");
  88. Element secondChild = new Element(Tag.valueOf("v-button"), "",
  89. secondChildAttributes);
  90. secondChild.html("test-button");
  91. node.appendChild(secondChild);
  92. return node;
  93. }
  94. }