Java Code Examples for com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord#setSns()

The following examples show how to use com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord#setSns() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnsRequestHandlerTest.java    From jrestless with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void delegateRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() {

	Context context = mock(Context.class);
	SNS sns = new SNS();
	sns.setTopicArn(":t");
	SNSRecord snsRecord = new SNSRecord();
	snsRecord.setSns(sns);

	RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, snsRecord);

	Ref<SNSRecord> snsRef = mock(Ref.class);
	Ref<Context> contextRef = mock(Ref.class);

	InjectionManager injectionManager = mock(InjectionManager.class);
	when(injectionManager.getInstance(SNS_RECORD_TYPE)).thenReturn(snsRef);
	when(injectionManager.getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE)).thenReturn(contextRef);

	requestScopedInitializer.initialize(injectionManager);

	verify(snsRef).set(snsRecord);
	verify(contextRef).set(context);
}
 
Example 2
Source File: SnsRequestHandlerTest.java    From jrestless with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void createResponseWriter_writeResponse_Always_ShouldDelegateResponseToHandler() throws IOException {
	SnsRecordAndLambdaContext reqAndContext = mock(SnsRecordAndLambdaContext.class);
	SNS sns = new SNS();
	sns.setTopicArn(":t");
	SNSRecord snsRecord = new SNSRecord();
	snsRecord.setSns(sns);
	when(reqAndContext.getSnsRecord()).thenReturn(snsRecord);

	StatusType statusType = mock(StatusType.class);
	Map<String, List<String>> headers = mock(Map.class);
	ByteArrayOutputStream entityOutputStream = mock(ByteArrayOutputStream.class);
	snsHandler.createResponseWriter(reqAndContext).writeResponse(statusType, headers, entityOutputStream);
	verify(snsHandler).handleReponse(reqAndContext, statusType, headers, entityOutputStream);
}
 
Example 3
Source File: SnsRequestHandlerTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@Test
public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() {

	Context context = mock(Context.class);
	SNS sns = new SNS();
	sns.setTopicArn(":t");
	SNSRecord snsRecord = new SNSRecord();
	snsRecord.setSns(sns);

	RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, snsRecord);

	InjectionManager injectionManager = mock(InjectionManager.class);
	requestScopedInitializer.initialize(injectionManager);
}
 
Example 4
Source File: SnsRequestHandlerTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
private SnsRecordAndLambdaContext createMinimalRequest() {
	SNS sns = new SNS();
	sns.setTopicArn(":t");
	SNSRecord snsRecord = new SNSRecord();
	snsRecord.setSns(sns);
	return new SnsRecordAndLambdaContext(snsRecord, null);
}
 
Example 5
Source File: SnsRequestHandlerIntTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
private SNSRecord createSnsRecord(String topicArn, String subject) {
	SNS sns = new SNS();
	sns.setTopicArn(topicArn);
	sns.setSubject(subject);
	SNSRecord snsRecord = new SNSRecord();
	snsRecord.setSns(sns);
	return snsRecord;
}
 
Example 6
Source File: SNSS3HandlerTest.java    From bender with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 7
Source File: SNSS3HandlerTest.java    From bender with Apache License 2.0 4 votes vote down vote up
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;
}