aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-24 07:32:50 (EST)
committerWinston Prakash2011-12-01 20:47:24 (EST)
commit9190ae75f62f30dfcbb19444e2a234590af19361 (patch)
tree5a5822032249d1bd99cd63a47a7418dced4e905a
parent27c4647bd3466c321f5178d4cf3f7c2c2559dfce (diff)
downloadorg.eclipse.hudson.core-9190ae75f62f30dfcbb19444e2a234590af19361.zip
org.eclipse.hudson.core-9190ae75f62f30dfcbb19444e2a234590af19361.tar.gz
org.eclipse.hudson.core-9190ae75f62f30dfcbb19444e2a234590af19361.tar.bz2
Implement test for legacy triggers, publishers conversion
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/test/java/hudson/model/LegacyProjectTest.java80
-rw-r--r--hudson-core/src/test/resources/hudson/model/freestyle/config.xml5
2 files changed, 72 insertions, 13 deletions
diff --git a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
index 287677b..70b33c7 100644
--- a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
@@ -16,7 +16,12 @@ package hudson.model;
import hudson.tasks.Mailer;
import hudson.tasks.Maven;
+import hudson.tasks.Publisher;
import hudson.tasks.junit.JUnitResultArchiver;
+import hudson.triggers.SCMTrigger;
+import hudson.triggers.TimerTrigger;
+import hudson.triggers.Trigger;
+import hudson.triggers.TriggerDescriptor;
import java.io.File;
import java.net.URISyntaxException;
import org.eclipse.hudson.api.model.IProjectProperty;
@@ -41,7 +46,8 @@ import static org.powermock.api.easymock.PowerMock.*;
* @author Nikita Levyankov
*/
@RunWith(PowerMockRunner.class)
-@PrepareForTest({Hudson.class})
+@PrepareForTest({Hudson.class, SCMTrigger.DescriptorImpl.class, TimerTrigger.DescriptorImpl.class,
+ Mailer.DescriptorImpl.class, JUnitResultArchiver.DescriptorImpl.class})
public class LegacyProjectTest {
private File config;
@@ -114,27 +120,34 @@ public class LegacyProjectTest {
* @throws Exception if any.
*/
@Test
- @Ignore
- //TODO investigate how to mock descriptor loading and creation.
public void testConvertPublishersProperty() throws Exception {
- Hudson hudson = createMock(Hudson.class);
- expect(hudson.getDescriptorOrDie(Mailer.class)).andReturn(new Mailer.DescriptorImpl());
- expect(hudson.getDescriptorOrDie(JUnitResultArchiver.class)).andReturn(
- new JUnitResultArchiver.DescriptorImpl());
- mockStatic(Hudson.class);
- expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
- replayAll();
Project project = (Project) Items.getConfigFile(config).read();
project.setAllowSave(false);
project.initProjectProperties();
+
+ Hudson hudson = createMock(Hudson.class);
+
String mailerKey = "hudson-tasks-Mailer";
+ Descriptor<Publisher> mailerDescriptor = createMock(Mailer.DescriptorImpl.class);
+ expect(mailerDescriptor.getJsonSafeClassName()).andReturn(mailerKey);
+ expect(hudson.getDescriptorOrDie(Mailer.class)).andReturn(mailerDescriptor);
+
+ String jUnitKey = "hudson-task-JUnitResultArchiver";
+ Descriptor<Publisher> junitDescriptor = createMock(JUnitResultArchiver.DescriptorImpl.class);
+ expect(junitDescriptor.getJsonSafeClassName()).andReturn(jUnitKey);
+ expect(hudson.getDescriptorOrDie(JUnitResultArchiver.class)).andReturn(junitDescriptor);
+
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+
//Publishers should be null, because of legacy implementation. Version < 2.2.0
assertNull(project.getProperty(mailerKey));
+ assertNull(project.getProperty(jUnitKey));
project.convertPublishersProperties();
//Verify publishers
- assertFalse(project.getPublishersList().isEmpty());
- assertEquals(2, project.getPublishersList().size());
assertNotNull(project.getProperty(mailerKey).getValue());
+ assertNotNull(project.getProperty(jUnitKey).getValue());
verifyAll();
}
@@ -265,4 +278,47 @@ public class LegacyProjectTest {
project.convertLogRotatorProperty();
assertNotNull(project.getProperty(Job.LOG_ROTATOR_PROPERTY_NAME));
}
+
+ /**
+ * Tests unmarshalling FreeStyleProject configuration and checks whether Triggers properties
+ * from Job are configured.
+ *
+ * @throws Exception if any.
+ */
+ @Test
+ public void testConvertLegacyTriggers() throws Exception {
+ AbstractProject project = (AbstractProject) Items.getConfigFile(config).read();
+ project.setAllowSave(false);
+ project.initProjectProperties();
+ Hudson hudson = createMock(Hudson.class);
+
+ String scmTriggerPropertyKey = "hudson-trigger-SCMTrigger";
+ TriggerDescriptor scmTriggerDescriptor = createMock(SCMTrigger.DescriptorImpl.class);
+ expect(scmTriggerDescriptor.getJsonSafeClassName()).andReturn(scmTriggerPropertyKey);
+ expect(hudson.getDescriptorOrDie(SCMTrigger.class)).andReturn(scmTriggerDescriptor);
+
+ String timerTriggerPropertyKey = "hudson-trigger-TimerTrigger";
+ TriggerDescriptor timerTriggerDescriptor = createMock(TimerTrigger.DescriptorImpl.class);
+ expect(timerTriggerDescriptor.getJsonSafeClassName()).andReturn(timerTriggerPropertyKey);
+ expect(hudson.getDescriptorOrDie(TimerTrigger.class)).andReturn(timerTriggerDescriptor);
+
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+
+ project.setAllowSave(false);
+ project.initProjectProperties();
+ assertNull(project.getProperty(scmTriggerPropertyKey));
+ assertNull(project.getProperty(timerTriggerPropertyKey));
+ project.convertTriggerProperties();
+
+ assertNotNull(project.getProperty(scmTriggerPropertyKey));
+ Trigger trigger = (Trigger) project.getProperty(scmTriggerPropertyKey).getValue();
+ assertEquals("5 * * * *", trigger.getSpec());
+
+ assertNotNull(project.getProperty(timerTriggerPropertyKey));
+ trigger = (Trigger) project.getProperty(timerTriggerPropertyKey).getValue();
+ assertEquals("*/10 * * * *", trigger.getSpec());
+ verifyAll();
+ }
}
diff --git a/hudson-core/src/test/resources/hudson/model/freestyle/config.xml b/hudson-core/src/test/resources/hudson/model/freestyle/config.xml
index 473a0ff..d582a06 100644
--- a/hudson-core/src/test/resources/hudson/model/freestyle/config.xml
+++ b/hudson-core/src/test/resources/hudson/model/freestyle/config.xml
@@ -21,6 +21,9 @@
<hudson.triggers.SCMTrigger>
<spec>5 * * * *</spec>
</hudson.triggers.SCMTrigger>
+ <hudson.triggers.TimerTrigger>
+ <spec>*/10 * * * *</spec>
+ </hudson.triggers.TimerTrigger>
</triggers>
<concurrentBuild>true</concurrentBuild>
<cleanWorkspaceRequired>true</cleanWorkspaceRequired>
@@ -46,4 +49,4 @@
</hudson.tasks.Maven>
</builders>
<customWorkspace>/tmp</customWorkspace>
-</project> \ No newline at end of file
+</project>