SnsRequestHandler extends SimpleRequestHandler<SnsRecordAndLambdaContext, Void> { @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); } protected  SnsRequestHandler(); void handleReponse(SnsRecordAndLambdaContext snsRecordAndContext, StatusType statusType,
			Map<String, List<String>> headers, ByteArrayOutputStream entityOutputStream);  }
@Test public void getRequestAndBaseUri_TopicArnAndNoSubjectGiven_ShouldCreateUriUsingTopicName() { SnsRecordAndLambdaContext reqAndContext = createMinimalRequest(); reqAndContext.getSnsRecord().getSNS().setTopicArn("a:b:c"); RequestAndBaseUri actual = new SnsRequestHandlerImpl().getRequestAndBaseUri(reqAndContext); assertEquals(URI.create("/c"), actual.getRequestUri()); assertEquals(URI.create("/"), actual.getBaseUri()); }
@Test public void getRequestAndBaseUri_TopicArnAndBlankSubjectGiven_ShouldCreateUriUsingTopicName() { SnsRecordAndLambdaContext reqAndContext = createMinimalRequest(); reqAndContext.getSnsRecord().getSNS().setTopicArn("a:b:c"); reqAndContext.getSnsRecord().getSNS().setSubject(" "); RequestAndBaseUri actual = new SnsRequestHandlerImpl().getRequestAndBaseUri(reqAndContext); assertEquals(URI.create("/c"), actual.getRequestUri()); assertEquals(URI.create("/"), actual.getBaseUri()); }
@Test public void getRequestAndBaseUri_TopicArnAndSubjectGiven_ShouldCreateUriUsingTopicNameAndSubject() { SnsRecordAndLambdaContext reqAndContext = createMinimalRequest(); reqAndContext.getSnsRecord().getSNS().setTopicArn("a:b:c"); reqAndContext.getSnsRecord().getSNS().setSubject("someSubject"); RequestAndBaseUri actual = new SnsRequestHandlerImpl().getRequestAndBaseUri(reqAndContext); assertEquals(URI.create("/c/someSubject"), actual.getRequestUri()); assertEquals(URI.create("/"), actual.getBaseUri()); }