1 37 package net.sourceforge.cruisecontrol; 38 39 import junit.framework.TestCase; 40 41 public class ProjectConfigTest extends TestCase { 42 43 private ProjectConfig config; 44 45 protected void setUp() { 46 config = new ProjectConfig(); 47 } 48 49 protected void tearDown() { 50 config = null; 51 } 52 53 public void testBuildAfterFailedShouldDefaultToTrue() { 54 assertTrue(config.shouldBuildAfterFailed()); 55 config.setBuildAfterFailed(false); 56 assertFalse(config.shouldBuildAfterFailed()); 57 } 58 59 public void testValidate_ScheduleRequired() throws CruiseControlException { 60 try { 61 config.validate(); 62 fail("a schedule should have been required by ProjectConfig"); 63 } catch (CruiseControlException expected) { 64 assertEquals("project requires a schedule", expected.getMessage()); 65 } 66 67 config.add(new MockSchedule()); 68 config.validate(); 69 } 70 71 public void testValidateCallsSubelementValidates() throws CruiseControlException { 72 MockSchedule schedule = new MockSchedule(); 73 config.add(schedule); 74 MockBootstrappers bootstrappers = new MockBootstrappers(); 75 config.add(bootstrappers); 76 MockModificationSet modificationSet = new MockModificationSet(); 77 config.add(modificationSet); 78 MockListeners listeners = new MockListeners(); 79 config.add(listeners); 80 MockPublishers publishers = new MockPublishers(); 81 config.add(publishers); 82 MockLog log = new MockLog(); 83 config.add(log); 84 85 config.validate(); 86 87 assertTrue(schedule.validateWasCalled()); 88 assertTrue(bootstrappers.validateWasCalled()); 89 assertTrue(modificationSet.validateWasCalled()); 90 assertTrue(listeners.validateWasCalled()); 91 assertTrue(publishers.validateWasCalled()); 92 assertTrue(log.validateWasCalled()); 93 } 94 95 private static class MockBootstrappers extends ProjectConfig.Bootstrappers { 96 private boolean validateWasCalled = false; 97 98 public void validate() throws CruiseControlException { 99 validateWasCalled = true; 100 } 101 102 public boolean validateWasCalled() { 103 return validateWasCalled; 104 } 105 } 106 107 private static class MockModificationSet extends ModificationSet { 108 private boolean validateWasCalled = false; 109 110 public void validate() throws CruiseControlException { 111 validateWasCalled = true; 112 } 113 114 public boolean validateWasCalled() { 115 return validateWasCalled; 116 } 117 } 118 119 private static class MockListeners extends ProjectConfig.Listeners { 120 private boolean validateWasCalled = false; 121 122 public void validate() throws CruiseControlException { 123 validateWasCalled = true; 124 } 125 126 public boolean validateWasCalled() { 127 return validateWasCalled; 128 } 129 } 130 131 private static class MockPublishers extends ProjectConfig.Publishers { 132 private boolean validateWasCalled = false; 133 134 public void validate() throws CruiseControlException { 135 validateWasCalled = true; 136 } 137 138 public boolean validateWasCalled() { 139 return validateWasCalled; 140 } 141 } 142 143 private static class MockLog extends Log { 144 private boolean validateWasCalled = false; 145 146 public void validate() throws CruiseControlException { 147 validateWasCalled = true; 148 } 149 150 public boolean validateWasCalled() { 151 return validateWasCalled; 152 } 153 } 154 } 155 | Popular Tags |