Skip to content

Commit b1bb2a9

Browse files
committed
Fix the BLOB test so that it uses the registered aliases for primitive types
1 parent 115e999 commit b1bb2a9

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/test/java/org/apache/ibatis/submitted/blobtest/BlobMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<mapper namespace="org.apache.ibatis.submitted.blobtest.BlobMapper">
44
<resultMap type="org.apache.ibatis.submitted.blobtest.BlobRecord" id="blobRecordResult">
55
<constructor>
6-
<idArg column="id" javaType="int"/>
7-
<arg column="blob" javaType="byte[]"/>
6+
<idArg column="id" javaType="_int"/>
7+
<arg column="blob" javaType="_byte[]"/>
88
</constructor>
99
</resultMap>
1010

src/test/java/org/apache/ibatis/submitted/blobtest/BlobTest.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.apache.ibatis.submitted.blobtest;
22

33
import static junit.framework.Assert.assertEquals;
4+
import static junit.framework.Assert.assertTrue;
45

56
import java.io.Reader;
67
import java.sql.Connection;
@@ -13,7 +14,6 @@
1314
import org.apache.ibatis.session.SqlSessionFactory;
1415
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
1516
import org.junit.BeforeClass;
16-
import org.junit.Ignore;
1717
import org.junit.Test;
1818

1919
public class BlobTest {
@@ -48,7 +48,10 @@ public static void initDatabase() throws Exception {
4848
}
4949

5050
@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+
*/
5255
public void testInsertBlobThenSelectAll() {
5356
SqlSession sqlSession = sqlSessionFactory.openSession();
5457
try {
@@ -65,9 +68,32 @@ public void testInsertBlobThenSelectAll() {
6568
assertEquals(1, results.size());
6669
BlobRecord result = results.get(0);
6770
assertEquals (blobRecord.getId(), result.getId());
68-
assertEquals (blobRecord.getBlob(), result.getBlob());
71+
assertTrue (blobsAreEqual(blobRecord.getBlob(), result.getBlob()));
6972
} finally {
7073
sqlSession.close();
7174
}
7275
}
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+
}
7399
}

0 commit comments

Comments
 (0)