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.

ReadEmptyDesignTest.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.vaadin.tests.server.component;
  2. import static org.junit.Assert.assertNotNull;
  3. import static org.junit.Assert.assertNull;
  4. import static org.junit.Assert.fail;
  5. import java.io.ByteArrayInputStream;
  6. import java.io.InputStream;
  7. import org.jsoup.nodes.Document;
  8. import org.jsoup.nodes.DocumentType;
  9. import org.jsoup.nodes.Element;
  10. import org.junit.Before;
  11. import org.junit.Test;
  12. import com.vaadin.ui.Component;
  13. import com.vaadin.ui.VerticalLayout;
  14. import com.vaadin.ui.declarative.Design;
  15. import com.vaadin.ui.declarative.DesignContext;
  16. import com.vaadin.ui.declarative.DesignException;
  17. /**
  18. * Test cases for checking that reading a design with no elements in the html
  19. * body produces null as the root component.
  20. */
  21. public class ReadEmptyDesignTest {
  22. InputStream is;
  23. @Before
  24. public void setUp() {
  25. String html = createDesign().toString();
  26. is = new ByteArrayInputStream(html.getBytes());
  27. }
  28. @Test
  29. public void testReadComponent() {
  30. Component root = Design.read(is);
  31. assertNull("The root component should be null.", root);
  32. }
  33. @Test
  34. public void testReadContext() {
  35. DesignContext ctx = Design.read(is, null);
  36. assertNotNull("The design context should not be null.", ctx);
  37. assertNull("The root component should be null.",
  38. ctx.getRootComponent());
  39. }
  40. @Test
  41. public void testReadContextWithRootParameter() {
  42. try {
  43. Component rootComponent = new VerticalLayout();
  44. DesignContext ctx = Design.read(is, rootComponent);
  45. fail("Reading a design with no elements should fail when a non-null root Component is specified.");
  46. } catch (DesignException e) {
  47. // This is the expected outcome, nothing to do.
  48. }
  49. }
  50. private Document createDesign() {
  51. Document doc = new Document("");
  52. DocumentType docType = new DocumentType("html", "", "");
  53. doc.appendChild(docType);
  54. Element html = doc.createElement("html");
  55. doc.appendChild(html);
  56. html.appendChild(doc.createElement("head"));
  57. html.appendChild(doc.createElement("body"));
  58. return doc;
  59. }
  60. }