@@ -18,6 +18,10 @@ import spock.lang.Specification
1818import static com.commercehub.jclouds.gridfs.blobstore.Constants.GRIDFS_URI_SCHEME
1919
2020class GridFSBlobStoreSpec extends Specification {
21+ private static final HOST = " localhost"
22+ private static final PORT = 27017
23+ private static final GRIDFS_ENDPOINT = " ${ GRIDFS_URI_SCHEME} ://${ HOST} :${ PORT} "
24+ private static final STANDARD_CONNECTION_STRING = " mongodb://${ HOST} :${ PORT} "
2125 private static final DB_NAME = this . simpleName
2226 private static final BUCKET = " bk1"
2327 private static final CONTAINER = " ${ DB_NAME} /${ BUCKET} "
@@ -28,36 +32,53 @@ class GridFSBlobStoreSpec extends Specification {
2832
2933 @Shared
3034 private Mongo mongo
31- @Shared
35+
3236 private BlobStoreContext context
33- @Shared
3437 private BlobStore blobStore
3538
3639 def setupSpec () {
37- String host = " localhost"
38- int port = 27017
39- mongo = new MongoClient (host, port)
40+ mongo = new MongoClient (HOST , PORT )
4041 mongo. getDB(DB_NAME ). dropDatabase()
41- // TODO: use embedded mongo
42- def overrides = new Properties ()
43- overrides. setProperty(Constants . PROPERTY_ENDPOINT , " ${ GRIDFS_URI_SCHEME} ://${ host} :${ port} " );
44- context = ContextBuilder . newBuilder(" gridfs" )
45- .overrides(overrides)
46- .buildView(BlobStoreContext )
47- blobStore = context. getBlobStore()
4842 }
4943
5044 def cleanupSpec () {
51- if (context) {
52- context. close()
53- }
5445 if (mongo) {
5546 mongo. getDB(DB_NAME ). dropDatabase()
5647 mongo. close()
5748 }
5849 }
5950
51+ def cleanup () {
52+ if (context) {
53+ context. close()
54+ }
55+ }
56+
57+ private void initBlobStore (String endpoint ) {
58+ // TODO: use embedded mongo
59+ def overrides = new Properties ()
60+ overrides. setProperty(Constants . PROPERTY_ENDPOINT , endpoint);
61+ context = ContextBuilder . newBuilder(" gridfs" )
62+ .overrides(overrides)
63+ .buildView(BlobStoreContext )
64+ blobStore = context. getBlobStore()
65+ }
66+
67+ private void initBlobStore () {
68+ initBlobStore(STANDARD_CONNECTION_STRING )
69+ }
70+
71+ def " can create blobStore with 'gridfs://' endpoint" () {
72+ initBlobStore(GRIDFS_ENDPOINT )
73+ }
74+
75+ def " can create blobStore with standard connection string endpoint" () {
76+ initBlobStore(STANDARD_CONNECTION_STRING )
77+ }
78+
6079 def " can create and delete containers without create container options" () {
80+ initBlobStore()
81+
6182 assert ! blobStore. containerExists(CONTAINER )
6283
6384 expect :
@@ -69,6 +90,8 @@ class GridFSBlobStoreSpec extends Specification {
6990 }
7091
7192 def " can create and delete containers with NONE create container options" () {
93+ initBlobStore()
94+
7295 assert ! blobStore. containerExists(CONTAINER )
7396
7497 expect :
@@ -80,6 +103,8 @@ class GridFSBlobStoreSpec extends Specification {
80103 }
81104
82105 def " doesn't allow creating containers with public read" () {
106+ initBlobStore()
107+
83108 when :
84109 blobStore. createContainerInLocation(null , CONTAINER , CreateContainerOptions.Builder . publicRead())
85110
@@ -89,6 +114,8 @@ class GridFSBlobStoreSpec extends Specification {
89114 }
90115
91116 def " can create and delete blobs without put options" () {
117+ initBlobStore()
118+
92119 assert ! blobStore. blobExists(CONTAINER , BLOB_NAME )
93120 // TODO: test put when container doesn't exist
94121 // TODO: test remove when container doesn't exist
@@ -108,6 +135,8 @@ class GridFSBlobStoreSpec extends Specification {
108135 }
109136
110137 def " can create and delete blobs with multipart put options" () {
138+ initBlobStore()
139+
111140 assert ! blobStore. blobExists(CONTAINER , BLOB_NAME )
112141
113142 expect :
@@ -123,6 +152,8 @@ class GridFSBlobStoreSpec extends Specification {
123152 }
124153
125154 def " doesn't allow put with null payload" () {
155+ initBlobStore()
156+
126157 when :
127158 blobStore. putBlob(CONTAINER , blobStore. blobBuilder(BLOB_NAME ). build())
128159
@@ -131,6 +162,8 @@ class GridFSBlobStoreSpec extends Specification {
131162 }
132163
133164 def " doesn't allow put with non-multipart" () {
165+ initBlobStore()
166+
134167 when :
135168 def payload = blobStore. blobBuilder(BLOB_NAME ). payload(PAYLOAD ). build()
136169 blobStore. putBlob(CONTAINER , payload, PutOptions.Builder . multipart(false ))
@@ -141,6 +174,8 @@ class GridFSBlobStoreSpec extends Specification {
141174 }
142175
143176 def " get from non-existent container throws exception" () {
177+ initBlobStore()
178+
144179 when :
145180 blobStore. getBlob(" containerDoesNotExist" , " blobDoesNotExist" )
146181
@@ -149,11 +184,15 @@ class GridFSBlobStoreSpec extends Specification {
149184 }
150185
151186 def " get non-existent blob returns null" () {
187+ initBlobStore()
188+
152189 expect :
153190 blobStore. getBlob(CONTAINER , " blobDoesNotExist" ) == null
154191 }
155192
156193 def " can retrieve blob without get options" () {
194+ initBlobStore()
195+
157196 when :
158197 def payload = blobStore. blobBuilder(BLOB_NAME ). payload(PAYLOAD ). contentType(CONTENT_TYPE )
159198 .userMetadata([user : " joe" , type : " profilePicture" ]). build()
@@ -200,6 +239,8 @@ class GridFSBlobStoreSpec extends Specification {
200239 }
201240
202241 def " get options not supported" () {
242+ initBlobStore()
243+
203244 when :
204245 blobStore. getBlob(CONTAINER , BLOB_NAME , GetOptions.Builder . ifETagDoesntMatch(PAYLOAD_MD5 ))
205246
@@ -232,6 +273,8 @@ class GridFSBlobStoreSpec extends Specification {
232273 }
233274
234275 def " list not supported" () {
276+ initBlobStore()
277+
235278 when :
236279 blobStore. list()
237280 then :
@@ -249,6 +292,8 @@ class GridFSBlobStoreSpec extends Specification {
249292 }
250293
251294 def " clearContainer not supported" () {
295+ initBlobStore()
296+
252297 when :
253298 blobStore. clearContainer(CONTAINER )
254299 then :
@@ -261,6 +306,8 @@ class GridFSBlobStoreSpec extends Specification {
261306 }
262307
263308 def " directory operations not supported" () {
309+ initBlobStore()
310+
264311 when :
265312 blobStore. createDirectory(CONTAINER , " myDirectory" )
266313 then :
@@ -278,13 +325,17 @@ class GridFSBlobStoreSpec extends Specification {
278325 }
279326
280327 def " blobMetadata not supported" () {
328+ initBlobStore()
329+
281330 when :
282331 blobStore. blobMetadata(CONTAINER , BLOB_NAME )
283332 then :
284333 thrown(UnsupportedOperationException )
285334 }
286335
287336 def " countBlobs not supported" () {
337+ initBlobStore()
338+
288339 when :
289340 blobStore. countBlobs(CONTAINER )
290341 then :
0 commit comments