Java 类com.amazonaws.services.lambda.runtime.events.SNSEvent.SNS 实例源码

项目:Java-9-Programming-Blueprints    文件:SnsEventHandlerTest.java   
public void testHandleRequest() {
    System.out.println("handleRequest");

    SNS sns = new SNS();
    sns.setMessage("test message");

    SNSRecord record = new SNSRecord();
    record.setSns(sns);

    SNSEvent request = new SNSEvent();
    List<SNSRecord> records = new ArrayList<>();
    records.add(record);
    request.setRecords(records);

    Context context = new TestContext();
    SnsEventHandler instance = new SnsEventHandler();

    instance.handleRequest(request, context);
}
项目:game-of-life    文件:BoardImageGenerator.java   
@Override
public Object handleRequest(SNSEvent snsEvent, Context context) {
    logger = context.getLogger();
    awsHelper = new AWSHelper(logger);

    logger.log("Input: " + snsEvent);

    List<SNSRecord> records = snsEvent.getRecords();
    logger.log("Passed 001");
    SNSRecord record = records.get(0);
    logger.log("Passed 002");
    SNS sns = record.getSNS();
    logger.log("Passed 003");
    String boardToProcess = sns.getMessage();
    logger.log("Passed 004");


    processBoard(boardToProcess);
    logger.log("Passed 005");

    return null;
}
项目:game-of-life    文件:BoardCalculator.java   
@Override
public Object handleRequest(SNSEvent snsEvent, Context context) {

    awsHelper = new AWSHelper(context.getLogger());

    logger = context.getLogger();
    logger.log("Input: " + snsEvent);
    // You gotta love Java's deep objects...
    List<SNSRecord> records = snsEvent.getRecords();
    logger.log("Passed 001");
    SNSRecord record = records.get(0);
    logger.log("Passed 002");
    SNS sns = record.getSNS();
    logger.log("Passed 003");
    String sessionId = sns.getMessage();
    logger.log("Passed 004");


    context.getLogger().log("Game of Life Session ID: " + sessionId);
    logger.log("Passed 005");

    calculateBoards(sessionId, NUMBER_OF_BOARDS);
    logger.log("Passed 006");
    return sessionId;
}
项目:jrestless    文件:SnsRequestHandler.java   
/**
 * Creates the request and base URI for the actual request made to the
 * Jersey container.
 * <p>
 * The default implementation constructs
 * <ol>
 * <li>the request URI by using the topic
 * name (the last part of the topic arn) and concatenates the subject if one
 * is set: {@code topicName + "/" + subject}
 * <li>the base URI is set to "/", always
 * </ol>
 *
 * @param snsRecordAndContext
 * @return the request and base URI
 */
@Nonnull
protected RequestAndBaseUri getRequestAndBaseUri(@Nonnull SnsRecordAndLambdaContext snsRecordAndContext) {
    SNS sns = snsRecordAndContext.getSnsRecord().getSNS();
    String subject = sns.getSubject();
    String topicArn = sns.getTopicArn();
    int lastColonIndex = topicArn.lastIndexOf(':');
    String topicName = topicArn.substring(lastColonIndex + 1);
    URI requestUri;
    if (subject != null && !subject.trim().isEmpty()) {
        requestUri = URI.create("/" + topicName + "/" + subject);
    } else {
        requestUri = URI.create("/" + topicName);
    }
    return new RequestAndBaseUri(BASE_ROOT_URI, requestUri);
}
项目:jrestless    文件:SnsRequestHandlerTest.java   
@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);
}
项目:jrestless    文件:SnsRequestHandlerTest.java   
@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);
}
项目:jrestless    文件:SnsRequestHandlerTest.java   
@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);
}
项目:jrestless    文件:SnsRequestHandlerTest.java   
private SnsRecordAndLambdaContext createMinimalRequest() {
    SNS sns = new SNS();
    sns.setTopicArn(":t");
    SNSRecord snsRecord = new SNSRecord();
    snsRecord.setSns(sns);
    return new SnsRecordAndLambdaContext(snsRecord, null);
}
项目:jrestless    文件:SnsRequestHandlerIntTest.java   
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;
}
项目:jrestless    文件:SnsRequestHandlerIntTest.java   
void injectedSns(SNS sns);