Search in sources :

Example 1 with ResumeComponentRequest

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();
}
Also used : ResumeComponentRequest(software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test)

Example 2 with ResumeComponentRequest

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();
}
Also used : Permission(com.aws.greengrass.authorization.Permission) ResumeComponentRequest(software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test)

Example 3 with ResumeComponentRequest

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"));
}
Also used : ServiceError(software.amazon.awssdk.aws.greengrass.model.ServiceError) ResumeComponentRequest(software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 4 with ResumeComponentRequest

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();
}
Also used : ServiceException(com.aws.greengrass.lifecyclemanager.exceptions.ServiceException) Permission(com.aws.greengrass.authorization.Permission) ResumeComponentRequest(software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test)

Example 5 with ResumeComponentRequest

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();
}
Also used : GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) Permission(com.aws.greengrass.authorization.Permission) ResumeComponentRequest(software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 ResumeComponentRequest (software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest)9 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)8 Permission (com.aws.greengrass.authorization.Permission)6 AuthorizationException (com.aws.greengrass.authorization.exceptions.AuthorizationException)1 GenericExternalService (com.aws.greengrass.lifecyclemanager.GenericExternalService)1 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)1 ServiceException (com.aws.greengrass.lifecyclemanager.exceptions.ServiceException)1 ServiceLoadException (com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)1 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)1 PauseComponentRequest (software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest)1 ServiceError (software.amazon.awssdk.aws.greengrass.model.ServiceError)1