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 { 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); } public void testFile() throws Exception { final File file = createTempFile("some constant content"); assertEquals("-248bdf60e0ed4ea1abf34aa2c427db7", createDefaultHashProvider().getResourceHash(TriggerParameters.create("file://" + file.getAbsolutePath()))); } @NotNull private DefaultResourceHashProvider createDefaultHashProvider() { return new DefaultResourceHashProvider(); } }