CompiledResourceCreatorConfiguration { public Collection<VirtualTerraformResource> apply(TerraformResource resource) { Object values; try { values = valuesPath.read(resource.getValues()); } catch (PathNotFoundException e) { return Collections.emptyList(); } if (values instanceof List) { return createResource(resource, (List<?>)values); } List<Object> valueList = new ArrayList<>(); valueList.add(values); return createResource(resource, valueList); } CompiledResourceCreatorConfiguration(ResourceCreatorConfiguration resourceCreatorConfiguration); boolean matches(TerraformResource resource); Collection<VirtualTerraformResource> apply(TerraformResource resource);  }
@Test void applyShouldReturnOneResourceIfValueSelectorMatchesOneElmentThatContainsThePropertySelectedByTheNameSelector() { ResourceCreatorConfiguration configuration = createSelectorTestConfiguration("$.name", "$.tmp"); CompiledResourceCreatorConfiguration compiledResourceCreatorConfiguration = new CompiledResourceCreatorConfiguration(configuration); TerraformResource terraformResource = mockSelectorTestResource("{ \"foo\": \"bar\", \"tmp\": { \"a\": 1, \"b\": 2, \"name\": \"i am a name\" } }"); Collection<VirtualTerraformResource> results = compiledResourceCreatorConfiguration.apply(terraformResource); assertThat(results).hasSize(1); Optional<VirtualTerraformResource> resourceOptional = results.stream().findFirst(); assertThat(resourceOptional).isPresent(); VirtualTerraformResource resource = resourceOptional.get(); assertThat(resource.getOriginalResource()).isSameAs(terraformResource); assertThat(resource.getName()).isEqualTo("i am a name"); Map<String, Object> values = resource.getValues(); assertThat(values.get("a")).isEqualTo(1d); assertThat(values.get("b")).isEqualTo(2d); assertThat(values.get("name")).isEqualTo(resource.getName()); }
@Test void applyShouldReturnNoResourceIfValueSelectorMatchesAnElementButThePropertySelectedByTheNameSlectorIsMissing() { ResourceCreatorConfiguration configuration = createSelectorTestConfiguration("$.missingName", "$.tmp"); CompiledResourceCreatorConfiguration compiledResourceCreatorConfiguration = new CompiledResourceCreatorConfiguration(configuration); TerraformResource terraformResource = mockSelectorTestResource("{ \"foo\": \"bar\", \"tmp\": { \"a\": 1, \"b\": 2, \"name\": \"i am a name\" } }"); Collection<VirtualTerraformResource> results = compiledResourceCreatorConfiguration.apply(terraformResource); assertThat(results).isEmpty(); }