Search in sources :

Example 1 with PublishToIoTCoreResponse

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));
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) PublishToIoTCoreResponse(software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreResponse) PublishRequest(com.aws.greengrass.mqttclient.PublishRequest) PublishToIoTCoreRequest(software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest) Test(org.junit.jupiter.api.Test)

Aggregations

PublishRequest (com.aws.greengrass.mqttclient.PublishRequest)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Test (org.junit.jupiter.api.Test)1 PublishToIoTCoreRequest (software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest)1 PublishToIoTCoreResponse (software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreResponse)1