01: package net.sourceforge.cruisecontrol.jmx;
02:
03: import java.io.File;
04: import java.util.ArrayList;
05: import java.util.Date;
06: import java.util.List;
07: import java.util.Map;
08:
09: import org.codehaus.plexus.util.FileUtils;
10:
11: import junit.framework.TestCase;
12: import net.sourceforge.cruisecontrol.CruiseControlException;
13: import net.sourceforge.cruisecontrol.Modification;
14: import net.sourceforge.cruisecontrol.ModificationSet;
15: import net.sourceforge.cruisecontrol.Project;
16: import net.sourceforge.cruisecontrol.ProjectConfig;
17: import net.sourceforge.cruisecontrol.SourceControl;
18: import net.sourceforge.cruisecontrol.bootstrappers.AntBootstrapper;
19: import net.sourceforge.cruisecontrol.labelincrementers.DefaultLabelIncrementer;
20:
21: public class ProjectControllerTest extends TestCase {
22:
23: public void testShouldBeAbleToGetCommitMessage() throws Exception {
24: Project project = new Project();
25: project.setName("TestProject");
26: ModificationSet modicationSet = new ModificationSet();
27: modicationSet.add(new SVNStub());
28: ProjectConfig projectConfig = new ProjectConfig();
29: projectConfig.add(new DefaultLabelIncrementer());
30: projectConfig.add(modicationSet);
31:
32: project.setProjectConfig(projectConfig);
33:
34: ProjectMBean controller = new ProjectController(project);
35: String[][] message = controller.commitMessages();
36: assertEquals(message[0][0], "user1");
37: assertEquals(message[0][1], "comment1");
38: assertEquals(message[1][0], "user2");
39: assertEquals(message[1][1], "comment2");
40: }
41:
42: public void testShouldRetrieveBuildOutputWhenProjectIsBuilding()
43: throws Exception {
44: Project project = new Project();
45: project.setName("project1");
46:
47: File validFile = new File("project1");
48: FileUtils.forceMkdir(validFile);
49:
50: AntBootstrapper bootstrapper = new AntBootstrapper();
51:
52: bootstrapper.setBuildFile(validFile.getAbsolutePath());
53: bootstrapper.setTempFile("notLog.xml");
54: bootstrapper.setTarget("init");
55: bootstrapper.setAntWorkingDir(validFile.getAbsolutePath());
56: bootstrapper.validate();
57: try {
58: bootstrapper.bootstrap();
59: } catch (Exception e) {
60: Thread.sleep(2 * 1000);
61: } finally {
62: FileUtils.forceDelete(validFile);
63: }
64:
65: ProjectMBean mbean = new ProjectController(project);
66: String[] output = mbean.getBuildOutput(new Integer(0));
67: assertNotNull(output);
68: assertTrue(output.length > 0);
69: }
70:
71: private class SVNStub implements SourceControl {
72: private static final long serialVersionUID = 1L;
73:
74: public List getModifications(Date lastBuild, Date now) {
75: List modications = new ArrayList();
76: Modification modification = new Modification();
77: modification.userName = "user1";
78: modification.comment = "comment1";
79: modications.add(modification);
80: modification = new Modification();
81: modification.userName = "user2";
82: modification.comment = "comment2";
83: modications.add(modification);
84: return modications;
85: }
86:
87: public Map getProperties() {
88: return null;
89: }
90:
91: public void validate() throws CruiseControlException {
92: }
93: }
94: }
|