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.

WriteLegacyDesignTest.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.vaadin.v7.tests.design;
  2. import static org.junit.Assert.assertTrue;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.IOException;
  5. import java.util.Properties;
  6. import org.jsoup.Jsoup;
  7. import org.jsoup.nodes.Document;
  8. import org.jsoup.nodes.Element;
  9. import org.jsoup.nodes.Node;
  10. import org.junit.After;
  11. import org.junit.Before;
  12. import org.junit.Test;
  13. import com.vaadin.server.Constants;
  14. import com.vaadin.server.DefaultDeploymentConfiguration;
  15. import com.vaadin.server.DeploymentConfiguration;
  16. import com.vaadin.server.VaadinService;
  17. import com.vaadin.server.VaadinServletService;
  18. import com.vaadin.ui.declarative.Design;
  19. import com.vaadin.ui.declarative.DesignContext;
  20. import com.vaadin.util.CurrentInstance;
  21. /**
  22. * Parse and write a legacy design (using the "v-" prefix).
  23. */
  24. public class WriteLegacyDesignTest {
  25. // The context is used for accessing the created component hierarchy.
  26. private DesignContext ctx;
  27. @Before
  28. public void setUp() throws Exception {
  29. Properties properties = new Properties();
  30. properties.put(Constants.SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX,
  31. "true");
  32. final DeploymentConfiguration configuration = new DefaultDeploymentConfiguration(
  33. WriteLegacyDesignTest.class, properties);
  34. VaadinService service = new VaadinServletService(null, configuration);
  35. CurrentInstance.set(VaadinService.class, service);
  36. ctx = Design.read(
  37. getClass().getResourceAsStream("testFile-legacy.html"), null);
  38. }
  39. @After
  40. public void tearDown() {
  41. CurrentInstance.set(VaadinService.class, null);
  42. }
  43. private ByteArrayOutputStream serializeDesign(DesignContext context)
  44. throws IOException {
  45. ByteArrayOutputStream out = new ByteArrayOutputStream();
  46. Design.write(context, out);
  47. return out;
  48. }
  49. @Test
  50. public void designIsSerializedWithCorrectPrefixesAndPackageNames()
  51. throws IOException {
  52. ByteArrayOutputStream out = serializeDesign(ctx);
  53. Document doc = Jsoup.parse(out.toString("UTF-8"));
  54. for (Node child : doc.body().childNodes()) {
  55. checkNode(child);
  56. }
  57. }
  58. private void checkNode(Node node) {
  59. if (node instanceof Element) {
  60. assertTrue("Wrong design element prefix",
  61. node.nodeName().startsWith("v-"));
  62. for (Node child : node.childNodes()) {
  63. checkNode(child);
  64. }
  65. }
  66. }
  67. }