use of software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreResponse in project aws-greengrass-nucleus by aws-greengrass.
the class MqttProxyIPCAgentTest method GIVEN_MqttProxyIPCAgent_WHEN_publish_on_topic_THEN_message_published.
@Test
void GIVEN_MqttProxyIPCAgent_WHEN_publish_on_topic_THEN_message_published() throws Exception {
PublishToIoTCoreRequest publishToIoTCoreRequest = new PublishToIoTCoreRequest();
publishToIoTCoreRequest.setPayload(TEST_PAYLOAD);
publishToIoTCoreRequest.setTopicName(TEST_TOPIC);
publishToIoTCoreRequest.setQos(QOS.AT_LEAST_ONCE);
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
completableFuture.complete(0);
when(mqttClient.publish(any())).thenReturn(completableFuture);
when(authorizationHandler.isAuthorized(any(), any(), any())).thenReturn(true);
ArgumentCaptor<PublishRequest> publishRequestArgumentCaptor = ArgumentCaptor.forClass(PublishRequest.class);
try (MqttProxyIPCAgent.PublishToIoTCoreOperationHandler publishToIoTCoreOperationHandler = mqttProxyIPCAgent.getPublishToIoTCoreOperationHandler(mockContext)) {
PublishToIoTCoreResponse publishToIoTCoreResponse = publishToIoTCoreOperationHandler.handleRequest(publishToIoTCoreRequest);
assertNotNull(publishToIoTCoreResponse);
verify(authorizationHandler).isAuthorized(MQTT_PROXY_SERVICE_NAME, Permission.builder().principal(TEST_SERVICE).operation(GreengrassCoreIPCService.PUBLISH_TO_IOT_CORE).resource(TEST_TOPIC).build(), ResourceLookupPolicy.MQTT_STYLE);
verify(mqttClient).publish(publishRequestArgumentCaptor.capture());
PublishRequest capturedPublishRequest = publishRequestArgumentCaptor.getValue();
assertThat(capturedPublishRequest.getPayload(), is(TEST_PAYLOAD));
assertThat(capturedPublishRequest.getTopic(), is(TEST_TOPIC));
assertThat(capturedPublishRequest.getQos(), is(QualityOfService.AT_LEAST_ONCE));
}
}
Aggregations