KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > publishers > ClearCaseBaselinePublisherTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2006, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.publishers;
38
39 import junit.framework.TestCase;
40 import net.sourceforge.cruisecontrol.CruiseControlException;
41 import org.jdom.CDATA;
42 import org.jdom.Element;
43
44 public class ClearCaseBaselinePublisherTest extends TestCase {
45
46     public Element mockbuildLog() {
47         // create a fake cruisecontrol log
48
Element logElement = new Element("cruisecontrol");
49         // add a single modification
50
Element mods = new Element("modifications");
51         logElement.addContent(mods);
52         Element mod = new Element("modification");
53         mod.setAttribute("type", "activity");
54         mods.addContent(mod);
55         Element rev = new Element("revision");
56         rev.addContent(new CDATA("Some activitiy"));
57         mod.addContent(rev);
58         // and a build label
59
Element info = new Element("info");
60         logElement.addContent(info);
61         Element prop = new Element("property");
62         prop.setAttribute("name", "label");
63         prop.setAttribute("value", "1_TST");
64         info.addContent(prop);
65         return logElement;
66     }
67
68     public void testValidate() {
69         ClearCaseBaselinePublisher cbp = new ClearCaseBaselinePublisher();
70
71         try {
72             cbp.validate();
73             fail("ClearCaseBaselinePublisher should throw an exception when the required attributes are not set.");
74         } catch (CruiseControlException e) {
75             assertEquals("exception message when required attributes not set",
76                     "'viewtag' is required for ClearCaseBaselinePublisher", e.getMessage());
77         }
78         cbp.setViewtag("someviewtag");
79         try {
80             cbp.validate();
81         } catch (CruiseControlException e) {
82             fail("ClearCaseBaselinePublisher should not throw an exception when the required attributes are set.");
83         }
84     }
85
86     public void testGetActivities() {
87         ClearCaseBaselinePublisher cbp = new ClearCaseBaselinePublisher();
88         cbp.setViewtag("someviewtag");
89         assertEquals(0, cbp.getActivities(new Element("cruisecontrol")).size());
90         Element logElement = mockbuildLog();
91         assertEquals(1, cbp.getActivities(logElement).size());
92     }
93
94     public void testShouldPublish() {
95         ClearCaseBaselinePublisher cbp = new ClearCaseBaselinePublisher();
96         cbp.setViewtag("someviewtag");
97         assertFalse(cbp.shouldPublish(new Element("cruisecontrol")));
98         Element logElement = mockbuildLog();
99         assertTrue(cbp.shouldPublish(logElement));
100     }
101 }
102
Popular Tags