31
31
import com .google .cloud .storage .BlobInfo ;
32
32
import com .google .cloud .storage .BucketInfo ;
33
33
import com .google .cloud .storage .Storage ;
34
+ import com .google .cloud .storage .Storage .BlobListOption ;
34
35
import com .google .cloud .storage .StorageException ;
35
36
import com .google .cloud .storage .testing .RemoteStorageHelper ;
36
37
import com .google .common .collect .ImmutableMap ;
37
38
import com .google .common .collect .Sets ;
38
39
40
+ import org .junit .After ;
39
41
import org .junit .AfterClass ;
42
+ import org .junit .Before ;
40
43
import org .junit .BeforeClass ;
41
44
import org .junit .Rule ;
42
45
import org .junit .Test ;
46
49
import java .io .InputStream ;
47
50
import java .net .URL ;
48
51
import java .net .URLConnection ;
52
+ import java .util .Iterator ;
49
53
import java .util .Set ;
50
54
import java .util .concurrent .ExecutionException ;
51
55
import java .util .concurrent .TimeUnit ;
@@ -71,7 +75,6 @@ public static void beforeClass() {
71
75
RemoteStorageHelper helper = RemoteStorageHelper .create ();
72
76
storage = helper .getOptions ().getService ();
73
77
storage .create (BucketInfo .of (BUCKET ));
74
- blob = storage .create (BlobInfo .newBuilder (BUCKET , BLOB ).build ());
75
78
}
76
79
77
80
@ AfterClass
@@ -84,6 +87,18 @@ public static void afterClass() throws ExecutionException, InterruptedException
84
87
}
85
88
}
86
89
90
+ @ Before
91
+ public void before () {
92
+ blob = storage .create (BlobInfo .newBuilder (BUCKET , BLOB ).build ());
93
+ }
94
+
95
+ @ After
96
+ public void after () {
97
+ for (BlobInfo info : storage .list (BUCKET , BlobListOption .versions (true )).getValues ()) {
98
+ storage .delete (info .getBlobId ());
99
+ }
100
+ }
101
+
87
102
@ Test
88
103
public void testBlob () throws IOException {
89
104
BlobSnippets blobSnippets = new BlobSnippets (blob );
@@ -137,4 +152,21 @@ public void testBlob() throws IOException {
137
152
assertNull (blobSnippets .getAcl ());
138
153
storage .delete (BlobId .of (BUCKET , BLOB ));
139
154
}
155
+
156
+ @ Test
157
+ public void testMoveBlob () throws IOException {
158
+ BlobSnippets blobSnippets = new BlobSnippets (blob );
159
+
160
+ Blob movedBlob = blobSnippets .moveTo (BUCKET , "moveBlob" );
161
+ assertNotNull (movedBlob );
162
+
163
+ // Assert that the destination blob exists
164
+ Iterator <Blob > blobs = storage .list (BUCKET ).iterateAll ();
165
+ Blob moveBlob = blobs .next ();
166
+ assertEquals (BUCKET , moveBlob .getBucket ());
167
+ assertEquals ("moveBlob" , moveBlob .getName ());
168
+
169
+ // Assert that the old blob doesn't exist
170
+ assertFalse (blobs .hasNext ());
171
+ }
140
172
}
0 commit comments