package jetbrains.buildServer.buildTriggers.url; import jetbrains.buildServer.BaseTestCase; import org.jetbrains.annotations.NotNull; import org.testng.annotations.Test; import java.io.File; import java.net.SocketTimeoutException; import java.util.Collection; import java.util.Date; /** * @author Victory.Bedrosova * 11/22/13. */ @Test public class DefaultResourceHashProviderTest extends BaseTestCase { @Test public void testConnectionTimeout() throws Exception { final long before = new Date().getTime(); try { createDefaultHashProvider().getResourceHash(TriggerParameters.create("http://www.google.com:81", "admin", "admin", 10)); } catch (Throwable e) { final Collection causes = ResourceHashProviderTestUtil.getCauses(e); for (Throwable t : causes) { if (t instanceof SocketTimeoutException) { // expected return; } } System.out.println(causes); fail(); } assertTrue(new Date().getTime() - before < 1000); } @Test public void testFile() throws Exception { final File file = createTempFile("some constant content"); final String fileUril = file.toURI().toString(); assertEquals("-248bdf60e0ed4ea1abf34aa2c427db7", createDefaultHashProvider().getResourceHash(TriggerParameters.create(fileUril))); } @NotNull private DefaultResourceHashProvider createDefaultHashProvider() { return new DefaultResourceHashProvider(); } }