1
2
3
4 package org.melati.poem.test;
5
6 import java.sql.PreparedStatement;
7
8 import org.apache.commons.codec.binary.Base64;
9 import org.melati.poem.BinaryLengthValidationPoemException;
10 import org.melati.poem.BinaryPoemType;
11 import org.melati.poem.NullTypeMismatchPoemException;
12 import org.melati.poem.SQLPoemType;
13 import org.melati.poem.SQLSeriousPoemException;
14 import org.melati.poem.dbms.AnsiStandard;
15
16
17
18
19
20
21 public class NotNullableBinaryPoemTypeTest extends SizedAtomPoemTypeSpec<byte[]> {
22
23 public NotNullableBinaryPoemTypeTest() {
24 }
25
26 public NotNullableBinaryPoemTypeTest(String name) {
27 super(name);
28 }
29
30 void setObjectUnderTest() {
31 it = new BinaryPoemType(false, 20);
32 }
33
34
35
36
37 public void testQuotedRaw() {
38 assertEquals("'" + new String(Base64.encodeBase64(new byte[20])) + "'",
39 ((SQLPoemType<byte[]>)it).quotedRaw(new byte[20]));
40
41 }
42
43
44
45
46 public void testToDsdType() {
47 assertEquals("byte[]", it.toDsdType());
48
49 }
50
51
52
53
54
55 public void testSetRaw() {
56 try {
57 ((SQLPoemType<byte[]>)it).setRaw((PreparedStatement)null, 1, null);
58 fail("Should have blown up");
59 } catch (NullPointerException e) {
60 e = null;
61 } catch (NullTypeMismatchPoemException e2) {
62 assertFalse(it.getNullable());
63 e2 = null;
64 }
65 try {
66 ((SQLPoemType<byte[]>)it).setRaw((PreparedStatement)null, 1, new byte[20]);
67 fail("Should have blown up");
68
69 } catch (NullTypeMismatchPoemException e2) {
70 assertFalse(it.getNullable());
71 e2 = null;
72 } catch (NullPointerException e3) {
73 e3 = null;
74 }
75 }
76
77
78
79
80 public void testRawOfString() {
81 super.testRawOfString();
82 byte[] b = (byte[])it.rawOfString("TWFuIGlzIGRpc3R=" );
83 assertEquals(11, b.length);
84 assertEquals("Man is dist", new String(b));
85 }
86
87
88
89
90 public void testToString() {
91 assertEquals("binary(20)",it.toString());
92 }
93
94
95
96
97
98
99 public void testAssertValidRaw() {
100 super.testAssertValidRaw();
101 try {
102 it.assertValidRaw(new byte[33]);
103 fail("Should have blown up");
104 } catch (BinaryLengthValidationPoemException e) {
105 e = null;
106 }
107
108 }
109
110
111
112
113
114 public void testSqlDefinition() {
115 super.testSqlDefinition();
116 BinaryPoemType it2 = (BinaryPoemType)((BinaryPoemType)it).withSize(-1);
117 it2.sqlDefinition(getDb().getDbms());
118 try {
119 it2.sqlDefinition(new AnsiStandard());
120 } catch (SQLSeriousPoemException e) {
121 e = null;
122 }
123 }
124
125 }