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.

InvalidTagNamesTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.ByteArrayInputStream;
  18. import java.io.UnsupportedEncodingException;
  19. import org.junit.Assert;
  20. import org.junit.Test;
  21. import com.vaadin.ui.Button;
  22. import com.vaadin.ui.Component;
  23. import com.vaadin.ui.declarative.Design;
  24. import com.vaadin.ui.declarative.DesignException;
  25. public class InvalidTagNamesTest {
  26. @Test(expected = DesignException.class)
  27. public void tagWithoutDash() {
  28. readDesign("<vbutton>foo</vbutton>");
  29. }
  30. @Test
  31. public void emptyTag() {
  32. // JSoup parses empty tags into text nodes
  33. Component c = readDesign("<>foo</>");
  34. Assert.assertNull(c);
  35. }
  36. @Test(expected = DesignException.class)
  37. public void onlyPrefix() {
  38. readDesign("<vaadin->foo</vaadin->");
  39. }
  40. @Test
  41. public void onlyClass() {
  42. // JSoup will refuse to parse tags starting with - and convert them into
  43. // text nodes instead
  44. Component c = readDesign("<-v>foo</-v>");
  45. Assert.assertNull(c);
  46. }
  47. @Test(expected = DesignException.class)
  48. public void unknownClass() {
  49. readDesign("<vaadin-unknownbutton>foo</vaadin-unknownbutton>");
  50. }
  51. @Test(expected = DesignException.class)
  52. public void unknownTag() {
  53. readDesign("<x-button></x-button>");
  54. }
  55. // @Test(expected = DesignException.class)
  56. // This is a side effect of not actively checking for invalid input. Will be
  57. // parsed currently as <vaadin-button> (this should not be considered API)
  58. public void tagEndsInDash() {
  59. Component c = readDesign("<vaadin-button-></vaadin-button->");
  60. Assert.assertTrue(c.getClass() == Button.class);
  61. }
  62. // @Test(expected = DesignException.class)
  63. // This is a side effect of not actively checking for invalid input. Will be
  64. // parsed currently as <vaadin-button> (this should not be considered API)
  65. public void tagEndsInTwoDashes() {
  66. Component c = readDesign("<vaadin-button--></vaadin-button-->");
  67. Assert.assertTrue(c.getClass() == Button.class);
  68. }
  69. // @Test(expected = DesignException.class)
  70. // This is a side effect of not actively checking for invalid input. Will be
  71. // parsed currently as <vaadin-button> (this should not be considered API)
  72. public void tagWithTwoDashes() {
  73. Component c = readDesign("<vaadin--button></vaadin--button>");
  74. Assert.assertTrue(c.getClass() == Button.class);
  75. }
  76. @Test(expected = DesignException.class)
  77. public void specialCharacters() {
  78. readDesign("<vaadin-button-&!#></vaadin-button-&!#>");
  79. }
  80. private Component readDesign(String string) {
  81. try {
  82. return Design
  83. .read(new ByteArrayInputStream(string.getBytes("UTF-8")));
  84. } catch (UnsupportedEncodingException e) {
  85. throw new RuntimeException(e);
  86. }
  87. }
  88. }