1 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 Element logElement = new Element("cruisecontrol"); 49 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 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 |