| 1 16 package scriptella.driver.velocity; 17 18 import scriptella.AbstractTestCase; 19 import scriptella.configuration.MockConnectionEl; 20 import scriptella.configuration.StringResource; 21 import scriptella.spi.ConnectionParameters; 22 import scriptella.spi.MockDriverContext; 23 import scriptella.spi.MockParametersCallbacks; 24 25 import java.io.ByteArrayOutputStream ; 26 import java.io.InputStream ; 27 import java.io.OutputStream ; 28 import java.net.MalformedURLException ; 29 import java.net.URL ; 30 import java.net.URLConnection ; 31 import java.net.URLStreamHandler ; 32 33 39 public class VelocityConnectionTest extends AbstractTestCase { 40 41 45 public void test() { 46 ByteArrayOutputStream out = new ByteArrayOutputStream (); 47 VelocityConnection c = createConnection(out); 48 run(c); 49 c.close(); 50 String s = out.toString(); 51 assertEquals("*v1*///*v2*", s); 52 53 54 } 55 57 static VelocityConnection createConnection(final OutputStream out) { 58 try { 59 final URL u = new URL ("mem", "", 0, "memfile", new URLStreamHandler () { 60 protected URLConnection openConnection(URL u) { 61 return new URLConnection (u) { 62 public void connect() { 63 } 64 65 public InputStream getInputStream() { 66 throw new UnsupportedOperationException (); 67 } 68 69 public OutputStream getOutputStream() { 70 return out; 71 } 72 }; 73 } 74 }); 75 ConnectionParameters cp = new ConnectionParameters(new MockConnectionEl(), MockDriverContext.INSTANCE) { 76 @Override  77 public URL getResolvedUrl() { 78 return u; 79 } 80 }; 81 return new VelocityConnection(cp); 82 } catch (MalformedURLException e) { 83 throw new IllegalStateException (e); 84 } 85 } 86 87 static void run(VelocityConnection c) { 88 c.executeScript(new StringResource(("$v1///$v2")), MockParametersCallbacks.SIMPLE); 89 } 90 } 91 | Popular Tags |