Search in sources :

Example 1 with DEVICE_PARAM_PRIVATE_KEY_PATH

use of com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH in project aws-greengrass-nucleus by aws-greengrass.

the class ProvisionFromTestPlugin method GIVEN_nucleus_started_with_testProvisioningPlugin_AND_without_config_params_THEN_device_runs_offline_mode.

@Order(1)
@Test
@SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts")
void GIVEN_nucleus_started_with_testProvisioningPlugin_AND_without_config_params_THEN_device_runs_offline_mode() throws Throwable {
    URL filepath = getClass().getResource("config_without_test_provisioning_plugin.yaml");
    ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, filepath);
    CountDownLatch logLatch = new CountDownLatch(2);
    CountDownLatch reverseLatch = new CountDownLatch(1);
    DeviceConfiguration deviceConfiguration = kernel.getContext().get(DeviceConfiguration.class);
    try (AutoCloseable listener = TestUtils.createCloseableLogListener((message) -> {
        String messageString = message.getMessage();
        if (messageString.contains(IotJobsHelper.DEVICE_OFFLINE_MESSAGE) || messageString.contains(ShadowDeploymentListener.DEVICE_OFFLINE_MESSAGE)) {
            logLatch.countDown();
        } else if (KernelLifecycle.UPDATED_PROVISIONING_MESSAGE.equals(messageString)) {
            deviceConfiguration.onAnyChange((what, node) -> {
                if (node != null && WhatHappened.childChanged.equals(what)) {
                    if (node.childOf(DEVICE_PARAM_THING_NAME) || node.childOf(DEVICE_PARAM_IOT_DATA_ENDPOINT) || node.childOf(DEVICE_PARAM_PRIVATE_KEY_PATH) || node.childOf(DEVICE_PARAM_CERTIFICATE_FILE_PATH) || node.childOf(DEVICE_PARAM_ROOT_CA_PATH) || node.childOf(DEVICE_PARAM_AWS_REGION)) {
                        reverseLatch.countDown();
                    }
                }
            });
            logLatch.countDown();
        }
    })) {
        kernel.launch();
        assertTrue(logLatch.await(2, TimeUnit.SECONDS));
        assertFalse(reverseLatch.await(5, TimeUnit.SECONDS));
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DEVICE_PARAM_ROOT_CA_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_ROOT_CA_PATH) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) Order(org.junit.jupiter.api.Order) IotJobsHelper(com.aws.greengrass.deployment.IotJobsHelper) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BaseITCase(com.aws.greengrass.integrationtests.BaseITCase) Path(java.nio.file.Path) DEVICE_PARAM_PRIVATE_KEY_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) EventuallyLambdaMatcher.eventuallyEval(com.github.grantwest.eventually.EventuallyLambdaMatcher.eventuallyEval) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) CountDownLatch(java.util.concurrent.CountDownLatch) ShadowDeploymentListener(com.aws.greengrass.deployment.ShadowDeploymentListener) DEVICE_PARAM_CERTIFICATE_FILE_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_CERTIFICATE_FILE_PATH) TempDir(org.junit.jupiter.api.io.TempDir) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DEVICE_PARAM_AWS_REGION(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_AWS_REGION) InvalidKeyException(java.security.InvalidKeyException) Matchers.containsString(org.hamcrest.Matchers.containsString) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ConfigPlatformResolver(com.aws.greengrass.integrationtests.util.ConfigPlatformResolver) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Coerce(com.aws.greengrass.util.Coerce) GGExtension(com.aws.greengrass.testcommons.testutilities.GGExtension) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DEVICE_PARAM_IOT_DATA_ENDPOINT(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_IOT_DATA_ENDPOINT) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Files(java.nio.file.Files) DEVICE_PARAM_THING_NAME(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_THING_NAME) ExceptionLogProtector.ignoreExceptionUltimateCauseOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseOfType) IOException(java.io.IOException) MqttException(software.amazon.awssdk.crt.mqtt.MqttException) File(java.io.File) MethodOrderer(org.junit.jupiter.api.MethodOrderer) TimeUnit(java.util.concurrent.TimeUnit) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) AfterEach(org.junit.jupiter.api.AfterEach) Utils(com.aws.greengrass.util.Utils) WhatHappened(com.aws.greengrass.config.WhatHappened) KernelLifecycle(com.aws.greengrass.lifecyclemanager.KernelLifecycle) Paths(java.nio.file.Paths) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) URL(java.net.URL) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Aggregations

WhatHappened (com.aws.greengrass.config.WhatHappened)1 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)1 DEVICE_PARAM_AWS_REGION (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_AWS_REGION)1 DEVICE_PARAM_CERTIFICATE_FILE_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_CERTIFICATE_FILE_PATH)1 DEVICE_PARAM_IOT_DATA_ENDPOINT (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_IOT_DATA_ENDPOINT)1 DEVICE_PARAM_PRIVATE_KEY_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH)1 DEVICE_PARAM_ROOT_CA_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_ROOT_CA_PATH)1 DEVICE_PARAM_THING_NAME (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_THING_NAME)1 IotJobsHelper (com.aws.greengrass.deployment.IotJobsHelper)1 ShadowDeploymentListener (com.aws.greengrass.deployment.ShadowDeploymentListener)1 BaseITCase (com.aws.greengrass.integrationtests.BaseITCase)1 ConfigPlatformResolver (com.aws.greengrass.integrationtests.util.ConfigPlatformResolver)1 Kernel (com.aws.greengrass.lifecyclemanager.Kernel)1 KernelLifecycle (com.aws.greengrass.lifecyclemanager.KernelLifecycle)1 ExceptionLogProtector.ignoreExceptionUltimateCauseOfType (com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseOfType)1 GGExtension (com.aws.greengrass.testcommons.testutilities.GGExtension)1 TestUtils (com.aws.greengrass.testcommons.testutilities.TestUtils)1 Coerce (com.aws.greengrass.util.Coerce)1 Utils (com.aws.greengrass.util.Utils)1 EventuallyLambdaMatcher.eventuallyEval (com.github.grantwest.eventually.EventuallyLambdaMatcher.eventuallyEval)1