use of com.aws.greengrass.util.GreengrassServiceClientFactory in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsFleetStatusServiceTest method setupKernel.
@SuppressWarnings("PMD.CloseResource")
@BeforeEach
void setupKernel(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, TLSAuthException.class);
ignoreExceptionOfType(context, PackageDownloadException.class);
ignoreExceptionUltimateCauseOfType(context, EOFException.class);
ignoreExceptionUltimateCauseOfType(context, ResourceNotFoundException.class);
CountDownLatch fssRunning = new CountDownLatch(1);
CountDownLatch deploymentServiceRunning = new CountDownLatch(1);
CompletableFuture<Void> cf = new CompletableFuture<>();
cf.complete(null);
lenient().when(mockIotJobsClientWrapper.PublishUpdateJobExecution(any(UpdateJobExecutionRequest.class), any(QualityOfService.class))).thenAnswer(invocationOnMock -> {
verify(mockIotJobsClientWrapper, atLeastOnce()).SubscribeToUpdateJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), jobsAcceptedHandlerCaptor.capture());
Consumer<UpdateJobExecutionResponse> jobResponseConsumer = jobsAcceptedHandlerCaptor.getValue();
UpdateJobExecutionResponse mockJobExecutionResponse = mock(UpdateJobExecutionResponse.class);
jobResponseConsumer.accept(mockJobExecutionResponse);
return cf;
});
lenient().when(mqttClient.publish(any())).thenReturn(CompletableFuture.completedFuture(0));
kernel = new Kernel();
NoOpPathOwnershipHandler.register(kernel);
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, IotJobsFleetStatusServiceTest.class.getResource("onlyMain.yaml"));
kernel.getContext().put(MqttClient.class, mqttClient);
kernel.getContext().put(ThingGroupHelper.class, thingGroupHelper);
// Mock out cloud communication
GreengrassServiceClientFactory mgscf = mock(GreengrassServiceClientFactory.class);
GreengrassV2DataClient mcf = mock(GreengrassV2DataClient.class);
lenient().when(mcf.resolveComponentCandidates(any(ResolveComponentCandidatesRequest.class))).thenThrow(ResourceNotFoundException.class);
lenient().when(mgscf.getGreengrassV2DataClient()).thenReturn(mcf);
kernel.getContext().put(GreengrassServiceClientFactory.class, mgscf);
componentNamesToCheck.clear();
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals(FleetStatusService.FLEET_STATUS_SERVICE_TOPICS) && newState.equals(State.RUNNING)) {
fssRunning.countDown();
}
if (service.getName().equals(DeploymentService.DEPLOYMENT_SERVICE_TOPICS) && newState.equals(State.RUNNING)) {
deploymentServiceRunning.countDown();
deploymentService = (DeploymentService) service;
IotJobsHelper iotJobsHelper = deploymentService.getContext().get(IotJobsHelper.class);
iotJobsHelper.setIotJobsClientWrapper(mockIotJobsClientWrapper);
}
componentNamesToCheck.add(service.getName());
});
// set required instances from context
deviceConfiguration = new DeviceConfiguration(kernel, "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com", "xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath", "certFilePath", "caFilePath", "us-east-1", "roleAliasName");
kernel.getContext().put(DeviceConfiguration.class, deviceConfiguration);
// pre-load contents to package store
Path localStoreContentPath = Paths.get(IotJobsFleetStatusServiceTest.class.getResource("local_store_content").toURI());
PreloadComponentStoreHelper.preloadRecipesFromTestResourceDir(localStoreContentPath.resolve("recipes"), kernel.getNucleusPaths().recipePath());
copyFolderRecursively(localStoreContentPath.resolve("artifacts"), kernel.getNucleusPaths().artifactPath(), REPLACE_EXISTING);
kernel.launch();
assertTrue(fssRunning.await(10, TimeUnit.SECONDS));
assertTrue(deploymentServiceRunning.await(10, TimeUnit.SECONDS));
}
Aggregations