KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > driver > text > TextScriptITest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.driver.text;
17
18 import scriptella.AbstractTestCase;
19 import scriptella.execution.EtlExecutor;
20 import scriptella.execution.EtlExecutorException;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.ByteArrayOutputStream JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.OutputStream JavaDoc;
26 import java.io.UnsupportedEncodingException JavaDoc;
27 import java.net.URL JavaDoc;
28
29 /**
30  * Integration test for text script
31  *
32  * @author Fyodor Kupolov
33  * @version 1.0
34  */

35 public class TextScriptITest extends AbstractTestCase {
36     private ByteArrayOutputStream JavaDoc o1;
37     private ByteArrayOutputStream JavaDoc o2;
38
39     protected void setUp() throws Exception JavaDoc {
40
41         testURLHandler = new TestURLHandler() {
42             public InputStream JavaDoc getInputStream(final URL JavaDoc u) {
43                 if (u.toString().endsWith("2")) {
44                     throw new UnsupportedOperationException JavaDoc();
45                 }
46                 return new ByteArrayInputStream JavaDoc("a1\nb22b\n\rc333c".getBytes());
47             }
48
49             public OutputStream JavaDoc getOutputStream(final URL JavaDoc u) {
50                 if (u.toString().endsWith("2")) {
51                     return o2 = new ByteArrayOutputStream JavaDoc();
52                 } else {
53                     return o1 = new ByteArrayOutputStream JavaDoc();
54                 }
55             }
56
57             public int getContentLength(final URL JavaDoc u) {
58                 return -1;
59             }
60         };
61     }
62
63
64     public void test() throws EtlExecutorException, UnsupportedEncodingException JavaDoc {
65         EtlExecutor e = newEtlExecutor();
66         e.execute();
67         assertNotNull(o1);
68         assertEquals("Test Trim\n", new String JavaDoc(o1.toByteArray()));
69         assertNotNull(o2);
70         assertEquals("n1\rn22\rn333\r", new String JavaDoc(o2.toByteArray()));
71
72     }
73
74 }
75
Popular Tags