VariableResolver { public <T> T resolve(String variableName, Class<T> clazz) { if (!resolver.containsProperty(variableName)) { throw new UnknownVariableException(variableName); } return resolver.getProperty(variableName, clazz); } VariableResolver(PropertySource appVariables, PropertySource envTypeVariables, PropertySource envVariables, AlienContextVariables alienContextVariables);  VariableResolver(Properties appVariables, Properties envTypeVariables, Properties envVariables, AlienContextVariables alienContextVariables); T resolve(String variableName, Class<T> clazz); String resolve(String variableName);  }
@Test public void resolve_app_var_int() throws Exception { assertThat(resolver.resolve("int_variable", Integer.class)).isEqualTo(1); }
@Test public void resolve_app_var_float() throws Exception { assertThat(resolver.resolve("float_variable", Float.class)).isEqualTo(3.14f); }
@Test public void resolve_app_var_string() throws Exception { assertThat(resolver.resolve("string_variable")).isEqualTo("text"); }
@Test @SuppressWarnings("unchecked") public void resolve_app_var_complex() throws Exception { Map<String, Object> complex = resolver.resolve("complex_variable", Map.class); assertThat(complex.get("complex")).isEqualTo(ImmutableMap.builder().put("subfield", "subValue").build()); }
@Test @SuppressWarnings("unchecked") public void resolve_app_var_complex_with_var_in_leaf() throws Exception { Map<String, Object> complex = resolver.resolve("complex_with_var_in_leaf", Map.class); assertThat(complex.get("complex")).isEqualTo(ImmutableMap.builder().put("subfield", "text").build()); }
@Test @SuppressWarnings("unchecked") public void resolve_complex_with_list_var_in_body() throws Exception { Object complex = resolver.resolve("complex_with_list_var_in_body", Object.class); assertThat(complex).isInstanceOf(Map.class); assertThat(((Map) complex).get("string_list")).isEqualTo(Arrays.asList("item 1", "item 2", "item 3")); assertThat(((Map) complex).get("complex_list")).isEqualTo(Arrays.asList( ImmutableMap.of("item10", "value10", "item11", "value11"), ImmutableMap.of("item20", "value20", "item21", "value21")) ); }
@Test @SuppressWarnings("unchecked") public void resolve_app_var_complex_with_var_in_body() throws Exception { Map<String, Object> complex = (Map<String, Object>) resolver.resolve("complex_with_var_in_body", Object.class); assertThat(complex.get("complex_from_var")).isEqualTo(ImmutableMap.of("complex", ImmutableMap.builder().put("subfield", "text").build())); }
@Test public void resolve_concat() throws Exception { String s = resolver.resolve("concat_variable"); assertThat(s).isEqualTo("1 - text"); }
@Test public void resolve_spel() throws Exception { assertThat(resolver.resolve("spel_variable", String.class)).isEqualTo("true"); }
@Test public void resolve_mix_spel_and_variable() throws Exception { assertThat(resolver.resolve("mix_spel_and_variable", String.class)).isEqualTo("1 true"); }
@Test public void resolve_leaf_complex_object() throws Exception { String s = resolver.resolve("complex_variable.complex.subfield"); assertThat(s).isEqualTo("subValue"); }
@Test public void resolve_complex_with_dot_field() throws Exception { Map map = resolver.resolve("complex_with_dot_field.complex.dot.field", Map.class); assertThat(map).isEqualTo(ImmutableMap.builder().put("value", "3.14").build()); }
@Test @SuppressWarnings("unchecked") public void resolve_subfield_complex_object() throws Exception { assertThat(resolver.resolve("complex_variable.complex", Map.class)).isEqualTo(ImmutableMap.builder().put("subfield", "subValue").build()); }
@Test(expected = UnknownVariableException.class) public void throw_exception_if_variable_unknown() throws Exception { String s = resolver.resolve("unknown"); }
@Test public void check_app_variable_can_be_overridden_in_env() throws Exception { assertThat(resolver.resolve("overidden_variable")).isEqualTo("ok"); }
@Test public void check_new_variable_can_be_added_in_env() throws Exception { assertThat(resolver.resolve("env_variable")).isEqualTo("new env var"); }
@Test public void check_variable_from_env_type_can_be_resolved() throws Exception { assertThat(resolver.resolve("env_type_variable")).isEqualTo("new env type var"); }
@Test @SuppressWarnings("unchecked") public void resolve_list_variable() throws Exception { Object listVariable = resolver.resolve("list_variable", Object.class); assertThat(listVariable).isInstanceOf(List.class); assertThat((List<String>) listVariable).containsExactly("item 1", "item 2", "item 3"); }
@Test @SuppressWarnings("unchecked") public void resolve_list_spel_variable() throws Exception { Object listVariable = resolver.resolve("list_spel_variable", Object.class); assertThat(listVariable).isInstanceOf(List.class); assertThat((List<String>) listVariable).containsExactly("item true", "item false", "item 3"); }
@Test @SuppressWarnings("unchecked") public void resolve_complex_with_list() throws Exception { Object complex = resolver.resolve("complex_with_list", Object.class); assertThat(complex).isInstanceOf(Map.class); assertThat(((Map<String, Object>) complex)).containsExactly( entry("subfield1", "text"), entry("subfield2", ImmutableMap.of("sublist", Arrays.asList("item 1", "item 2", "item 3.14")))); }
@Test @SuppressWarnings("unchecked") public void resolve_list_of_complex() throws Exception { Object list = resolver.resolve("list_of_complex", Object.class); assertThat(list).isInstanceOf(Collection.class); assertThat(((Collection<Object>) list)).hasSize(2); assertThat(((Collection<Object>) list)).containsExactly( ImmutableMap.of("item10", "value10", "item11", "value11"), ImmutableMap.of("item20", "value20", "item21", "value21") ); }
@Test public void predefined_var_cannot_be_redefined() throws Exception { assertThat(resolver.resolve("a4c.application.name")).isEqualTo("originalAppName"); }