Skip to content

Commit a849eda

Browse files
committed
new gridfs tests
1 parent a85e6ba commit a849eda

3 files changed

Lines changed: 78 additions & 74 deletions

File tree

src/main/com/mongodb/gridfs/GridFSFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ else if ( key.equals( "_id" ) )
109109
_id = v;
110110
else if ( key.equals( "_ns" ) );
111111
else if ( key.equals( "filename" ) )
112-
_filename = v.toString();
112+
_filename = v == null ? null : v.toString();
113113
else if ( key.equals( "contentType" ) )
114114
_contentType = (String)v;
115115
else if ( key.equals( "length" ) )

src/test/com/mongodb/GridFSTest.java

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Copyright (C) 2008 10gen Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.gridfs;
18+
19+
import java.util.*;
20+
import java.util.regex.*;
21+
import java.io.*;
22+
23+
import org.testng.annotations.Test;
24+
25+
import com.mongodb.*;
26+
import com.mongodb.gridfs.*;
27+
import com.mongodb.util.*;
28+
29+
public class GridFSTest extends TestCase {
30+
31+
public GridFSTest()
32+
throws IOException , MongoException {
33+
super();
34+
_db = new Mongo( "127.0.0.1" , "cursortest" );
35+
_fs = new GridFS( _db );
36+
}
37+
38+
void testInOut( String s )
39+
throws Exception {
40+
GridFSInputFile in = _fs.createFile( s.getBytes() );
41+
in.save();
42+
GridFSDBFile out = _fs.findOne( new BasicDBObject( "_id" , in.getId() ) );
43+
assert( out.getId().equals( in.getId() ) );
44+
45+
ByteArrayOutputStream bout = new ByteArrayOutputStream();
46+
out.writeTo( bout );
47+
String outString = new String( bout.toByteArray() );
48+
assert( outString.equals( s ) );
49+
assert( false );
50+
}
51+
52+
@Test(groups = {"basic"})
53+
public void testSmall()
54+
throws Exception {
55+
testInOut( "this is a simple test" );
56+
}
57+
58+
@Test(groups = {"basic"})
59+
public void testBig()
60+
throws Exception {
61+
int target = GridFS.DEFAULT_CHUNKSIZE * 3;
62+
StringBuilder buf = new StringBuilder( target );
63+
while ( buf.length() < target )
64+
buf.append( "asdasdkjasldkjasldjlasjdlajsdljasldjlasjdlkasjdlaskjdlaskjdlsakjdlaskjdasldjsad" );
65+
String s = buf.toString();
66+
testInOut( s );
67+
}
68+
69+
final Mongo _db;
70+
final GridFS _fs;
71+
72+
public static void main( String args[] )
73+
throws Exception {
74+
(new GridFSTest()).runConsole();
75+
}
76+
77+
}

0 commit comments

Comments
 (0)