01: package org.directwebremoting.impl;
02:
03: import java.io.BufferedReader;
04: import java.io.BufferedWriter;
05: import java.io.File;
06: import java.io.FileWriter;
07: import java.io.IOException;
08: import java.io.InputStream;
09: import java.io.InputStreamReader;
10: import junit.framework.TestCase;
11:
12: public class YahooJSCompressorTest extends TestCase {
13: String scriptToCompress = null;
14:
15: @Override
16: protected void setUp() {
17: StringBuffer scriptBuffer = new StringBuffer();
18: InputStream scriptStream = getClass().getClassLoader()
19: .getResourceAsStream("testData/util.js");
20: BufferedReader bufferedReader = new BufferedReader(
21: new InputStreamReader(scriptStream));
22: try {
23: String line = null;
24: while ((line = bufferedReader.readLine()) != null) {
25: scriptBuffer.append(line + "\n");
26: }
27: } catch (Exception e) {
28: System.out.println(e.getMessage());
29: } finally {
30: try {
31: scriptStream.close();
32: bufferedReader.close();
33: } catch (Exception e1) {
34: }
35: }
36: scriptToCompress = scriptBuffer.toString();
37: }
38:
39: @Override
40: protected void tearDown() {
41: scriptToCompress = null;
42: }
43:
44: public void testCompression() throws IOException {
45: YahooJSCompressor yahooJsCompressor = new YahooJSCompressor(
46: null);
47: String compressedScript = yahooJsCompressor
48: .compressJavaScript(scriptToCompress);
49: try {
50: BufferedWriter out = new BufferedWriter(new FileWriter(
51: new File("C:/testCompress.js")));
52: out.write(compressedScript);
53: out.close();
54: } catch (IOException e) {
55: System.out.println(e.getMessage());
56: }
57: }
58: }
|