From b2eec6e2c379f6c7aae0dff8f64b5d3ad9721b97 Mon Sep 17 00:00:00 2001 From: Ednara Oliveira Date: Thu, 11 Apr 2013 16:13:08 -0300 Subject: [PATCH] Testes com valor da chave vazio no arquivo de configuração --- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationClassValueExtractor.java | 8 +------- impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayEmptyFieldConfig.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayFieldConfig.java | 6 ++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/ConfigurationArrayFieldTest.java | 34 ++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/PropertiesArrayEmptyFieldConfig.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java | 24 ++++++++++++++++-------- impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperEmptyFieldConfig.java | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/configuration/field/array/demoiselle.properties | 9 +++++++++ impl/core/src/test/resources/configuration/field/array/demoiselle.xml | 4 ++++ 9 files changed, 242 insertions(+), 15 deletions(-) create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayEmptyFieldConfig.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/PropertiesArrayEmptyFieldConfig.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperEmptyFieldConfig.java diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationClassValueExtractor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationClassValueExtractor.java index c209e73..8be2007 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationClassValueExtractor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationClassValueExtractor.java @@ -52,14 +52,8 @@ public class ConfigurationClassValueExtractor implements ConfigurationValueExtra @Override public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { - Object value = null; String canonicalName = configuration.getString(prefix + key); - - if (!Strings.isEmpty(canonicalName)) { - value = Reflections.forName(canonicalName); - } - - return value; + return Reflections.forName(canonicalName); } @Override diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayEmptyFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayEmptyFieldConfig.java new file mode 100644 index 0000000..5ffdde0 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayEmptyFieldConfig.java @@ -0,0 +1,52 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.configuration.field.array; + +public abstract class AbstractArrayEmptyFieldConfig { + + private int[] emptyPrimitiveIntegers; + + private Integer[] emptyWrapperIntegers; + + public Integer[] getEmptyWrapperIntegers() { + return emptyWrapperIntegers; + } + + public int[] getEmptyPrimitiveIntegers() { + return emptyPrimitiveIntegers; + } +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayFieldConfig.java index 08ed1fb..0b9481a 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayFieldConfig.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/AbstractArrayFieldConfig.java @@ -48,6 +48,8 @@ public abstract class AbstractArrayFieldConfig { private Double[] wrappedDoubles; + private String[] emptyStrings; + public int[] getPrimitiveIntegers() { return primitiveIntegers; } @@ -67,4 +69,8 @@ public abstract class AbstractArrayFieldConfig { public Double[] getWrappedDoubles() { return wrappedDoubles; } + + public String[] getEmptyStrings() { + return emptyStrings; + } } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/ConfigurationArrayFieldTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/ConfigurationArrayFieldTest.java index 10eb5b2..0145e4b 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/ConfigurationArrayFieldTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/ConfigurationArrayFieldTest.java @@ -36,12 +36,16 @@ */ package br.gov.frameworkdemoiselle.configuration.field.array; +import static junit.framework.Assert.assertEquals; import static org.junit.Assert.assertArrayEquals; import java.io.File; import javax.inject.Inject; +import junit.framework.Assert; + +import org.apache.commons.configuration.ConversionException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.asset.FileAsset; @@ -50,12 +54,16 @@ import org.junit.Test; import org.junit.runner.RunWith; import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; @RunWith(Arquillian.class) public class ConfigurationArrayFieldTest extends AbstractConfigurationTest { @Inject private PropertiesArrayFieldConfig propertiesConfig; + + @Inject + private PropertiesArrayEmptyFieldConfig propertiesNullConfig; @Inject private XMLArrayFieldConfig xmlConfig; @@ -113,4 +121,30 @@ public class ConfigurationArrayFieldTest extends AbstractConfigurationTest { assertArrayEquals(expected, propertiesConfig.getWrappedDoubles()); assertArrayEquals(expected, xmlConfig.getWrappedDoubles()); } + + @Test + public void loadEmptyString() { + String[] expected = { "demoisele", "" }; + assertArrayEquals(expected, propertiesConfig.getEmptyStrings()); + } + + @Test + public void loadEmptyPrimitive() { + try { + propertiesNullConfig.getEmptyPrimitiveIntegers(); + Assert.fail(); + } catch (ConfigurationException cause) { + assertEquals(ConversionException.class, cause.getCause().getClass()); + } + } + + @Test + public void loadEmptyWrapper() { + try { + propertiesNullConfig.getEmptyWrapperIntegers(); + Assert.fail(); + } catch (ConfigurationException cause) { + assertEquals(ConversionException.class, cause.getCause().getClass()); + } + } } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/PropertiesArrayEmptyFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/PropertiesArrayEmptyFieldConfig.java new file mode 100644 index 0000000..93e81a3 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/array/PropertiesArrayEmptyFieldConfig.java @@ -0,0 +1,44 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.configuration.field.array; + +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(type = PROPERTIES) +public class PropertiesArrayEmptyFieldConfig extends AbstractArrayEmptyFieldConfig { +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java index 22be0ff..3903b98 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java @@ -61,7 +61,7 @@ public class ConfigurationClassFieldTest extends AbstractConfigurationTest { @Inject private PropertiesClassNotFoundFieldConfig propertiesNotFoundConfig; - + @Inject private PropertiesNullClassFieldConfig propertiesNullFieldConfig; @@ -70,9 +70,8 @@ public class ConfigurationClassFieldTest extends AbstractConfigurationTest { JavaArchive deployment = createConfigurationDeployment(); deployment.addPackages(true, ConfigurationClassFieldTest.class.getPackage()); - deployment.addAsResource( - new FileAsset(new File("src/test/resources/configuration/field/class/demoiselle.properties")), - "demoiselle.properties"); + deployment.addAsResource(new FileAsset(new File( + "src/test/resources/configuration/field/class/demoiselle.properties")), "demoiselle.properties"); return deployment; } @@ -106,16 +105,25 @@ public class ConfigurationClassFieldTest extends AbstractConfigurationTest { assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); } } - + @Test public void loadNullTypedClass() { - assertEquals(null, propertiesNullFieldConfig.getNullTypedClass()); + try { + propertiesNullFieldConfig.getNullTypedClass(); + fail(); + } catch (ConfigurationException cause) { + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); + } } @Test public void loadNullUntypedClass() { - assertEquals(null, propertiesNullFieldConfig.getNullUntypedClass()); + try { + propertiesNullFieldConfig.getNullUntypedClass(); + fail(); + } catch (ConfigurationException cause) { + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); + } } - } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperEmptyFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperEmptyFieldConfig.java new file mode 100644 index 0000000..f5d8325 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperEmptyFieldConfig.java @@ -0,0 +1,76 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.configuration.field.primitiveorwrapper; + +public abstract class AbstractPrimitiveOrWrapperEmptyFieldConfig { + + private int primitiveInteger; + + private int nullPrimitiveInteger; + + private int errorPrimitiveInteger; + + private Integer wrappedInteger; + + private Integer nullWrappedInteger; + + private Integer errorWrappedInteger; + + public Integer getWrappedInteger() { + return wrappedInteger; + } + + public int getPrimitiveInteger() { + return primitiveInteger; + } + + public int getNullPrimitiveInteger() { + return nullPrimitiveInteger; + } + + public Integer getNullWrappedInteger() { + return nullWrappedInteger; + } + + public int getErrorPrimitiveInteger() { + return errorPrimitiveInteger; + } + + public Integer getErrorWrappedInteger() { + return errorWrappedInteger; + } +} diff --git a/impl/core/src/test/resources/configuration/field/array/demoiselle.properties b/impl/core/src/test/resources/configuration/field/array/demoiselle.properties index 68775a4..ebd2d27 100644 --- a/impl/core/src/test/resources/configuration/field/array/demoiselle.properties +++ b/impl/core/src/test/resources/configuration/field/array/demoiselle.properties @@ -53,3 +53,12 @@ primitiveDoubles=0 wrappedDoubles=-456.123456789 wrappedDoubles=0.0 wrappedDoubles=52.2 + +emptyPrimitiveIntegers=1 +emptyPrimitiveIntegers= + +emptyWrapperIntegers=1 +emptyWrapperIntegers= + +emptyStrings=demoisele +emptyStrings= diff --git a/impl/core/src/test/resources/configuration/field/array/demoiselle.xml b/impl/core/src/test/resources/configuration/field/array/demoiselle.xml index 37e33c8..be9d1ae 100644 --- a/impl/core/src/test/resources/configuration/field/array/demoiselle.xml +++ b/impl/core/src/test/resources/configuration/field/array/demoiselle.xml @@ -56,4 +56,8 @@ -456.123456789 0.0 52.2 + + + + -- libgit2 0.21.2