01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.jdbc.meta.strats;
20:
21: import java.io.ByteArrayInputStream;
22: import java.io.IOException;
23: import java.io.InputStream;
24:
25: /**
26: * Defines all the abstract methods from AbstractLobTest to tests the
27: * the LOB support with an InputStream.
28: *
29: * @author Ignacio Andreu
30: * @since 1.1.0
31: */
32:
33: public class InputStreamLobTest extends AbstractLobTest {
34:
35: protected LobEntity newLobEntity(String s, int id) {
36: InputStreamLobEntity isle = new InputStreamLobEntity();
37: isle.setId(id);
38: if (s != null) {
39: isle.setStream(new ByteArrayInputStream(s.getBytes()));
40: } else {
41: isle.setStream(null);
42: }
43: return isle;
44: }
45:
46: protected LobEntity newLobEntityForLoadContent(String s, int id) {
47: InputStreamLobEntity isle = new InputStreamLobEntity();
48: isle.setId(id);
49: isle.setStream(new InputStreamWrapper(s));
50: return isle;
51: }
52:
53: protected Class getLobEntityClass() {
54: return InputStreamLobEntity.class;
55: }
56:
57: protected String getSelectQuery() {
58: return "SELECT o FROM InputStreamLobEntity o";
59: }
60:
61: protected String getStreamContentAsString(Object o)
62: throws IOException {
63: InputStream is = (InputStream) o;
64: String content = "";
65: byte[] bs = new byte[4];
66: int read = -1;
67: do {
68: read = is.read(bs);
69: if (read == -1) {
70: return content;
71: }
72: content = content + (new String(bs)).substring(0, read);
73: } while (true);
74: }
75:
76: protected void changeStream(LobEntity le, String s) {
77: le.setStream(new ByteArrayInputStream(s.getBytes()));
78: }
79: }
|