01: package org.compass.core.test.property.inputstream;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.IOException;
05:
06: import org.compass.core.CompassSession;
07: import org.compass.core.CompassTransaction;
08: import org.compass.core.test.AbstractTestCase;
09:
10: /**
11: * @author kimchy
12: */
13: public class InputStreamTests extends AbstractTestCase {
14:
15: protected String[] getMappings() {
16: return new String[] { "property/inputstream/mapping.cpm.xml" };
17: }
18:
19: public void testInputStream() throws IOException {
20: CompassSession session = openSession();
21: CompassTransaction tr = session.beginTransaction();
22:
23: Long id = new Long(1);
24: InputStreamType o = new InputStreamType();
25: o.setId(id);
26:
27: byte[] bytes = new byte[] { 1, 2, 3 };
28: ByteArrayInputStream inputStream = new ByteArrayInputStream(
29: bytes);
30: o.setInputStream(inputStream);
31: session.save(o);
32:
33: tr.commit();
34:
35: tr = session.beginTransaction();
36:
37: o = (InputStreamType) session.load(InputStreamType.class, id);
38: assertEquals(id, o.getId());
39: assertNotNull(o.getInputStream());
40: assertEquals(1, o.getInputStream().read());
41: assertEquals(2, o.getInputStream().read());
42: assertEquals(3, o.getInputStream().read());
43:
44: tr.commit();
45: }
46:
47: public void testBinaryArray() {
48: CompassSession session = openSession();
49: CompassTransaction tr = session.beginTransaction();
50:
51: Long id = new Long(1);
52: byte[] bytes = new byte[] { 1, 2, 3 };
53: Byte[] oBytes = new Byte[] { new Byte((byte) 1),
54: new Byte((byte) 2), new Byte((byte) 3) };
55: BinaryArrayType o = new BinaryArrayType();
56: o.setId(id);
57: o.setBytes(bytes);
58: o.setOBytes(oBytes);
59:
60: session.save(o);
61:
62: o = (BinaryArrayType) session.load(BinaryArrayType.class, id);
63: assertNotNull(o.getBytes());
64: assertEquals(3, o.getBytes().length);
65: assertEquals(1, o.getBytes()[0]);
66: assertEquals(2, o.getBytes()[1]);
67: assertEquals(3, o.getBytes()[2]);
68:
69: assertEquals(3, o.getOBytes().length);
70: assertEquals(new Byte((byte) 1), o.getOBytes()[0]);
71: assertEquals(new Byte((byte) 2), o.getOBytes()[1]);
72: assertEquals(new Byte((byte) 3), o.getOBytes()[2]);
73:
74: tr.commit();
75: session.close();
76: }
77: }
|