3333import com .aliyun .oss .common .auth .Credentials ;
3434import com .aliyun .oss .common .auth .DefaultCredentialProvider ;
3535import com .aliyun .oss .common .auth .DefaultCredentials ;
36+ import com .aliyun .oss .internal .OSSConstants ;
37+ import com .aliyun .oss .model .*;
3638import junit .framework .Assert ;
3739
3840import org .junit .Test ;
3941
4042import com .aliyun .oss .OSSErrorCode ;
4143import com .aliyun .oss .OSSException ;
42- import com .aliyun .oss .model .ListVersionsRequest ;
43- import com .aliyun .oss .model .OSSVersionSummary ;
44- import com .aliyun .oss .model .VersionListing ;
45- import com .aliyun .oss .model .BucketVersioningConfiguration ;
46- import com .aliyun .oss .model .SetBucketVersioningRequest ;
44+ import com .aliyun .oss .model .DeleteVersionsRequest .KeyVersion ;
4745
4846public class ListVersionsTest extends TestBase {
4947
@@ -176,8 +174,7 @@ public void testListVersionsWithEncodingType() {
176174 // Unormal
177175 ListVersionsRequest listVersionsRequest = new ListVersionsRequest ()
178176 .withBucketName (bucketName )
179- .withPrefix (objectPrefix )
180- .withEncodingType (null );
177+ .withPrefix (objectPrefix );
181178
182179 ossClient .listVersions (listVersionsRequest );
183180 Assert .fail ("List version should not be successful." );
@@ -189,12 +186,19 @@ public void testListVersionsWithEncodingType() {
189186 // Normal
190187 ListVersionsRequest listVersionsRequest = new ListVersionsRequest ()
191188 .withBucketName (bucketName )
192- .withPrefix (objectPrefix );
189+ .withPrefix (objectPrefix )
190+ .withEncodingType (OSSConstants .URL_ENCODING );
193191
194192 VersionListing versionListing = ossClient .listVersions (listVersionsRequest );
195- for (OSSVersionSummary version : versionListing .getVersionSummaries ()) {
196- String decodedKey = URLDecoder .decode (version .getKey (), "UTF-8" );
197- Assert .assertTrue (existingKeys .contains (decodedKey ));
193+ if (versionListing .getVersionSummaries ().size () > 0 ) {
194+ List <KeyVersion > keyVersionsList = new ArrayList <KeyVersion >();
195+ for (OSSVersionSummary version : versionListing .getVersionSummaries ()) {
196+ String decodedKey = URLDecoder .decode (version .getKey (), "UTF-8" );
197+ Assert .assertTrue (existingKeys .contains (decodedKey ));
198+ keyVersionsList .add (new KeyVersion (version .getKey (), version .getVersionId ()));
199+ }
200+ DeleteVersionsRequest delVersionsRequest = new DeleteVersionsRequest (bucketName ).withKeys (keyVersionsList );
201+ ossClient .deleteVersions (delVersionsRequest );
198202 }
199203 Assert .assertNull (versionListing .getEncodingType ());
200204 } catch (Exception e ) {
0 commit comments