super.tearDown();
}
@Test
public void testSendRawMessageAppearsInS3() throws Exception {
Connection testIMGConnection = createAndMockForIMGConnectionWithOutboundTypes(OutboundDataType.RAW);
testIMGConnection.setUser(testUser);
testIMGConnection.setAccount(testAccount);
testIMGConnection.setId(null);
connectionService.createConnection(testIMGConnection);
JSONObject imgPayload = TestUtils.createValidSampleIMGPayload();
Response response = gatewayResource.createCustomConnectionMessage(imgPayload); //magic happens here
//Start verification
if (response.getStatus() != 201) {
ErrorMessage e = (ErrorMessage) response.getEntity();
Assert.fail("Unable to verify test due to IMG failure. Response has a status of " + response.getStatus() +
" and an error message of : " + e.getErrorMessage());
}
//Give enough time for this to trickle to SQS and back to server
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
ConnectionCredentials s3Creds = new ArrayList<>(
testIMGConnection.getOutboundConfigurations()).get(0).getCredentials();
s3TestUtils = new S3TestUtils(s3Creds);
String expectedBucketName = "com.streamreduce." + testIMGConnection.getAccount().getId();
String prefix = "raw/" + testIMGConnection.getId() + "/";
Blob payload = s3TestUtils.getFirstBlobFromS3ThatMatchesPrefix(expectedBucketName, prefix);
JSONObject jsonPayload = JSONObject.fromObject(IOUtils.toString(payload.getPayload().getInput()));
Assert.assertEquals(imgPayload,jsonPayload);
}