Skip to content

Commit

Permalink
test: include test for component calling CLI IPC API (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDombo authored Jun 2, 2022
1 parent ec56ea1 commit 57d53cd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<dependency>
<groupId>com.aws.greengrass</groupId>
<artifactId>nucleus</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.6.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
16 changes: 15 additions & 1 deletion server/src/test/java/com/aws/greengrass/cli/IPCCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient;
import software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClientV2;
import software.amazon.awssdk.aws.greengrass.model.ComponentDetails;
import software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest;
import software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse;
Expand Down Expand Up @@ -161,6 +162,13 @@ void GIVEN_component_running_WHEN_get_component_request_made_THEN_service_detail

assertNotNull(componentDetails);
assertEquals("1.0.0", componentDetails.getVersion());

try(EventStreamRPCConnection connection = IPCTestUtils.getEventStreamRpcConnection(kernel,
"ServiceName")) {
GreengrassCoreIPCClientV2 client =
GreengrassCoreIPCClientV2.builder().withClient(new GreengrassCoreIPCClient(connection)).build();
assertEquals(componentDetails, client.getComponentDetails(request).getComponentDetails());
}
}

@Test
Expand Down Expand Up @@ -198,11 +206,17 @@ void GIVEN_kernel_running_WHEN_list_component_request_made_THEN_components_detai
clientConnection.listComponents(request, Optional.empty()).getResponse()
.get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
List<String> components =
listComponentsResponse.getComponents().stream().map(cd -> cd.getComponentName()).collect(Collectors.toList());
listComponentsResponse.getComponents().stream().map(ComponentDetails::getComponentName).collect(Collectors.toList());
assertTrue(components.contains("mqtt"));
assertTrue(components.contains(TEST_SERVICE_NAME));
assertFalse(components.contains("main"));

try(EventStreamRPCConnection connection = IPCTestUtils.getEventStreamRpcConnection(kernel,
"ServiceName")) {
GreengrassCoreIPCClientV2 client =
GreengrassCoreIPCClientV2.builder().withClient(new GreengrassCoreIPCClient(connection)).build();
assertEquals(components, client.listComponents(request).getComponents().stream().map(ComponentDetails::getComponentName).collect(Collectors.toList()));
}
}

@Test
Expand Down
10 changes: 10 additions & 0 deletions server/src/test/resources/com/aws/greengrass/cli/ipc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ services:
lifecycle: {}
version: 1.0.0
ServiceName:
configuration:
accessControl:
aws.greengrass.Cli:
testPolicy1:
policyDescription: "Test policy"
operations:
- aws.greengrass#GetComponentDetails
- aws.greengrass#ListComponents
resources:
- '*'
lifecycle:
run:
windows:
Expand Down

0 comments on commit 57d53cd

Please sign in to comment.