Search in sources :

Example 1 with PauseComponentRequest

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

Example 2 with PauseComponentRequest

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

Example 3 with PauseComponentRequest

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

Example 4 with PauseComponentRequest

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

Example 5 with PauseComponentRequest

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

Aggregations

Test (org.junit.jupiter.api.Test)8 PauseComponentRequest (software.amazon.awssdk.aws.greengrass.model.PauseComponentRequest)8 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)7 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 ResumeComponentRequest (software.amazon.awssdk.aws.greengrass.model.ResumeComponentRequest)1 ServiceError (software.amazon.awssdk.aws.greengrass.model.ServiceError)1