Search in sources :

Example 11 with Context

use of com.aws.greengrass.dependency.Context in project aws-greengrass-cli by aws-greengrass.

the class CLIEventStreamAgentTest method testListLocalDeployment_successful.

@Test
@SuppressWarnings("PMD.CloseResource")
void testListLocalDeployment_successful() throws IOException {
    Topics mockCliConfig = mock(Topics.class);
    try (Context context = new Context()) {
        Topics localDeployments = Topics.of(context, "localDeployments", null);
        String deploymentId1 = UUID.randomUUID().toString();
        localDeployments.lookupTopics(deploymentId1).lookup(DEPLOYMENT_STATUS_KEY_NAME).withValue(DeploymentStatus.IN_PROGRESS.toString());
        String deploymentId2 = UUID.randomUUID().toString();
        localDeployments.lookupTopics(deploymentId2).lookup(DEPLOYMENT_STATUS_KEY_NAME).withValue(DeploymentStatus.SUCCEEDED.toString());
        when(mockCliConfig.findTopics(PERSISTENT_LOCAL_DEPLOYMENTS)).thenReturn(localDeployments);
        ListLocalDeploymentsRequest request = new ListLocalDeploymentsRequest();
        ListLocalDeploymentsResponse response = cliEventStreamAgent.getListLocalDeploymentsHandler(mockContext, mockCliConfig).handleRequest(request);
        assertEquals(2, response.getLocalDeployments().size());
        response.getLocalDeployments().stream().forEach(ld -> {
            if (ld.getDeploymentId().equals(deploymentId1)) {
                assertEquals(DeploymentStatus.IN_PROGRESS, ld.getStatus());
            } else if (ld.getDeploymentId().equals(deploymentId2)) {
                assertEquals(DeploymentStatus.SUCCEEDED, ld.getStatus());
            } else {
                fail("Invalid deploymentId found in list of local deployments");
            }
        });
    }
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Context(com.aws.greengrass.dependency.Context) OperationContinuationHandlerContext(software.amazon.awssdk.eventstreamrpc.OperationContinuationHandlerContext) Topics(com.aws.greengrass.config.Topics) ListLocalDeploymentsRequest(software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsRequest) ListLocalDeploymentsResponse(software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsResponse) Test(org.junit.jupiter.api.Test)

Example 12 with Context

use of com.aws.greengrass.dependency.Context in project aws-greengrass-cli by aws-greengrass.

the class CLIEventStreamAgentTest method testListLocalDeployment_no_local_deployments.

@Test
@SuppressWarnings("PMD.CloseResource")
void testListLocalDeployment_no_local_deployments() throws IOException {
    Topics mockCliConfig = mock(Topics.class);
    try (Context context = new Context()) {
        Topics localDeployments = Topics.of(context, "localDeployments", null);
        when(mockCliConfig.findTopics(PERSISTENT_LOCAL_DEPLOYMENTS)).thenReturn(localDeployments);
        ListLocalDeploymentsRequest request = new ListLocalDeploymentsRequest();
        ListLocalDeploymentsResponse response = cliEventStreamAgent.getListLocalDeploymentsHandler(mockContext, mockCliConfig).handleRequest(request);
        assertEquals(0, response.getLocalDeployments().size());
    }
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Context(com.aws.greengrass.dependency.Context) OperationContinuationHandlerContext(software.amazon.awssdk.eventstreamrpc.OperationContinuationHandlerContext) Topics(com.aws.greengrass.config.Topics) ListLocalDeploymentsRequest(software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsRequest) ListLocalDeploymentsResponse(software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsResponse) Test(org.junit.jupiter.api.Test)

Example 13 with Context

use of com.aws.greengrass.dependency.Context in project aws-greengrass-cli by aws-greengrass.

the class CLIEventStreamAgentTest method test_GetComponentDetails_successful.

@Test
@SuppressWarnings("PMD.CloseResource")
void test_GetComponentDetails_successful() throws ServiceLoadException, IOException {
    GetComponentDetailsRequest request = new GetComponentDetailsRequest();
    request.setComponentName(TEST_SERVICE);
    GreengrassService mockTestService = mock(GreengrassService.class);
    when(mockTestService.getName()).thenReturn(TEST_SERVICE);
    when(mockTestService.getState()).thenReturn(State.RUNNING);
    Context context = new Context();
    Topics mockServiceConfig = Topics.of(context, TEST_SERVICE, null);
    mockServiceConfig.lookup(VERSION_CONFIG_KEY).withValue("1.0.0");
    Map<String, Object> mockParameterConfig = ImmutableMap.of("param1", "value1");
    mockServiceConfig.lookupTopics(CONFIGURATION_CONFIG_KEY).replaceAndWait(mockParameterConfig);
    when(mockTestService.getServiceConfig()).thenReturn(mockServiceConfig);
    when(kernel.locate(TEST_SERVICE)).thenReturn(mockTestService);
    GetComponentDetailsResponse response = cliEventStreamAgent.getGetComponentDetailsHandler(mockContext).handleRequest(request);
    assertEquals(TEST_SERVICE, response.getComponentDetails().getComponentName());
    assertEquals(LifecycleState.RUNNING, response.getComponentDetails().getState());
    assertEquals("1.0.0", response.getComponentDetails().getVersion());
    assertEquals(mockParameterConfig, response.getComponentDetails().getConfiguration());
    context.close();
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Context(com.aws.greengrass.dependency.Context) OperationContinuationHandlerContext(software.amazon.awssdk.eventstreamrpc.OperationContinuationHandlerContext) Topics(com.aws.greengrass.config.Topics) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) GetComponentDetailsResponse(software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsResponse) GetComponentDetailsRequest(software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest) Test(org.junit.jupiter.api.Test)

Example 14 with Context

use of com.aws.greengrass.dependency.Context in project aws-greengrass-cli by aws-greengrass.

the class CLIEventStreamAgentTest method test_GetListComponent_success.

@Test
@SuppressWarnings("PMD.CloseResource")
void test_GetListComponent_success() throws IOException {
    ListComponentsRequest request = new ListComponentsRequest();
    GreengrassService mockTestService = mock(GreengrassService.class);
    GreengrassService mockMainService = mock(GreengrassService.class);
    when(mockTestService.getName()).thenReturn(TEST_SERVICE);
    when(mockTestService.getState()).thenReturn(State.RUNNING);
    try (Context context = new Context()) {
        Topics mockServiceConfig = Topics.of(context, TEST_SERVICE, null);
        mockServiceConfig.lookup(VERSION_CONFIG_KEY).withValue("1.0.0");
        Map<String, Object> mockParameterConfig = ImmutableMap.of("param1", "value1");
        mockServiceConfig.lookupTopics(CONFIGURATION_CONFIG_KEY).replaceAndWait(mockParameterConfig);
        when(mockTestService.getServiceConfig()).thenReturn(mockServiceConfig);
        when(kernel.getMain()).thenReturn(mockMainService);
        when(kernel.orderedDependencies()).thenReturn(Arrays.asList(mockTestService, mockMainService));
        ListComponentsResponse response = cliEventStreamAgent.getListComponentsHandler(mockContext).handleRequest(request);
        assertEquals(1, response.getComponents().size());
        ComponentDetails componentDetails = response.getComponents().get(0);
        assertEquals(TEST_SERVICE, componentDetails.getComponentName());
        assertEquals(mockParameterConfig, componentDetails.getConfiguration());
        assertEquals("1.0.0", componentDetails.getVersion());
    }
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Context(com.aws.greengrass.dependency.Context) OperationContinuationHandlerContext(software.amazon.awssdk.eventstreamrpc.OperationContinuationHandlerContext) Topics(com.aws.greengrass.config.Topics) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) ListComponentsResponse(software.amazon.awssdk.aws.greengrass.model.ListComponentsResponse) ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails) ListComponentsRequest(software.amazon.awssdk.aws.greengrass.model.ListComponentsRequest) Test(org.junit.jupiter.api.Test)

Example 15 with Context

use of com.aws.greengrass.dependency.Context in project aws-greengrass-cli by aws-greengrass.

the class CLIEventStreamAgentTest method testGetLocalDeploymentStatus_successful.

@Test
@SuppressWarnings("PMD.CloseResource")
void testGetLocalDeploymentStatus_successful() throws IOException {
    Topics localDeployments = mock(Topics.class);
    Topics mockCliConfig = mock(Topics.class);
    try (Context context = new Context()) {
        String deploymentId = UUID.randomUUID().toString();
        Topics mockLocalDeployment = Topics.of(context, deploymentId, null);
        mockLocalDeployment.lookup(DEPLOYMENT_STATUS_KEY_NAME).withValue(DeploymentStatus.IN_PROGRESS.toString());
        when(mockCliConfig.findTopics(PERSISTENT_LOCAL_DEPLOYMENTS)).thenReturn(localDeployments);
        when(localDeployments.findTopics(deploymentId)).thenReturn(mockLocalDeployment);
        GetLocalDeploymentStatusRequest request = new GetLocalDeploymentStatusRequest();
        request.setDeploymentId(deploymentId);
        GetLocalDeploymentStatusResponse response = cliEventStreamAgent.getGetLocalDeploymentStatusHandler(mockContext, mockCliConfig).handleRequest(request);
        assertEquals(deploymentId, response.getDeployment().getDeploymentId());
        assertEquals(DeploymentStatus.IN_PROGRESS, response.getDeployment().getStatus());
    }
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Context(com.aws.greengrass.dependency.Context) OperationContinuationHandlerContext(software.amazon.awssdk.eventstreamrpc.OperationContinuationHandlerContext) GetLocalDeploymentStatusRequest(software.amazon.awssdk.aws.greengrass.model.GetLocalDeploymentStatusRequest) GetLocalDeploymentStatusResponse(software.amazon.awssdk.aws.greengrass.model.GetLocalDeploymentStatusResponse) Topics(com.aws.greengrass.config.Topics) Test(org.junit.jupiter.api.Test)

Aggregations

Context (com.aws.greengrass.dependency.Context)36 Topics (com.aws.greengrass.config.Topics)24 Test (org.junit.jupiter.api.Test)21 Configuration (com.aws.greengrass.config.Configuration)19 BeforeEach (org.junit.jupiter.api.BeforeEach)15 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)15 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)14 IOException (java.io.IOException)8 ExecutorService (java.util.concurrent.ExecutorService)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 ChildChanged (com.aws.greengrass.config.ChildChanged)7 WhatHappened (com.aws.greengrass.config.WhatHappened)7 DEVICE_MQTT_NAMESPACE (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_MQTT_NAMESPACE)7 DEVICE_PARAM_AWS_REGION (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_AWS_REGION)7 DEVICE_PARAM_CERTIFICATE_FILE_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_CERTIFICATE_FILE_PATH)7 DEVICE_PARAM_IOT_DATA_ENDPOINT (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_IOT_DATA_ENDPOINT)7 DEVICE_PARAM_PRIVATE_KEY_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH)7 DEVICE_PARAM_ROOT_CA_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_ROOT_CA_PATH)7 DEVICE_PARAM_THING_NAME (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_THING_NAME)7 DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT (com.aws.greengrass.mqttclient.MqttClient.DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT)7