use of com.amazonaws.services.lambda.runtime.events.SNSEvent in project bender by Nextdoor.
the class SNSS3HandlerTest method getTestEvent.
@Override
public SNSEvent getTestEvent() throws Exception {
/*
* Upload a test resoruce to the mock S3
*/
String payload = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
this.client.putObject(S3_BUCKET, "basic_input.log", payload);
/*
* Create a S3EventNotification event
*/
S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
S3BucketEntity bucketEntity = new S3BucketEntity(S3_BUCKET, null, null);
S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, "1970-01-01T00:00:00.000Z", null, null, null, entity, null);
List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
notifications.add(rec);
/*
* Wrap as an SNS Event
*/
S3EventNotification event = new S3EventNotification(notifications);
SNSEvent.SNS sns = new SNSEvent.SNS();
sns.setMessage(event.toJson());
SNSEvent snsEvent = new SNSEvent();
ArrayList<SNSRecord> snsRecords = new ArrayList<SNSRecord>(1);
SNSRecord snsRecord = new SNSRecord();
snsRecord.setEventSource("aws:sns");
snsRecord.setEventVersion("1.0");
snsRecord.setEventSubscriptionArn("arn");
snsRecord.setSns(sns);
snsRecords.add(snsRecord);
snsEvent.setRecords(snsRecords);
return snsEvent;
}
use of com.amazonaws.services.lambda.runtime.events.SNSEvent in project bender by Nextdoor.
the class SNSS3HandlerTest method getTestEvent.
private SNSEvent getTestEvent(String bucket, boolean doPut) throws Exception {
/*
* Upload a test resoruce to the mock S3
*/
if (doPut) {
String payload = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
this.client.putObject(bucket, "basic_input.log", payload);
}
/*
* Create a S3EventNotification event
*/
S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null);
S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, "1970-01-01T00:00:00.000Z", null, null, null, entity, null);
List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
notifications.add(rec);
/*
* Wrap as an SNS Event
*/
S3EventNotification event = new S3EventNotification(notifications);
SNSEvent.SNS sns = new SNSEvent.SNS();
sns.setMessage(event.toJson());
SNSEvent snsEvent = new SNSEvent();
ArrayList<SNSRecord> snsRecords = new ArrayList<SNSRecord>(1);
SNSRecord snsRecord = new SNSRecord();
snsRecord.setEventSource("aws:sns");
snsRecord.setEventVersion("1.0");
snsRecord.setEventSubscriptionArn("arn");
snsRecord.setSns(sns);
snsRecords.add(snsRecord);
snsEvent.setRecords(snsRecords);
return snsEvent;
}
use of com.amazonaws.services.lambda.runtime.events.SNSEvent in project bender by Nextdoor.
the class SNSS3HandlerTest method testExceptionHandlingd.
@Test
public void testExceptionHandlingd() throws Throwable {
BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_test_sns.json";
TestContext ctx = new TestContext();
ctx.setFunctionName("unittest");
ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");
/*
* Invoke handler
*/
SNSS3Handler fhandler = (SNSS3Handler) getHandler();
fhandler.init(ctx);
IpcSenderService ipcSpy = spy(fhandler.getIpcService());
doThrow(new TransportException("expected")).when(ipcSpy).shutdown();
fhandler.setIpcService(ipcSpy);
AmazonSNSClient mockClient = mock(AmazonSNSClient.class);
AmazonSNSClientFactory mockClientFactory = mock(AmazonSNSClientFactory.class);
doReturn(mockClient).when(mockClientFactory).newInstance();
fhandler.snsClientFactory = mockClientFactory;
SNSEvent event = getTestEvent();
try {
fhandler.handler(event, ctx);
} catch (Exception e) {
}
verify(mockClient, times(1)).publish("foo", "basic_input.log", "SNSS3Handler Failed");
}
Aggregations