@Test
public void testSendInsightMessageDoesAppearInS3() throws Exception {
//Make sure if INSIGHT is an OutboundDataType that we send it to s3 for an SobaMessage with type NODEBELLY
JSONObject imgPayload = TestUtils.createValidSampleIMGPayload();
Connection testIMGConnection =
TestUtils.createIMGConnectionWithSpecificOutboundDatatypes(
OutboundDataType.INSIGHT);
testIMGConnection.setUser(testUser);
testIMGConnection.setAccount(testAccount);
testIMGConnection.setId(null);
connectionService.createConnection(testIMGConnection);
SobaMessage sobaMessage = new SobaMessage.Builder()
.connection(testIMGConnection)
.dateGenerated(System.currentTimeMillis())
.hashtags(Sets.newHashSet("#foo"))
.sender(testIMGConnection)
.transformedMessage(imgPayload.getString("message"))
.type(MessageType.NODEBELLY) //This is a fakeout... no Nodebelly/Insight Message looks like this.
.visibility(SobaObject.Visibility.ACCOUNT)
.build();
sobaMessage.setId(new ObjectId());
outboundStorageService.sendSobaMessage(sobaMessage, testIMGConnection);
Thread.sleep(TimeUnit.SECONDS.toMillis(10)); //give this some time to go through the queue
ConnectionCredentials creds = new ArrayList<>(
testIMGConnection.getOutboundConfigurations()).get(0).getCredentials();
s3TestUtils = new S3TestUtils(creds);
String expectedBucketName = "com.streamreduce." + testIMGConnection.getAccount().getId();
String prefix = "insight/" + sobaMessage.getConnectionId() + "/";
Blob payload = s3TestUtils.getFirstBlobFromS3ThatMatchesPrefix(expectedBucketName, prefix);
//Test that what made it to S3 is the same thing we get when we turn the sobaMessage into a dto
JSONObject actualJSONPayloadFromS3 = JSONObject.fromObject(IOUtils.toString(payload.getPayload().getInput()));