| 1 |
package com.github.markusbernhardt.proxy.selector.pac; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.net.MalformedURLException; |
| 5 |
import java.util.Calendar; |
| 6 |
|
| 7 |
import org.junit.AfterClass; |
| 8 |
import org.junit.Assert; |
| 9 |
import org.junit.BeforeClass; |
| 10 |
import org.junit.Ignore; |
| 11 |
import org.junit.Test; |
| 12 |
|
| 13 |
import com.github.markusbernhardt.proxy.TestUtil; |
| 14 |
import com.github.markusbernhardt.proxy.selector.pac.JavaxPacScriptParser; |
| 15 |
import com.github.markusbernhardt.proxy.selector.pac.PacScriptParser; |
| 16 |
import com.github.markusbernhardt.proxy.selector.pac.UrlPacScriptSource; |
| 17 |
import com.github.markusbernhardt.proxy.util.ProxyException; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class JavaxPacScriptParserTest { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
@BeforeClass |
| 33 |
public static void setup() { |
| 34 |
Calendar cal = Calendar.getInstance(); |
| 35 |
cal.set(Calendar.YEAR, 1994); |
| 36 |
cal.set(Calendar.MONTH, Calendar.DECEMBER); |
| 37 |
cal.set(Calendar.DAY_OF_MONTH, 15); |
| 38 |
cal.set(Calendar.HOUR_OF_DAY, 12); |
| 39 |
cal.set(Calendar.MINUTE, 00); |
| 40 |
cal.set(Calendar.SECOND, 00); |
| 41 |
cal.set(Calendar.MILLISECOND, 00); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
@AfterClass |
| 51 |
public static void teadDown() { |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
@Test |
| 64 |
public void testScriptExecution() throws ProxyException, MalformedURLException { |
| 65 |
PacScriptParser p = new JavaxPacScriptParser(new UrlPacScriptSource(toUrl("test1.pac"))); |
| 66 |
p.evaluate(TestUtil.HTTP_TEST_URI.toString(), "host1.unit-test.invalid"); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
@Test |
| 78 |
public void testCommentsInScript() throws ProxyException, MalformedURLException { |
| 79 |
PacScriptParser p = new JavaxPacScriptParser(new UrlPacScriptSource(toUrl("test2.pac"))); |
| 80 |
p.evaluate(TestUtil.HTTP_TEST_URI.toString(), "host1.unit-test.invalid"); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
@Test |
| 92 |
@Ignore |
| 93 |
|
| 94 |
public void testScriptWeekDayScript() throws ProxyException, MalformedURLException { |
| 95 |
PacScriptParser p = new JavaxPacScriptParser(new UrlPacScriptSource(toUrl("testWeekDay.pac"))); |
| 96 |
p.evaluate(TestUtil.HTTP_TEST_URI.toString(), "host1.unit-test.invalid"); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
@Test |
| 108 |
@Ignore |
| 109 |
|
| 110 |
public void testDateRangeScript() throws ProxyException, MalformedURLException { |
| 111 |
PacScriptParser p = new JavaxPacScriptParser(new UrlPacScriptSource(toUrl("testDateRange.pac"))); |
| 112 |
p.evaluate(TestUtil.HTTP_TEST_URI.toString(), "host1.unit-test.invalid"); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
@Test |
| 124 |
@Ignore |
| 125 |
|
| 126 |
public void testTimeRangeScript() throws ProxyException, MalformedURLException { |
| 127 |
PacScriptParser p = new JavaxPacScriptParser(new UrlPacScriptSource(toUrl("testTimeRange.pac"))); |
| 128 |
p.evaluate(TestUtil.HTTP_TEST_URI.toString(), "host1.unit-test.invalid"); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
@Test |
| 140 |
public void methodsShouldReturnJsStrings() throws ProxyException, MalformedURLException { |
| 141 |
PacScriptParser p = new JavaxPacScriptParser(new UrlPacScriptSource(toUrl("testReturnTypes.pac"))); |
| 142 |
String actual = p.evaluate(TestUtil.HTTP_TEST_URI.toString(), "host1.unit-test.invalid"); |
| 143 |
Assert.assertEquals("number boolean string", actual); |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
private String toUrl(String testFile) throws MalformedURLException { |
| 156 |
return new File(TestUtil.TEST_DATA_FOLDER + "pac", testFile).toURI().toURL().toString(); |
| 157 |
} |
| 158 |
|
| 159 |
} |