use of com.mercedesbenz.sechub.storage.core.S3Setup in project sechub by mercedes-benz.
the class S3RealLiveStorageTestMain method main.
public static void main(String[] args) throws IOException {
/* setup */
SharedVolumeSetup setup = createFakeSharedVolumeNotValid();
S3Setup s3Setup = createS3SetupByEnvironmentVariables();
MultiStorageService service = new MultiStorageService(setup, s3Setup);
UUID jobUUID = UUID.randomUUID();
JobStorage jobStorage = service.getJobStorage("test-only", jobUUID);
/* check preconditions */
boolean existsBefore = jobStorage.isExisting(S3_OBJECT_NAME);
String testDataAsString = "This is some test data as a simple string\nJust another line...";
/* store */
jobStorage.store(S3_OBJECT_NAME, new StringInputStream(testDataAsString));
boolean existsAfterStore = jobStorage.isExisting(S3_OBJECT_NAME);
/* fetch */
InputStream inputStream = jobStorage.fetch(S3_OBJECT_NAME);
InputStreamReader reader = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(reader);
String result = br.readLine();
br.close();
/* delete all */
jobStorage.deleteAll();
/* check delete done */
boolean existsAfterDelete = jobStorage.isExisting(S3_OBJECT_NAME);
System.out.println("exists before storage:" + existsBefore);
System.out.println("exists after storage:" + existsAfterStore);
System.out.println("fetched string from object store:" + result);
System.out.println("exists after delete:" + existsAfterDelete);
if (existsBefore) {
System.err.println("existed before!");
System.exit(1);
}
if (!existsAfterStore) {
System.err.println("was not stored!");
System.exit(1);
}
if (!testDataAsString.equals(result)) {
System.err.println("result was not as expected:" + result);
System.exit(1);
}
if (existsAfterDelete) {
System.err.println("data was not as expected:" + result);
System.exit(1);
}
}
use of com.mercedesbenz.sechub.storage.core.S3Setup in project sechub by mercedes-benz.
the class S3RealLiveStorageTestMain method createS3SetupByEnvironmentVariables.
private static S3Setup createS3SetupByEnvironmentVariables() {
String bucketURL = System.getenv("S3_ENDPOINT");
if (bucketURL == null || bucketURL.isEmpty()) {
throw new IllegalStateException("S3_ENDPOINT missing");
}
String bucketAccessKey = System.getenv("S3_ACCESSKEY");
if (bucketAccessKey == null || bucketAccessKey.isEmpty()) {
throw new IllegalStateException("S3_ACCESSKEY missing");
}
String bucketSecretKey = System.getenv("S3_SECRETKEY");
if (bucketSecretKey == null || bucketSecretKey.isEmpty()) {
throw new IllegalStateException("S3_SECRETKEY missing");
}
String bucketName = System.getenv("S3_BUCKET_NAME");
if (bucketName == null || bucketName.isEmpty()) {
throw new IllegalStateException("S3_BUCKET_NAME missing");
}
S3Setup s3Setup = new S3Setup() {
@Override
public String getAccessKey() {
return bucketAccessKey;
}
@Override
public String getSecretkey() {
return bucketSecretKey;
}
@Override
public String getEndPoint() {
return bucketURL;
}
@Override
public String getBucketName() {
return bucketName;
}
@Override
public boolean isAvailable() {
return true;
}
};
return s3Setup;
}
use of com.mercedesbenz.sechub.storage.core.S3Setup in project sechub by mercedes-benz.
the class S3RealLiveStorageManualTest method createS3SetupByEnvironmentVariables.
private static S3Setup createS3SetupByEnvironmentVariables() {
String bucketURL = System.getenv("S3_ENDPOINT");
if (bucketURL == null || bucketURL.isEmpty()) {
throw new IllegalStateException("S3_ENDPOINT missing");
}
String bucketAccessKey = System.getenv("S3_ACCESSKEY");
if (bucketAccessKey == null || bucketAccessKey.isEmpty()) {
throw new IllegalStateException("S3_ACCESSKEY missing");
}
String bucketSecretKey = System.getenv("S3_SECRETKEY");
if (bucketSecretKey == null || bucketSecretKey.isEmpty()) {
throw new IllegalStateException("S3_SECRETKEY missing");
}
String bucketName = System.getenv("S3_BUCKET_NAME");
if (bucketName == null || bucketName.isEmpty()) {
throw new IllegalStateException("S3_BUCKET_NAME missing");
}
S3Setup s3Setup = new S3Setup() {
@Override
public String getAccessKey() {
return bucketAccessKey;
}
@Override
public String getSecretkey() {
return bucketSecretKey;
}
@Override
public String getEndPoint() {
return bucketURL;
}
@Override
public String getBucketName() {
return bucketName;
}
@Override
public boolean isAvailable() {
return true;
}
};
return s3Setup;
}
use of com.mercedesbenz.sechub.storage.core.S3Setup in project sechub by mercedes-benz.
the class S3RealLiveStorageManualTest method manualTestByDeveloper.
@Test
@EnabledIfSystemProperty(named = TestConstants.MANUAL_TEST_BY_DEVELOPER, matches = "true", disabledReason = TestConstants.DESCRIPTION_DISABLED_BECAUSE_A_MANUAL_TEST_FOR_GENERATION)
void manualTestByDeveloper() throws Exception {
/* setup */
SharedVolumeSetup setup = createFakeSharedVolumeNotValid();
S3Setup s3Setup = createS3SetupByEnvironmentVariables();
MultiStorageService service = new MultiStorageService(setup, s3Setup);
UUID jobUUID = UUID.randomUUID();
JobStorage jobStorage = service.getJobStorage("test-only", jobUUID);
/* check preconditions */
boolean existsBefore = jobStorage.isExisting(S3_OBJECT_NAME);
String testDataAsString = "This is some test data as a simple string\nJust another line...";
/* store */
jobStorage.store(S3_OBJECT_NAME, new StringInputStream(testDataAsString));
boolean existsAfterStore = jobStorage.isExisting(S3_OBJECT_NAME);
/* fetch */
InputStream inputStream = jobStorage.fetch(S3_OBJECT_NAME);
InputStreamReader reader = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(reader);
String result = br.readLine();
br.close();
/* delete all */
jobStorage.deleteAll();
/* check delete done */
boolean existsAfterDelete = jobStorage.isExisting(S3_OBJECT_NAME);
System.out.println("exists before storage:" + existsBefore);
System.out.println("exists after storage:" + existsAfterStore);
System.out.println("fetched string from object store:" + result);
System.out.println("exists after delete:" + existsAfterDelete);
if (existsBefore) {
System.err.println("existed before!");
System.exit(1);
}
if (!existsAfterStore) {
System.err.println("was not stored!");
System.exit(1);
}
if (!testDataAsString.equals(result)) {
System.err.println("result was not as expected:" + result);
System.exit(1);
}
if (existsAfterDelete) {
System.err.println("data was not as expected:" + result);
System.exit(1);
}
}
Aggregations