Search in sources :

Example 1 with Context

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

the class DeviceConfigurationTest method GIVEN_no_existing_config_WHEN_init_device_config_THEN_use_default_nucleus_config.

@Test
void GIVEN_no_existing_config_WHEN_init_device_config_THEN_use_default_nucleus_config() throws Exception {
    try (Context context = new Context()) {
        Topics servicesConfig = Topics.of(context, SERVICES_NAMESPACE_TOPIC, null);
        lenient().when(configuration.lookupTopics(SERVICES_NAMESPACE_TOPIC)).thenReturn(servicesConfig);
        deviceConfiguration = new DeviceConfiguration(mockKernel);
        when(mockKernel.findServiceTopic(DEFAULT_NUCLEUS_COMPONENT_NAME)).thenReturn(servicesConfig.findTopics(DEFAULT_NUCLEUS_COMPONENT_NAME));
        // Expect fallback version in the absence of version information from build files
        assertEquals("0.0.0", deviceConfiguration.getNucleusVersion());
    }
}
Also used : Context(com.aws.greengrass.dependency.Context) Topics(com.aws.greengrass.config.Topics) Test(org.junit.jupiter.api.Test)

Example 2 with Context

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

the class DeviceConfigurationTest method GIVEN_existing_config_including_nucleus_version_WHEN_init_device_config_THEN_use_nucleus_version_from_config.

@Test
void GIVEN_existing_config_including_nucleus_version_WHEN_init_device_config_THEN_use_nucleus_version_from_config() throws Exception {
    try (Context context = new Context()) {
        Topics servicesConfig = Topics.of(context, SERVICES_NAMESPACE_TOPIC, null);
        Topics nucleusConfig = servicesConfig.lookupTopics(DEFAULT_NUCLEUS_COMPONENT_NAME);
        Topic componentTypeConfig = nucleusConfig.lookup(SERVICE_TYPE_TOPIC_KEY).withValue(ComponentType.NUCLEUS.name());
        Topic nucleusVersionConfig = nucleusConfig.lookup(VERSION_CONFIG_KEY).withValue("99.99.99");
        lenient().when(configuration.lookupTopics(SERVICES_NAMESPACE_TOPIC)).thenReturn(servicesConfig);
        lenient().when(configuration.lookup(SERVICES_NAMESPACE_TOPIC, DEFAULT_NUCLEUS_COMPONENT_NAME, VERSION_CONFIG_KEY)).thenReturn(nucleusVersionConfig);
        lenient().when(configuration.lookup(SERVICES_NAMESPACE_TOPIC, DEFAULT_NUCLEUS_COMPONENT_NAME, SERVICE_TYPE_TOPIC_KEY)).thenReturn(componentTypeConfig);
        when(mockKernel.findServiceTopic(DEFAULT_NUCLEUS_COMPONENT_NAME)).thenReturn(nucleusConfig);
        deviceConfiguration = new DeviceConfiguration(mockKernel);
        // Confirm version config didn't get overwritten with default
        assertEquals("99.99.99", Coerce.toString(nucleusVersionConfig));
        assertEquals("99.99.99", deviceConfiguration.getNucleusVersion());
    }
}
Also used : Context(com.aws.greengrass.dependency.Context) Topics(com.aws.greengrass.config.Topics) Topic(com.aws.greengrass.config.Topic) Test(org.junit.jupiter.api.Test)

Example 3 with Context

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

the class DeviceConfigurationTest method GIVEN_existing_config_with_no_nucleus_version_WHEN_init_device_config_THEN_use_default_nucleus_version.

@Test
void GIVEN_existing_config_with_no_nucleus_version_WHEN_init_device_config_THEN_use_default_nucleus_version() throws Exception {
    try (Context context = new Context()) {
        Topics servicesConfig = Topics.of(context, SERVICES_NAMESPACE_TOPIC, null);
        Topics nucleusConfig = servicesConfig.lookupTopics(DEFAULT_NUCLEUS_COMPONENT_NAME);
        Topic componentTypeConfig = nucleusConfig.lookup(SERVICE_TYPE_TOPIC_KEY).withValue(ComponentType.NUCLEUS.name());
        lenient().when(configuration.lookupTopics(SERVICES_NAMESPACE_TOPIC)).thenReturn(servicesConfig);
        lenient().when(configuration.lookup(SERVICES_NAMESPACE_TOPIC, DEFAULT_NUCLEUS_COMPONENT_NAME, SERVICE_TYPE_TOPIC_KEY)).thenReturn(componentTypeConfig);
        when(mockKernel.findServiceTopic(DEFAULT_NUCLEUS_COMPONENT_NAME)).thenReturn(nucleusConfig);
        deviceConfiguration = new DeviceConfiguration(mockKernel);
        // Expect fallback version in the absence of version information from build files
        assertEquals("0.0.0", deviceConfiguration.getNucleusVersion());
    }
}
Also used : Context(com.aws.greengrass.dependency.Context) Topics(com.aws.greengrass.config.Topics) Topic(com.aws.greengrass.config.Topic) Test(org.junit.jupiter.api.Test)

Example 4 with Context

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

the class PlatformResolverTest method WHEN_platform_override_THEN_override_should_take_place.

@Test
void WHEN_platform_override_THEN_override_should_take_place() throws Exception {
    String platformOverrideConfig = "---\n" + "architecture: fooArch\n" + "key1: val1\n";
    Map<String, Object> platformOverrideMap = MAPPER.readValue(platformOverrideConfig, Map.class);
    try (Context context = new Context()) {
        Topics platformOverrideTopics = new Topics(context, DeviceConfiguration.PLATFORM_OVERRIDE_TOPIC, null);
        platformOverrideTopics.updateFromMap(platformOverrideMap, new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, 1));
        DeviceConfiguration deviceConfiguration = mock(DeviceConfiguration.class);
        when(deviceConfiguration.getPlatformOverrideTopic()).thenReturn(platformOverrideTopics);
        PlatformResolver platformResolver = new PlatformResolver(deviceConfiguration);
        Map<String, String> currentPlatform = platformResolver.getCurrentPlatform();
        assertThat(currentPlatform.get("key1"), equalTo("val1"));
        assertThat(currentPlatform.get(PlatformResolver.ARCHITECTURE_KEY), equalTo("fooArch"));
        // assert that non-overridden platform attributes exist
        assertThat(currentPlatform.containsKey(PlatformResolver.OS_KEY), equalTo(true));
    }
}
Also used : Context(com.aws.greengrass.dependency.Context) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Test(org.junit.jupiter.api.Test)

Example 5 with Context

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

the class GreengrassServiceTest method beforeEach.

@BeforeEach
void beforeEach() throws IOException, URISyntaxException, ServiceLoadException {
    Path configPath = Paths.get(this.getClass().getResource("services.yaml").toURI());
    context = spy(new Context());
    context.put(Kernel.class, kernel);
    configuration = new Configuration(context);
    configuration.read(configPath);
    Topics root = configuration.getRoot();
    bService = new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "B"));
    cService = new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "C"));
    dService = new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "D"));
    eService = new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "E"));
    when(kernel.locateIgnoreError("B")).thenReturn(bService);
    when(kernel.locateIgnoreError("C")).thenReturn(cService);
    when(kernel.locateIgnoreError("D")).thenReturn(dService);
    lenient().when(kernel.locateIgnoreError("E")).thenReturn(eService);
    aService = spy(new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "A")));
}
Also used : Path(java.nio.file.Path) Context(com.aws.greengrass.dependency.Context) Topics(com.aws.greengrass.config.Topics) Configuration(com.aws.greengrass.config.Configuration) BeforeEach(org.junit.jupiter.api.BeforeEach)

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