001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2007, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol.dashboard.web.command;
037:
038: import junit.framework.TestCase;
039: import net.sourceforge.cruisecontrol.Modification;
040: import net.sourceforge.cruisecontrol.dashboard.StoryTracker;
041: import org.apache.commons.lang.StringEscapeUtils;
042:
043: import java.util.ArrayList;
044: import java.util.Date;
045: import java.util.List;
046: import java.util.Map;
047:
048: public class ModificationCommandTest extends TestCase {
049: private Date date;
050:
051: protected void setUp() throws Exception {
052: date = new Date();
053: }
054:
055: public void testShouldreturnHyperLinkWhenCommandIsStoryTrackerSensitive() {
056: StoryTracker storyTracker = new StoryTracker("pj",
057: "http://mingle/story/", "story");
058: ModificationCommand command = new ModificationCommand(
059: createModification("story1"), storyTracker);
060: assertEquals("<a href=\"http://mingle/story/1\">story1</a>",
061: command.getComment());
062: }
063:
064: private Modification createModification(String comment) {
065: List files = new ArrayList();
066: Modification.ModifiedFile file1 = new Modification.ModifiedFile(
067: "file1.txt", "123", "folder", "deleted");
068: Modification.ModifiedFile file2 = new Modification.ModifiedFile(
069: "file1.txt", "123", "folder", "added");
070: files.add(file1);
071: files.add(file2);
072: return new Modification("svn", "user", comment,
073: "use@email.com", date, "1234", files);
074:
075: }
076:
077: public void testShouldReturnCommentWhenStoryTrackerIsNull() {
078: ModificationCommand command = new ModificationCommand(
079: createModification("story1"), null);
080: assertEquals("story1", command.getComment());
081: }
082:
083: public void testShouldEscapeHtmlTag() throws Exception {
084: String comment = "commit message <b>with</b> <some> html <tags>, go...";
085: ModificationCommand command = new ModificationCommand(
086: createModification(comment), null);
087: String expected = StringEscapeUtils.escapeHtml(comment);
088: assertEquals(expected, command.getComment());
089: }
090:
091: public void testShouldReturnJsonDataMap() throws Exception {
092: ModificationCommand command = new ModificationCommand(
093: createModification("story1"), null);
094: Map map = command.toJsonData();
095: assertEquals("svn", map.get("type"));
096: assertEquals("user", map.get("user"));
097: assertEquals("story1", map.get("comment"));
098: assertEquals(new Long(date.getTime()), map.get("modifiedtime"));
099: List files = (List) map.get("files");
100: assertEquals(2, files.size());
101: assertEquals("file1.txt", ((Map) files.get(0)).get("filename"));
102: assertEquals("123", ((Map) files.get(0)).get("revision"));
103: assertEquals("folder", ((Map) files.get(0)).get("folder"));
104: assertEquals("deleted", ((Map) files.get(0)).get("action"));
105: }
106: }
|