PropertyDefinitionsManager { public Map<String, PropertyDefinition> getDefinitions() { return definitions; } PropertyDefinitionsManager(); Map<String, PropertyDefinition> getDefinitions(); static final String DEFINITIONS_RESOURCE_NAME_SYS_PROPERTY; static final String DEFAULT_DEFINITIONS_RESOURCE_NAME; }
@Test public void defaultDefinitionsAreLoadedOK() { Map<String, PropertyDefinition> map = new PropertyDefinitionsManager().getDefinitions(); assertThat(map.get("string.key"), is(aDefinition("string.key", PropertyType.STRING))); assertThat(map.get("float.key"), is(aDefinition("float.key", PropertyType.FLOAT))); assertThat(map.get("integer.key"), is(aDefinition("integer.key", PropertyType.INTEGER))); assertThat(map.get("boolean.key"), is(aDefinition("boolean.key", PropertyType.BOOLEAN))); assertThat(map.get("uri.key"), is(aDefinition("uri.key", PropertyType.URL))); }
@Test public void enumDefinitionIsLoadedOK() { Map<String, PropertyDefinition> map = new PropertyDefinitionsManager().getDefinitions(); assertEquals(Regions.class, map.get("enum.key").getEnumClass()); assertEquals(PropertyType.ENUM, map.get("enum.key").getType()); }
@Test public void customLocatedDefinitionsAreLoadedOK() { System.setProperty(PropertyDefinitionsManager.DEFINITIONS_RESOURCE_NAME_SYS_PROPERTY, "custom-definitions-ok.properties"); Map<String, PropertyDefinition> map = new PropertyDefinitionsManager().getDefinitions(); assertThat(map.get("string.key2"), is(aDefinition("string.key2", PropertyType.STRING))); }
@Test(expected=ConfigException.class) public void errorneousPropertyType() { System.setProperty(PropertyDefinitionsManager.DEFINITIONS_RESOURCE_NAME_SYS_PROPERTY, "custom-definitions-error.properties"); new PropertyDefinitionsManager().getDefinitions(); }
@Test(expected=ConfigException.class) public void nonExistentDefinitionsFile() { System.setProperty(PropertyDefinitionsManager.DEFINITIONS_RESOURCE_NAME_SYS_PROPERTY, "custom-definitions-unexistent.properties"); new PropertyDefinitionsManager().getDefinitions(); }