package at.kugel.tool.buildtray.action;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.junit.Test;
import at.kugel.tool.buildtray.config.CheckBusy;
import at.kugel.tool.buildtray.config.Config;
import at.kugel.tool.buildtray.config.IntegrationTestConfig;
import at.kugel.tool.buildtray.status.IntegrationStatusResult;
import at.kugel.tool.buildtray.status.Status;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class JenkinsTest extends AbstractHtmlRegularExpressionActionsTestCase {
private IntegrationTestConfig createConfig() {
return createConfig("./config/Jenkins-1.4.properties");
}
@Test
public void testFailedNewest() {
IntegrationTestConfig mockConf = createConfig();
mockConf.setServerlUrl4Test(getTestDataUrl("Jenkins-1.4_failed.xml"));
IntegrationStatusResult res = refreshWith(mockConf);
assertNull(res.error);
assertEquals("commons-solr-copy #2", res.projectName);
assertEquals(Status.FAILED, res.status);
}
@Test
public void testUnstable() {
IntegrationTestConfig mockConf = createConfig();
mockConf.setServerlUrl4Test(getTestDataUrl("Jenkins-1.4_unstable.xml"));
IntegrationStatusResult res = refreshWith(mockConf);
assertNull(res.error);
assertEquals("collaboration #2", res.projectName);
assertEquals(Status.FAILED, res.status);
}
@Test
public void testBusy() {
IntegrationTestConfig mockConf = createConfig();
mockConf.setServerlUrl4Test(getTestDataUrl("Jenkins-1.4_busy.xml"));
IntegrationStatusResult res = refreshWith(mockConf);
assertNull(res.error);
assertEquals("clients-bbc-searchplus #7", res.projectName);
assertEquals(Status.BUSY, res.status);
assertNull(res.date);
}
@Test
public void testBusySkipped() {
IntegrationTestConfig serverMockConf = createConfig();
serverMockConf.setServerlUrl4Test(getTestDataUrl("Jenkins-1.4_busy.xml"));
Config mockConfig = decorateCheckBusy(serverMockConf, CheckBusy.SKIP);
IntegrationStatusResult res = refreshWith(mockConfig);
assertNull(res.error);
assertNull(res.projectName);
assertNull(res.status);
assertNull(res.date);
}
private Config decorateCheckBusy(final Config conf, final CheckBusy returnValue) {
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(@SuppressWarnings("unused") Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
if (method.getName().equals("getCheckBusy")) {
return returnValue;
}
return method.invoke(conf, args);
}
};
return (Config) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Config.class }, handler);
}
@Test
public void testSuccess() {
IntegrationTestConfig mockConf = createConfig();
mockConf.setServerlUrl4Test(getTestDataUrl("Jenkins-1.4_success.xml"));
IntegrationStatusResult res = refreshWith(mockConf);
assertNull(res.error);
assertEquals("clients-bbc-iplayer #4", res.projectName);
assertEquals(Status.OK, res.status);
assertEquals("2011-05-01T18:11:17Z", res.date);
}
}