/xwiki-enterprise-test/xwiki-enterprise-test-ui/src/test/it/org/xwiki/test/ui/tag/AddRemoveTagsTest.java

https://github.com/ntallapa/xwiki-enterprise · Java · 193 lines · 120 code · 19 blank · 54 comment · 0 complexity · ee38c6dff09d22a3773bdf7f8a0e50c0 MD5 · raw file

  1. /*
  2. * See the NOTICE file distributed with this work for additional
  3. * information regarding copyright ownership.
  4. *
  5. * This is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU Lesser General Public License as
  7. * published by the Free Software Foundation; either version 2.1 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This software is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this software; if not, write to the Free
  17. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  19. */
  20. package org.xwiki.test.ui.tag;
  21. import junit.framework.Assert;
  22. import org.apache.commons.lang.RandomStringUtils;
  23. import org.junit.Before;
  24. import org.junit.Test;
  25. import org.xwiki.test.po.AbstractAdminAuthenticatedTest;
  26. import org.xwiki.test.po.tag.AddTagsPane;
  27. import org.xwiki.test.po.tag.TaggablePage;
  28. /**
  29. * Several tests for adding and removing tags to/from a wiki page.
  30. *
  31. * @version $Id: b5e0bd25d52eac75754071630ee229d89d868ea3 $
  32. * @since 3.1M1
  33. */
  34. public class AddRemoveTagsTest extends AbstractAdminAuthenticatedTest
  35. {
  36. /**
  37. * The test page.
  38. */
  39. private TaggablePage taggablePage;
  40. @Before
  41. @Override
  42. public void setUp()
  43. {
  44. super.setUp();
  45. // Create a new test page.
  46. getUtil().deletePage(getTestClassName(), getTestMethodName());
  47. getUtil().createPage(getTestClassName(), getTestMethodName(), null, null);
  48. taggablePage = new TaggablePage();
  49. }
  50. /**
  51. * Adds and removes a tag.
  52. */
  53. @Test
  54. public void testAddRemoveTag()
  55. {
  56. String tag = RandomStringUtils.randomAlphanumeric(4);
  57. Assert.assertFalse(taggablePage.hasTag(tag));
  58. AddTagsPane addTagsPane = taggablePage.addTags();
  59. addTagsPane.setTags(tag);
  60. Assert.assertTrue(addTagsPane.add());
  61. Assert.assertTrue(taggablePage.hasTag(tag));
  62. taggablePage.removeTag(tag);
  63. Assert.assertFalse(taggablePage.hasTag(tag));
  64. }
  65. /**
  66. * Open the add tag panel, cancel then open again the add tag panel and add a new tag.
  67. */
  68. @Test
  69. public void testCancelAddTag()
  70. {
  71. String firstTag = RandomStringUtils.randomAlphanumeric(4);
  72. Assert.assertFalse(taggablePage.hasTag(firstTag));
  73. AddTagsPane addTagsPane = taggablePage.addTags();
  74. addTagsPane.setTags(firstTag);
  75. addTagsPane.cancel();
  76. String secondTag = RandomStringUtils.randomAlphanumeric(4);
  77. Assert.assertFalse(taggablePage.hasTag(secondTag));
  78. addTagsPane = taggablePage.addTags();
  79. addTagsPane.setTags(secondTag);
  80. Assert.assertTrue(addTagsPane.add());
  81. Assert.assertTrue(taggablePage.hasTag(secondTag));
  82. Assert.assertFalse(taggablePage.hasTag(firstTag));
  83. }
  84. /**
  85. * Add many tags and remove one of them.
  86. */
  87. @Test
  88. public void testAddManyRemoveOneTag()
  89. {
  90. String firstTag = RandomStringUtils.randomAlphanumeric(4);
  91. Assert.assertFalse(taggablePage.hasTag(firstTag));
  92. String secondTag = RandomStringUtils.randomAlphanumeric(4);
  93. Assert.assertFalse(taggablePage.hasTag(secondTag));
  94. AddTagsPane addTagsPane = taggablePage.addTags();
  95. addTagsPane.setTags(firstTag + "," + secondTag);
  96. Assert.assertTrue(addTagsPane.add());
  97. Assert.assertTrue(taggablePage.hasTag(firstTag));
  98. Assert.assertTrue(taggablePage.hasTag(secondTag));
  99. Assert.assertTrue(taggablePage.removeTag(firstTag));
  100. Assert.assertTrue(taggablePage.hasTag(secondTag));
  101. }
  102. /**
  103. * Tests that a tag can't be added twice to the same page.
  104. */
  105. @Test
  106. public void testAddExistingTag()
  107. {
  108. String tag = RandomStringUtils.randomAlphanumeric(4);
  109. Assert.assertFalse(taggablePage.hasTag(tag));
  110. AddTagsPane addTagsPane = taggablePage.addTags();
  111. addTagsPane.setTags(tag);
  112. Assert.assertTrue(addTagsPane.add());
  113. Assert.assertTrue(taggablePage.hasTag(tag));
  114. addTagsPane = taggablePage.addTags();
  115. addTagsPane.setTags(tag);
  116. Assert.assertFalse(addTagsPane.add());
  117. addTagsPane.cancel();
  118. }
  119. /**
  120. * Add a tag that contains the pipe character, which is used to separate stored tags.
  121. */
  122. @Test
  123. public void testAddTagContainingPipe()
  124. {
  125. String tag = RandomStringUtils.randomAlphanumeric(3) + "|" + RandomStringUtils.randomAlphanumeric(3);
  126. Assert.assertFalse(taggablePage.hasTag(tag));
  127. AddTagsPane addTagsPane = taggablePage.addTags();
  128. addTagsPane.setTags(tag);
  129. Assert.assertTrue(addTagsPane.add());
  130. Assert.assertTrue(taggablePage.hasTag(tag));
  131. // Reload the page and test again.
  132. getUtil().gotoPage(getTestClassName(), getTestMethodName());
  133. taggablePage = new TaggablePage();
  134. Assert.assertTrue(taggablePage.hasTag(tag));
  135. }
  136. /**
  137. * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-3843">XWIKI-3843</a>: Strip leading and trailing white
  138. * spaces to tags when white space is not the separator
  139. */
  140. @Test
  141. public void testStripLeadingAndTrailingSpacesFromTags()
  142. {
  143. String firstTag = RandomStringUtils.randomAlphanumeric(4);
  144. Assert.assertFalse(taggablePage.hasTag(firstTag));
  145. String secondTag = RandomStringUtils.randomAlphanumeric(4);
  146. Assert.assertFalse(taggablePage.hasTag(secondTag));
  147. AddTagsPane addTagsPane = taggablePage.addTags();
  148. addTagsPane.setTags(" " + firstTag + " , " + secondTag + " ");
  149. Assert.assertTrue(addTagsPane.add());
  150. Assert.assertTrue(taggablePage.hasTag(firstTag));
  151. Assert.assertTrue(taggablePage.hasTag(secondTag));
  152. }
  153. /**
  154. * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-6549">XWIKI-6549</a>: Prevent adding new tags that are
  155. * equal ignoring case with existing tags
  156. */
  157. @Test
  158. public void testTagCaseIsIgnored()
  159. {
  160. String firstTag = "taG1";
  161. Assert.assertFalse(taggablePage.hasTag(firstTag));
  162. // Second tag is same as first tag but with different uppercase/lowercase chars.
  163. String secondTag = "Tag1";
  164. Assert.assertFalse(taggablePage.hasTag(secondTag));
  165. String thirdTag = "tag3";
  166. Assert.assertFalse(taggablePage.hasTag(thirdTag));
  167. AddTagsPane addTagsPane = taggablePage.addTags();
  168. addTagsPane.setTags(firstTag + "," + thirdTag + "," + secondTag);
  169. Assert.assertTrue(addTagsPane.add());
  170. Assert.assertTrue(taggablePage.hasTag(firstTag));
  171. Assert.assertFalse(taggablePage.hasTag(secondTag));
  172. Assert.assertTrue(taggablePage.hasTag(thirdTag));
  173. }
  174. }