1
1
package org .apache .ibatis .submitted .blobtest ;
2
2
3
3
import static junit .framework .Assert .assertEquals ;
4
+ import static junit .framework .Assert .assertTrue ;
4
5
5
6
import java .io .Reader ;
6
7
import java .sql .Connection ;
13
14
import org .apache .ibatis .session .SqlSessionFactory ;
14
15
import org .apache .ibatis .session .SqlSessionFactoryBuilder ;
15
16
import org .junit .BeforeClass ;
16
- import org .junit .Ignore ;
17
17
import org .junit .Test ;
18
18
19
19
public class BlobTest {
@@ -48,7 +48,10 @@ public static void initDatabase() throws Exception {
48
48
}
49
49
50
50
@ Test
51
- @ Ignore ("Breaks the build currently due to NPE at selectAll" )
51
+ /**
52
+ * This test demonstrates the use of type aliases for primitive types
53
+ * in constructor based result maps
54
+ */
52
55
public void testInsertBlobThenSelectAll () {
53
56
SqlSession sqlSession = sqlSessionFactory .openSession ();
54
57
try {
@@ -65,9 +68,32 @@ public void testInsertBlobThenSelectAll() {
65
68
assertEquals (1 , results .size ());
66
69
BlobRecord result = results .get (0 );
67
70
assertEquals (blobRecord .getId (), result .getId ());
68
- assertEquals ( blobRecord .getBlob (), result .getBlob ());
71
+ assertTrue ( blobsAreEqual ( blobRecord .getBlob (), result .getBlob () ));
69
72
} finally {
70
73
sqlSession .close ();
71
74
}
72
75
}
76
+
77
+ public static boolean blobsAreEqual (byte [] blob1 , byte [] blob2 ) {
78
+ if (blob1 == null ) {
79
+ return blob2 == null ;
80
+ }
81
+
82
+ if (blob2 == null ) {
83
+ return blob1 == null ;
84
+ }
85
+
86
+ boolean rc = blob1 .length == blob2 .length ;
87
+
88
+ if (rc ) {
89
+ for (int i = 0 ; i < blob1 .length ; i ++) {
90
+ if (blob1 [i ] != blob2 [i ]) {
91
+ rc = false ;
92
+ break ;
93
+ }
94
+ }
95
+ }
96
+
97
+ return rc ;
98
+ }
73
99
}
0 commit comments