-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #539 from 1010sachin/add_bucketsHelperITClass_branch
Add a new IntegrationTestHelper class for buckets.
- Loading branch information
Showing
7 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
java-manta-it/src/test/java/com/joyent/manta/client/helper/IntegrationTestHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.joyent.manta.client.helper; | ||
|
||
import com.joyent.manta.client.MantaClient; | ||
import com.joyent.manta.config.ConfigContext; | ||
import com.joyent.manta.config.IntegrationTestConfigContext; | ||
import com.joyent.manta.exception.MantaClientHttpResponseException; | ||
import com.joyent.manta.exception.MantaErrorCode; | ||
import org.apache.commons.lang3.BooleanUtils; | ||
import org.testng.SkipException; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
/** | ||
* A helper class that contains methods to assist in the Integration testing of | ||
* manta buckets functionality. | ||
* | ||
* @author <a href="https://github.com/1010sachin">Sachin Gupta</a> | ||
*/ | ||
|
||
public class IntegrationTestHelper { | ||
|
||
private static String setupBucketsPath(final ConfigContext config, final String testName) { | ||
String bucketPathPrefix = String.format("%s%sbuckets%s%s", config.getMantaHomeDirectory(), | ||
MantaClient.SEPARATOR, MantaClient.SEPARATOR, | ||
testName.toLowerCase() + UUID.randomUUID()); | ||
return bucketPathPrefix + MantaClient.SEPARATOR + "objects" + MantaClient.SEPARATOR; | ||
} | ||
|
||
private static boolean verifyBucketsSupport(final ConfigContext config, | ||
final MantaClient client) throws IOException { | ||
try { | ||
String path = String.format("%s%sbuckets", config.getMantaHomeDirectory(), | ||
MantaClient.SEPARATOR); | ||
client.options(path); | ||
} catch (MantaClientHttpResponseException me) { | ||
if (MantaErrorCode.RESOURCE_NOT_FOUND_ERROR.equals(me.getServerCode())) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public static void cleanupTestBucketOrDirectory(final MantaClient client, | ||
final String testPath) throws IOException { | ||
|
||
String bucketObjectsSubstring = String.format("%sobjects%s", MantaClient.SEPARATOR, | ||
MantaClient.SEPARATOR); | ||
if (testPath.contains(bucketObjectsSubstring)) { | ||
String bucketPath = testPath.substring(0, testPath.lastIndexOf(bucketObjectsSubstring)); | ||
//Delete bucket here | ||
} else { | ||
IntegrationTestConfigContext.cleanupTestDirectory(client, testPath); | ||
} | ||
} | ||
|
||
public static String setupTestPath(final ConfigContext config, | ||
final MantaClient client, | ||
final String testName, | ||
final String testType) throws IOException { | ||
if ("buckets".equals(testType)) { | ||
if (BooleanUtils.isTrue(verifyBucketsSupport(config, client))) { | ||
return setupBucketsPath(config, testName); | ||
} else { | ||
throw new SkipException("Bucket operations not supported by the server"); | ||
} | ||
} | ||
|
||
return IntegrationTestConfigContext.generateBasePath(config, testName); | ||
} | ||
|
||
public static void createTestBucketOrDirectory(final MantaClient client, | ||
final String testPath, | ||
final String testType) throws IOException { | ||
if ("buckets".equals(testType)) { | ||
//Create bucket here | ||
} else { | ||
client.putDirectory(testPath, true); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters