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");
}
});
}
}
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());
}
}
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();
}
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());
}
}
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());
}
}
Aggregations