use of software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_resume_component_request_WHEN_component_name_input_not_present_THEN_return_invalid_error.
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_resume_component_request_WHEN_component_name_input_not_present_THEN_return_invalid_error() throws ServiceException, AuthorizationException {
ResumeComponentRequest request = new ResumeComponentRequest();
assertThrows(InvalidArgumentsError.class, () -> lifecycleIPCEventStreamAgent.getResumeComponentHandler(mockContext).handleRequest(request));
verify(authorizationHandler, never()).isAuthorized(any(), any());
verify(kernel, never()).locate(TEST_TARGET_COMPONENT);
verify(targetComponent, never()).isPaused();
verify(targetComponent, never()).resume();
}
use of software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_resume_component_request_WHEN_component_not_paused_THEN_return_invalid_error.
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_resume_component_request_WHEN_component_not_paused_THEN_return_invalid_error() throws ServiceException, AuthorizationException {
when(kernel.locate(TEST_TARGET_COMPONENT)).thenReturn(targetComponent);
when(targetComponent.isPaused()).thenReturn(false);
when(authorizationHandler.isAuthorized(any(), any())).thenReturn(true);
ResumeComponentRequest request = new ResumeComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
assertThrows(InvalidArgumentsError.class, () -> lifecycleIPCEventStreamAgent.getResumeComponentHandler(mockContext).handleRequest(request));
ArgumentCaptor<Permission> permissionArg = ArgumentCaptor.forClass(Permission.class);
verify(authorizationHandler).isAuthorized(eq(LIFECYCLE_SERVICE_NAME), permissionArg.capture());
Permission permission = permissionArg.getValue();
assertThat(permission.getOperation(), is(GreengrassCoreIPCService.RESUME_COMPONENT));
assertThat(permission.getPrincipal(), is(TEST_SERVICE));
assertThat(permission.getResource(), is(TEST_TARGET_COMPONENT));
verify(kernel).locate(TEST_TARGET_COMPONENT);
verify(targetComponent).isPaused();
verify(targetComponent, never()).resume();
}
use of software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_resume_component_request_WHEN_not_on_linux_THEN_throws_unsupported_operation_exception.
@Test
@DisabledOnOs(OS.LINUX)
void GIVEN_resume_component_request_WHEN_not_on_linux_THEN_throws_unsupported_operation_exception() {
ResumeComponentRequest request = new ResumeComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
ServiceError exception = assertThrows(ServiceError.class, () -> lifecycleIPCEventStreamAgent.getResumeComponentHandler(mockContext).handleRequest(request));
assertThat(exception.getMessage(), containsString("Pause/resume component not supported on this platform"));
}
use of software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_resume_component_request_WHEN_failure_THEN_return_service_error.
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_resume_component_request_WHEN_failure_THEN_return_service_error() throws AuthorizationException, ServiceException {
when(kernel.locate(TEST_TARGET_COMPONENT)).thenReturn(targetComponent);
when(targetComponent.isPaused()).thenReturn(true);
doThrow(new ServiceException("Failed to resume")).when(targetComponent).resume();
when(authorizationHandler.isAuthorized(any(), any())).thenReturn(true);
ResumeComponentRequest request = new ResumeComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
assertThrows(ServiceError.class, () -> lifecycleIPCEventStreamAgent.getResumeComponentHandler(mockContext).handleRequest(request));
ArgumentCaptor<Permission> permissionArg = ArgumentCaptor.forClass(Permission.class);
verify(authorizationHandler).isAuthorized(eq(LIFECYCLE_SERVICE_NAME), permissionArg.capture());
Permission permission = permissionArg.getValue();
assertThat(permission.getOperation(), is(GreengrassCoreIPCService.RESUME_COMPONENT));
assertThat(permission.getPrincipal(), is(TEST_SERVICE));
assertThat(permission.getResource(), is(TEST_TARGET_COMPONENT));
verify(kernel).locate(TEST_TARGET_COMPONENT);
verify(targetComponent).isPaused();
verify(targetComponent).resume();
}
use of software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_resume_component_request_WHEN_component_not_external_THEN_return_invalid_error.
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_resume_component_request_WHEN_component_not_external_THEN_return_invalid_error() throws ServiceException, AuthorizationException {
GreengrassService mockInternalComponent = mock(GreengrassService.class);
when(kernel.locate(TEST_TARGET_COMPONENT)).thenReturn(mockInternalComponent);
when(authorizationHandler.isAuthorized(any(), any())).thenReturn(true);
ResumeComponentRequest request = new ResumeComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
assertThrows(InvalidArgumentsError.class, () -> lifecycleIPCEventStreamAgent.getResumeComponentHandler(mockContext).handleRequest(request));
ArgumentCaptor<Permission> permissionArg = ArgumentCaptor.forClass(Permission.class);
verify(authorizationHandler).isAuthorized(eq(LIFECYCLE_SERVICE_NAME), permissionArg.capture());
Permission permission = permissionArg.getValue();
assertThat(permission.getOperation(), is(GreengrassCoreIPCService.RESUME_COMPONENT));
assertThat(permission.getPrincipal(), is(TEST_SERVICE));
assertThat(permission.getResource(), is(TEST_TARGET_COMPONENT));
verify(kernel).locate(TEST_TARGET_COMPONENT);
verify(targetComponent, never()).isPaused();
verify(targetComponent, never()).resume();
}
Aggregations