use of software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_pause_component_request_WHEN_component_not_external_THEN_return_invalid_error.
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_pause_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);
PauseComponentRequest request = new PauseComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
assertThrows(InvalidArgumentsError.class, () -> lifecycleIPCEventStreamAgent.getPauseComponentHandler(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.PAUSE_COMPONENT));
assertThat(permission.getPrincipal(), is(TEST_SERVICE));
assertThat(permission.getResource(), is(TEST_TARGET_COMPONENT));
verify(kernel).locate(TEST_TARGET_COMPONENT);
verify(targetComponent, never()).getState();
verify(targetComponent, never()).pause();
}
use of software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_pause_component_request_WHEN_component_not_present_THEN_return_resource_not_found_error.
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_pause_component_request_WHEN_component_not_present_THEN_return_resource_not_found_error() throws ServiceException, AuthorizationException {
when(kernel.locate(TEST_TARGET_COMPONENT)).thenThrow(new ServiceLoadException("Failed to load"));
when(authorizationHandler.isAuthorized(any(), any())).thenReturn(true);
PauseComponentRequest request = new PauseComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
assertThrows(ResourceNotFoundError.class, () -> lifecycleIPCEventStreamAgent.getPauseComponentHandler(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.PAUSE_COMPONENT));
assertThat(permission.getPrincipal(), is(TEST_SERVICE));
assertThat(permission.getResource(), is(TEST_TARGET_COMPONENT));
verify(kernel).locate(TEST_TARGET_COMPONENT);
verify(targetComponent, never()).getState();
verify(targetComponent, never()).pause();
}
use of software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_pause_component_request_WHEN_successful_THEN_return_response.
// Pause component tests
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_pause_component_request_WHEN_successful_THEN_return_response() throws ServiceException, AuthorizationException {
when(kernel.locate(TEST_TARGET_COMPONENT)).thenReturn(targetComponent);
when(targetComponent.getState()).thenReturn(State.RUNNING);
when(authorizationHandler.isAuthorized(any(), any())).thenReturn(true);
PauseComponentRequest request = new PauseComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
assertNotNull(lifecycleIPCEventStreamAgent.getPauseComponentHandler(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.PAUSE_COMPONENT));
assertThat(permission.getPrincipal(), is(TEST_SERVICE));
assertThat(permission.getResource(), is(TEST_TARGET_COMPONENT));
verify(kernel).locate(TEST_TARGET_COMPONENT);
verify(targetComponent).getState();
verify(targetComponent).pause();
}
use of software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_pause_component_request_WHEN_failure_THEN_return_service_error.
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_pause_component_request_WHEN_failure_THEN_return_service_error() throws AuthorizationException, ServiceException {
when(kernel.locate(TEST_TARGET_COMPONENT)).thenReturn(targetComponent);
when(targetComponent.getState()).thenReturn(State.RUNNING);
doThrow(new ServiceException("Failed to pause")).when(targetComponent).pause();
when(authorizationHandler.isAuthorized(any(), any())).thenReturn(true);
PauseComponentRequest request = new PauseComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
assertThrows(ServiceError.class, () -> lifecycleIPCEventStreamAgent.getPauseComponentHandler(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.PAUSE_COMPONENT));
assertThat(permission.getPrincipal(), is(TEST_SERVICE));
assertThat(permission.getResource(), is(TEST_TARGET_COMPONENT));
verify(kernel).locate(TEST_TARGET_COMPONENT);
verify(targetComponent).getState();
verify(targetComponent).pause();
}
use of software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleIPCEventStreamAgentTest method GIVEN_pause_component_request_WHEN_component_not_running_THEN_return_invalid_error.
@Test
@EnabledOnOs(OS.LINUX)
void GIVEN_pause_component_request_WHEN_component_not_running_THEN_return_invalid_error() throws ServiceException, AuthorizationException {
when(kernel.locate(TEST_TARGET_COMPONENT)).thenReturn(targetComponent);
when(targetComponent.getState()).thenReturn(State.FINISHED);
when(authorizationHandler.isAuthorized(any(), any())).thenReturn(true);
PauseComponentRequest request = new PauseComponentRequest();
request.setComponentName(TEST_TARGET_COMPONENT);
assertThrows(InvalidArgumentsError.class, () -> lifecycleIPCEventStreamAgent.getPauseComponentHandler(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.PAUSE_COMPONENT));
assertThat(permission.getPrincipal(), is(TEST_SERVICE));
assertThat(permission.getResource(), is(TEST_TARGET_COMPONENT));
verify(kernel).locate(TEST_TARGET_COMPONENT);
verify(targetComponent).getState();
verify(targetComponent, never()).pause();
}
Aggregations