| 1 |
package com.github.markusbernhardt.proxy.selector.pac; |
| 2 |
|
| 3 |
import static org.junit.Assert.assertEquals; |
| 4 |
|
| 5 |
import org.junit.Test; |
| 6 |
|
| 7 |
import com.github.markusbernhardt.proxy.selector.pac.UrlPacScriptSource; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public class UrlPacScriptSourceTest { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
@Test |
| 22 |
public void testHttpCharsetParser() { |
| 23 |
UrlPacScriptSource scriptSource = new UrlPacScriptSource(""); |
| 24 |
String charset = scriptSource.parseCharsetFromHeader("application/x-ns-proxy-autoconfig; charset=UTF-8"); |
| 25 |
assertEquals("UTF-8", charset); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
@Test |
| 32 |
public void testHttpCharsetParserDefault() { |
| 33 |
UrlPacScriptSource scriptSource = new UrlPacScriptSource(""); |
| 34 |
String charset = scriptSource.parseCharsetFromHeader("application/octet-stream;"); |
| 35 |
assertEquals("ISO-8859-1", charset); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
@Test |
| 42 |
public void overrideTimeoutShouldWork() { |
| 43 |
System.setProperty(UrlPacScriptSource.OVERRIDE_CONNECT_TIMEOUT, "5000"); |
| 44 |
UrlPacScriptSource scriptSource = new UrlPacScriptSource(""); |
| 45 |
int timeout = scriptSource.getTimeOut(UrlPacScriptSource.OVERRIDE_CONNECT_TIMEOUT, 1000); |
| 46 |
System.clearProperty(UrlPacScriptSource.OVERRIDE_CONNECT_TIMEOUT); |
| 47 |
assertEquals(5000, timeout); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
@Test |
| 54 |
public void timeoutShouldUseDefault() { |
| 55 |
System.setProperty(UrlPacScriptSource.OVERRIDE_CONNECT_TIMEOUT, "XXX"); |
| 56 |
UrlPacScriptSource scriptSource = new UrlPacScriptSource(""); |
| 57 |
int timeout = scriptSource.getTimeOut(UrlPacScriptSource.OVERRIDE_CONNECT_TIMEOUT, 1000); |
| 58 |
System.clearProperty(UrlPacScriptSource.OVERRIDE_CONNECT_TIMEOUT); |
| 59 |
assertEquals(1000, timeout); |
| 60 |
} |
| 61 |
|
| 62 |
} |