Commit 5b13ae54e703ead7cbabd40a1eadfbecb6823ae4
1 parent
35c73525
Exists in
master
Implementado o seguinte comportamento: quando não for encontrada uma
classe extratora para um determinado campo, será lançada uma ConfigurationException, com uma mensagem apropriada e ClassNotFoundException como causa. Os testes da classe ConfigurationCUstomFieldTest foram ajustados para esperar esse comportamento
Showing
4 changed files
with
11 additions
and
6 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationLoader.java
| ... | ... | @@ -126,7 +126,8 @@ public class ConfigurationLoader implements Serializable { |
| 126 | 126 | Name annotation = field.getAnnotation(Name.class); |
| 127 | 127 | |
| 128 | 128 | if (annotation != null && Strings.isEmpty(annotation.value())) { |
| 129 | - throw new ConfigurationException(getBundle().getString("configuration-name-attribute-cant-be-empty")); | |
| 129 | + throw new ConfigurationException(getBundle().getString("configuration-name-attribute-cant-be-empty"), | |
| 130 | + new IllegalArgumentException()); | |
| 130 | 131 | } |
| 131 | 132 | } |
| 132 | 133 | |
| ... | ... | @@ -179,7 +180,7 @@ public class ConfigurationLoader implements Serializable { |
| 179 | 180 | |
| 180 | 181 | default: |
| 181 | 182 | throw new ConfigurationException(getBundle().getString("configuration-type-not-implemented-yet", |
| 182 | - type.name())); | |
| 183 | + type.name()), new IllegalArgumentException()); | |
| 183 | 184 | } |
| 184 | 185 | |
| 185 | 186 | config.setDelimiterParsingDisabled(true); |
| ... | ... | @@ -241,13 +242,12 @@ public class ConfigurationLoader implements Serializable { |
| 241 | 242 | } |
| 242 | 243 | } |
| 243 | 244 | |
| 244 | - ConfigurationValueExtractor elected = StrategySelector.getInstance(ConfigurationValueExtractor.class, | |
| 245 | + ConfigurationValueExtractor elected = StrategySelector.selectInstance(ConfigurationValueExtractor.class, | |
| 245 | 246 | candidates); |
| 246 | 247 | |
| 247 | 248 | if (elected == null) { |
| 248 | - // TODO lançar exceção informando que nenhum extrator foi encontrado para o field e ensinar como implementar | |
| 249 | - // um extrator personalizado. | |
| 250 | - throw new ConfigurationException(""); | |
| 249 | + throw new ConfigurationException(getBundle().getString("configuration-extractor-not-found", | |
| 250 | + field.toGenericString(), ConfigurationValueExtractor.class.getName()), new ClassNotFoundException()); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | return elected; | ... | ... |
impl/core/src/main/resources/demoiselle-core-bundle.properties
| ... | ... | @@ -59,6 +59,7 @@ configuration-field-loaded=Configura\u00E7\u00E3o {0} atribu\u00EDda a {1} com o |
| 59 | 59 | configuration-attribute-is-mandatory=A configura\u00E7\u00E3o {0} \u00E9 obrigat\u00F3ria, mas n\u00E3o foi encontrada em {1} |
| 60 | 60 | configuration-name-attribute-cant-be-empty=A nota\u00E7\u00E3o Name n\u00E3o pode estar em branco |
| 61 | 61 | configuration-key-not-found=Chave de configura\u00E7\u00E3o {0} n\u00E3o encontrada |
| 62 | +configuration-extractor-not-found=N\u00E3o foi poss\u00EDvel encontrar a classe extratora para o atributo {0}. Implemente a interface {1} para criar sua classe extratora. | |
| 62 | 63 | |
| 63 | 64 | transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.transaction.class com a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo demoiselle.properties |
| 64 | 65 | executing-all=Executando todos os \: {0} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/custom/ConfigurationCustomFieldTest.java
| ... | ... | @@ -36,6 +36,7 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.configuration.field.custom; |
| 38 | 38 | |
| 39 | +import static junit.framework.Assert.assertEquals; | |
| 39 | 40 | import static junit.framework.Assert.assertNotNull; |
| 40 | 41 | import static junit.framework.Assert.fail; |
| 41 | 42 | |
| ... | ... | @@ -84,6 +85,7 @@ public class ConfigurationCustomFieldTest extends AbstractConfigurationTest { |
| 84 | 85 | unmappedField.getUnmappedClass(); |
| 85 | 86 | fail(); |
| 86 | 87 | } catch (ConfigurationException cause) { |
| 88 | + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); | |
| 87 | 89 | } |
| 88 | 90 | } |
| 89 | 91 | } | ... | ... |
impl/core/src/test/resources/configuration/field/custom/demoiselle.properties
| ... | ... | @@ -32,3 +32,5 @@ |
| 32 | 32 | # "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> |
| 33 | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | +mappedClass=Mapped Class | |
| 36 | +unmappedClass=UnmappedClass | ... | ... |