23
23
import java .util .*;
24
24
import java .util .regex .Pattern ;
25
25
26
+ import org .bson .BSON ;
26
27
import org .bson .Transformer ;
27
28
import org .bson .types .*;
28
29
import org .testng .annotations .Test ;
@@ -184,7 +185,7 @@ public void testBinary()
184
185
bb .order ( Bytes .ORDER );
185
186
bb .putInt ( 5 );
186
187
bb .put ( "eliot" .getBytes () );
187
- out .put ( "a" , new Binary ( ( byte ) 2 , raw ) );
188
+ out .put ( "a" , "eliot" . getBytes ( ) );
188
189
c .save ( out );
189
190
190
191
out = c .findOne ();
@@ -198,6 +199,39 @@ public void testBinary()
198
199
assertEquals ( Util .toHex ( raw ) , Util .toHex ( blah .getData () ) );
199
200
}
200
201
202
+ }
203
+
204
+ @ Test
205
+ public void testBinaryOld ()
206
+ throws MongoException {
207
+ DBCollection c = _db .getCollection ( "testBinary" );
208
+ c .drop ();
209
+ c .save ( BasicDBObjectBuilder .start ().add ( "a" , "eliot" .getBytes () ).get () );
210
+
211
+ DBObject out = c .findOne ();
212
+ byte [] b = (byte [])(out .get ( "a" ) );
213
+ assertEquals ( "eliot" , new String ( b ) );
214
+
215
+ {
216
+ byte [] raw = new byte [9 ];
217
+ ByteBuffer bb = ByteBuffer .wrap ( raw );
218
+ bb .order ( Bytes .ORDER );
219
+ bb .putInt ( 5 );
220
+ bb .put ( "eliot" .getBytes () );
221
+ out .put ( "a" , new Binary ( BSON .B_BINARY , "eliot" .getBytes () ) );
222
+ c .save ( out );
223
+
224
+ out = c .findOne ();
225
+ Binary blah = (Binary )(out .get ( "a" ) );
226
+ assertEquals ( "eliot" , new String ( blah .getData () ) );
227
+
228
+ out .put ( "a" , new Binary ( (byte )111 , raw ) );
229
+ c .save ( out );
230
+ blah = (Binary )c .findOne ().get ( "a" );
231
+ assertEquals ( 111 , blah .getType () );
232
+ assertEquals ( Util .toHex ( raw ) , Util .toHex ( blah .getData () ) );
233
+ }
234
+
201
235
}
202
236
@ Test
203
237
public void testUUID ()
0 commit comments