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