public PublishResult unmarshall(StaxUnmarshallerContext context) throws Exception { PublishResult publishResult = new PublishResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return publishResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("MessageId", targetDepth)) { publishResult.setMessageId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return publishResult; } } } }
public PublishResult unmarshall(StaxUnmarshallerContext context) throws Exception { PublishResult publishResult = new PublishResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("MessageId", targetDepth)) { publishResult.setMessageId(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return publishResult; }
@Override public PublishResult publish(String topicArn, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSNS amazonSNS) { // Nothing to do in the normal case since our unit tests aren't reading messages once they have been published. return new PublishResult().withMessageId(AbstractDaoTest.MESSAGE_ID); } }
@Override public PublishResult decode(InputStream inStream) throws CoderException, IOException { final String messageId = StringUtf8Coder.of().decode(inStream); return new PublishResult().withMessageId(messageId); }
@Bean @SuppressWarnings("unchecked") public AmazonSNSAsync amazonSNS() { AmazonSNSAsync mock = mock(AmazonSNSAsync.class); willAnswer(invocation -> { PublishResult publishResult = new PublishResult().withMessageId("111"); AsyncHandler<PublishRequest, PublishResult> asyncHandler = invocation.getArgument(1); asyncHandler.onSuccess(invocation.getArgument(0), publishResult); return new AsyncResult<>(publishResult); }) .given(mock) .publishAsync(any(PublishRequest.class), any(AsyncHandler.class)); return mock; }
@Test public void testPublish() { // Publish an SNS message without proxy. assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao.publish( new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, NO_HTTP_PROXY_HOST, NO_HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, NO_MESSAGE_HEADERS)); // Publish an SNS message using proxy settings. assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao .publish(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, NO_MESSAGE_HEADERS)); // Publish an SNS message with message headers. assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao .publish(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE)))); } }
public PublishResult unmarshall(StaxUnmarshallerContext context) throws Exception { PublishResult publishResult = new PublishResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("MessageId", targetDepth)) { publishResult.setMessageId(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return publishResult; }