use of software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest in project aws-greengrass-nucleus by aws-greengrass.
the class MqttClientPublishTest method whenPublishGetSpoolerException.
private boolean whenPublishGetSpoolerException(Pair<String, byte[]> requestTopicPayload) {
PublishToIoTCoreRequest publishToIoTCoreRequest = new PublishToIoTCoreRequest();
publishToIoTCoreRequest.setTopicName(requestTopicPayload.getLeft());
publishToIoTCoreRequest.setPayload(requestTopicPayload.getRight());
publishToIoTCoreRequest.setQos(QOS.AT_LEAST_ONCE);
try {
greengrassCoreIPCClient.publishToIoTCore(publishToIoTCoreRequest, Optional.empty()).getResponse().get();
} catch (ExecutionException | InterruptedException e) {
return true;
}
return false;
}
use of software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest 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));
}
}
use of software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest in project aws-greengrass-nucleus by aws-greengrass.
the class MqttProxyIPCAgentTest method GIVEN_MqttProxyIPCAgent_WHEN_publish_with_no_qos_THEN_error_thrown.
@Test
void GIVEN_MqttProxyIPCAgent_WHEN_publish_with_no_qos_THEN_error_thrown() throws Exception {
PublishToIoTCoreRequest publishToIoTCoreRequest = new PublishToIoTCoreRequest();
publishToIoTCoreRequest.setPayload(TEST_PAYLOAD);
publishToIoTCoreRequest.setTopicName(TEST_TOPIC);
when(authorizationHandler.isAuthorized(any(), any(), any())).thenReturn(true);
try (MqttProxyIPCAgent.PublishToIoTCoreOperationHandler publishToIoTCoreOperationHandler = mqttProxyIPCAgent.getPublishToIoTCoreOperationHandler(mockContext)) {
assertThrows(InvalidArgumentsError.class, () -> {
publishToIoTCoreOperationHandler.handleRequest(publishToIoTCoreRequest);
});
}
}
use of software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest in project aws-greengrass-nucleus by aws-greengrass.
the class MqttProxyIPCAgentTest method GIVEN_MqttProxyIPCAgent_WHEN_publish_with_no_payload_THEN_error_thrown.
@Test
void GIVEN_MqttProxyIPCAgent_WHEN_publish_with_no_payload_THEN_error_thrown() throws Exception {
PublishToIoTCoreRequest publishToIoTCoreRequest = new PublishToIoTCoreRequest();
publishToIoTCoreRequest.setTopicName(TEST_TOPIC);
publishToIoTCoreRequest.setQos(QOS.AT_LEAST_ONCE);
when(authorizationHandler.isAuthorized(any(), any(), any())).thenReturn(true);
try (MqttProxyIPCAgent.PublishToIoTCoreOperationHandler publishToIoTCoreOperationHandler = mqttProxyIPCAgent.getPublishToIoTCoreOperationHandler(mockContext)) {
assertThrows(InvalidArgumentsError.class, () -> {
publishToIoTCoreOperationHandler.handleRequest(publishToIoTCoreRequest);
});
}
}
use of software.amazon.awssdk.aws.greengrass.model.PublishToIoTCoreRequest in project aws-greengrass-nucleus by aws-greengrass.
the class MqttProxyIPCAgentTest method GIVEN_full_mqtt_spool_WHEN_publish_on_topic_THEN_service_error_thrown.
@Test
void GIVEN_full_mqtt_spool_WHEN_publish_on_topic_THEN_service_error_thrown() throws Exception {
PublishToIoTCoreRequest publishToIoTCoreRequest = new PublishToIoTCoreRequest();
publishToIoTCoreRequest.setPayload(TEST_PAYLOAD);
publishToIoTCoreRequest.setTopicName(TEST_TOPIC);
publishToIoTCoreRequest.setQos(QOS.AT_LEAST_ONCE);
CompletableFuture<Integer> f = new CompletableFuture<>();
f.completeExceptionally(new SpoolerStoreException("Spool full"));
when(mqttClient.publish(any())).thenReturn(f);
when(authorizationHandler.isAuthorized(any(), any(), any())).thenReturn(true);
try (MqttProxyIPCAgent.PublishToIoTCoreOperationHandler publishToIoTCoreOperationHandler = mqttProxyIPCAgent.getPublishToIoTCoreOperationHandler(mockContext)) {
assertThrows(ServiceError.class, () -> {
publishToIoTCoreOperationHandler.handleRequest(publishToIoTCoreRequest);
});
}
}
Aggregations