Commit d7ed5885ae146d8fd9bcfec665355f778023ae9a
1 parent
0d26fbc0
Exists in
master
Implementação dos testes de carregamento de configuração do tipo Class
Showing
13 changed files
with
362 additions
and
141 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java
| ... | ... | @@ -41,6 +41,8 @@ import static br.gov.frameworkdemoiselle.configuration.ConfigType.SYSTEM; |
| 41 | 41 | |
| 42 | 42 | import java.io.Serializable; |
| 43 | 43 | import java.lang.reflect.Field; |
| 44 | +import java.lang.reflect.ParameterizedType; | |
| 45 | +import java.lang.reflect.Type; | |
| 44 | 46 | import java.util.List; |
| 45 | 47 | |
| 46 | 48 | import javax.validation.constraints.NotNull; |
| ... | ... | @@ -183,6 +185,8 @@ public class ConfigurationLoader implements Serializable { |
| 183 | 185 | |
| 184 | 186 | if (field.getType().isArray()) { |
| 185 | 187 | value = getArrayValue(field, key); |
| 188 | + } else if (field.getType() == Class.class) { | |
| 189 | + value = getClassValue(field, key); | |
| 186 | 190 | } else { |
| 187 | 191 | value = getPrimitiveOrWrappedValue(field, key); |
| 188 | 192 | } |
| ... | ... | @@ -195,6 +199,25 @@ public class ConfigurationLoader implements Serializable { |
| 195 | 199 | Reflections.getFieldValue(field, this.object)); |
| 196 | 200 | } |
| 197 | 201 | |
| 202 | + private Object getClassValue(Field field, String key) { | |
| 203 | + Object value = null; | |
| 204 | + | |
| 205 | + String canonicalName = this.configuration.getString(key.toString()); | |
| 206 | + | |
| 207 | + if (canonicalName != null) { | |
| 208 | + ClassLoader classLoader = Reflections.getClassLoaderForClass(canonicalName); | |
| 209 | + | |
| 210 | + try { | |
| 211 | + value = Class.forName(canonicalName, true, classLoader); | |
| 212 | + } catch (ClassNotFoundException cause) { | |
| 213 | + // TODO Lançar a mensagem correta | |
| 214 | + throw new ConfigurationException(null, cause); | |
| 215 | + } | |
| 216 | + } | |
| 217 | + | |
| 218 | + return value; | |
| 219 | + } | |
| 220 | + | |
| 198 | 221 | @SuppressWarnings("unchecked") |
| 199 | 222 | private Object getPrimitiveOrWrappedValue(Field field, String key) { |
| 200 | 223 | Object value; |
| ... | ... | @@ -235,7 +258,7 @@ public class ConfigurationLoader implements Serializable { |
| 235 | 258 | |
| 236 | 259 | private void validateValue(Field field) { |
| 237 | 260 | if (field.isAnnotationPresent(NotNull.class) && Reflections.getFieldValue(field, this.object) == null) { |
| 238 | - throw new ConfigurationException(""); | |
| 261 | + throw new ConfigurationException("", new NullPointerException()); | |
| 239 | 262 | // TODO: Pegar mensagem do Bundle e verificar como as mensagens de log estão implementadas |
| 240 | 263 | } |
| 241 | 264 | } | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassCastFieldConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,46 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package br.gov.frameworkdemoiselle.configuration.field.clazz; | |
| 38 | + | |
| 39 | +public abstract class AbstractClassCastFieldConfig { | |
| 40 | + | |
| 41 | + private Class<MyClass> forcingClassCastException; | |
| 42 | + | |
| 43 | + public Class<MyClass> getForcingClassCastException() { | |
| 44 | + return forcingClassCastException; | |
| 45 | + } | |
| 46 | +} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassFieldConfig.java
| ... | ... | @@ -1,73 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * Copyright (C) 2010 SERPRO | |
| 4 | - * ---------------------------------------------------------------------------- | |
| 5 | - * This file is part of Demoiselle Framework. | |
| 6 | - * | |
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | - * as published by the Free Software Foundation. | |
| 10 | - * | |
| 11 | - * This program is distributed in the hope that it will be useful, | |
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - * GNU General Public License for more details. | |
| 15 | - * | |
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | - * ---------------------------------------------------------------------------- | |
| 21 | - * Este arquivo é parte do Framework Demoiselle. | |
| 22 | - * | |
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | - * do Software Livre (FSF). | |
| 26 | - * | |
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | - * para maiores detalhes. | |
| 31 | - * | |
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | - */ | |
| 37 | -package br.gov.frameworkdemoiselle.configuration.field.clazz; | |
| 38 | - | |
| 39 | -public abstract class AbstractClassFieldConfig { | |
| 40 | - | |
| 41 | - private Class<MyClass> existentTypedClass; | |
| 42 | - | |
| 43 | - private Class<?> existentUntypedClass; | |
| 44 | - | |
| 45 | - private Class<MyClass> nonExistentTypedClass; | |
| 46 | - | |
| 47 | - private Class<?> nonExistentUntypedClass; | |
| 48 | - | |
| 49 | - private Class<MyClass> forcingClassCastException; | |
| 50 | - | |
| 51 | - public Class<MyClass> getExistentTypedClass() { | |
| 52 | - return existentTypedClass; | |
| 53 | - } | |
| 54 | - | |
| 55 | - public Class<?> getExistentUntypedClass() { | |
| 56 | - return existentUntypedClass; | |
| 57 | - } | |
| 58 | - | |
| 59 | - public Class<MyClass> getNonExistentTypedClass() { | |
| 60 | - return nonExistentTypedClass; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public Class<?> getNonExistentUntypedClass() { | |
| 64 | - return nonExistentUntypedClass; | |
| 65 | - } | |
| 66 | - | |
| 67 | - public Class<MyClass> getForcingClassCastException() { | |
| 68 | - return forcingClassCastException; | |
| 69 | - } | |
| 70 | - | |
| 71 | - public static class MyClass { | |
| 72 | - } | |
| 73 | -} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,52 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package br.gov.frameworkdemoiselle.configuration.field.clazz; | |
| 38 | + | |
| 39 | +public abstract class AbstractClassNotFoundFieldConfig { | |
| 40 | + | |
| 41 | + private Class<MyClass> nonExistentTypedClass; | |
| 42 | + | |
| 43 | + private Class<?> nonExistentUntypedClass; | |
| 44 | + | |
| 45 | + public Class<MyClass> getNonExistentTypedClass() { | |
| 46 | + return nonExistentTypedClass; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public Class<?> getNonExistentUntypedClass() { | |
| 50 | + return nonExistentUntypedClass; | |
| 51 | + } | |
| 52 | +} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractExistentClassFieldConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,52 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package br.gov.frameworkdemoiselle.configuration.field.clazz; | |
| 38 | + | |
| 39 | +public abstract class AbstractExistentClassFieldConfig { | |
| 40 | + | |
| 41 | + private Class<MyClass> existentTypedClass; | |
| 42 | + | |
| 43 | + private Class<?> existentUntypedClass; | |
| 44 | + | |
| 45 | + public Class<MyClass> getExistentTypedClass() { | |
| 46 | + return existentTypedClass; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public Class<?> getExistentUntypedClass() { | |
| 50 | + return existentUntypedClass; | |
| 51 | + } | |
| 52 | +} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java
| ... | ... | @@ -37,13 +37,12 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.configuration.field.clazz; |
| 38 | 38 | |
| 39 | 39 | import static junit.framework.Assert.assertEquals; |
| 40 | +import static junit.framework.Assert.fail; | |
| 40 | 41 | |
| 41 | 42 | import java.io.File; |
| 42 | 43 | |
| 43 | 44 | import javax.inject.Inject; |
| 44 | 45 | |
| 45 | -import junit.framework.Assert; | |
| 46 | - | |
| 47 | 46 | import org.jboss.arquillian.container.test.api.Deployment; |
| 48 | 47 | import org.jboss.arquillian.junit.Arquillian; |
| 49 | 48 | import org.jboss.shrinkwrap.api.asset.FileAsset; |
| ... | ... | @@ -53,13 +52,18 @@ import org.junit.runner.RunWith; |
| 53 | 52 | |
| 54 | 53 | import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; |
| 55 | 54 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; |
| 56 | -import br.gov.frameworkdemoiselle.configuration.field.clazz.AbstractClassFieldConfig.MyClass; | |
| 57 | 55 | |
| 58 | 56 | @RunWith(Arquillian.class) |
| 59 | 57 | public class ConfigurationClassFieldTest extends AbstractConfigurationTest { |
| 60 | 58 | |
| 61 | 59 | @Inject |
| 62 | - private PropertiesClassFieldConfig propertiesConfig; | |
| 60 | + private PropertiesExistentClassFieldConfig propertiesExistentConfig; | |
| 61 | + | |
| 62 | + @Inject | |
| 63 | + private PropertiesClassNotFoundFieldConfig propertiesNotFoundConfig; | |
| 64 | + | |
| 65 | + @Inject | |
| 66 | + private PropertiesClassCastFieldConfig propertiesCastConfig; | |
| 63 | 67 | |
| 64 | 68 | @Deployment |
| 65 | 69 | public static JavaArchive createDeployment() { |
| ... | ... | @@ -79,40 +83,41 @@ public class ConfigurationClassFieldTest extends AbstractConfigurationTest { |
| 79 | 83 | public void loadExistentTypedClass() { |
| 80 | 84 | Class<MyClass> expected = MyClass.class; |
| 81 | 85 | |
| 82 | - assertEquals(expected, propertiesConfig.getExistentTypedClass()); | |
| 86 | + assertEquals(expected, propertiesExistentConfig.getExistentTypedClass()); | |
| 83 | 87 | } |
| 84 | 88 | |
| 85 | 89 | @Test |
| 86 | 90 | public void loadExistentUntypedClass() { |
| 87 | 91 | Class<?> expected = MyClass.class; |
| 88 | 92 | |
| 89 | - assertEquals(expected, propertiesConfig.getExistentUntypedClass()); | |
| 93 | + assertEquals(expected, propertiesExistentConfig.getExistentUntypedClass()); | |
| 90 | 94 | } |
| 91 | 95 | |
| 92 | 96 | @Test |
| 93 | 97 | public void loadNonExistentTypedClass() { |
| 94 | 98 | try { |
| 95 | - propertiesConfig.getNonExistentTypedClass(); | |
| 99 | + propertiesNotFoundConfig.getNonExistentTypedClass(); | |
| 100 | + fail(); | |
| 96 | 101 | } catch (ConfigurationException cause) { |
| 97 | - Assert.assertEquals(ClassNotFoundException.class, cause.getCause()); | |
| 102 | + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); | |
| 98 | 103 | } |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | 106 | @Test |
| 102 | 107 | public void loadNonExistentUntypedClass() { |
| 103 | 108 | try { |
| 104 | - propertiesConfig.getNonExistentUntypedClass(); | |
| 109 | + propertiesNotFoundConfig.getNonExistentUntypedClass(); | |
| 110 | + fail(); | |
| 105 | 111 | } catch (ConfigurationException cause) { |
| 106 | - Assert.assertEquals(ClassNotFoundException.class, cause.getCause()); | |
| 112 | + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); | |
| 107 | 113 | } |
| 108 | 114 | } |
| 109 | 115 | |
| 110 | - @Test | |
| 111 | - public void loadForcingClassCastException() { | |
| 112 | - try { | |
| 113 | - propertiesConfig.getForcingClassCastException(); | |
| 114 | - } catch (ConfigurationException cause) { | |
| 115 | - Assert.assertEquals(ClassCastException.class, cause.getCause()); | |
| 116 | - } | |
| 116 | + @Test(expected = ClassCastException.class) | |
| 117 | + public void loadForcingClassCastException() throws IllegalAccessException, InstantiationException { | |
| 118 | + Class<MyClass> clazz = propertiesCastConfig.getForcingClassCastException(); | |
| 119 | + | |
| 120 | + @SuppressWarnings("unused") | |
| 121 | + MyClass myClass = clazz.newInstance(); | |
| 117 | 122 | } |
| 118 | 123 | } | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/MyClass.java
0 → 100644
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassCastFieldConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package br.gov.frameworkdemoiselle.configuration.field.clazz; | |
| 38 | + | |
| 39 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; | |
| 40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | |
| 41 | + | |
| 42 | +@Configuration(type = PROPERTIES) | |
| 43 | +public class PropertiesClassCastFieldConfig extends AbstractClassCastFieldConfig { | |
| 44 | + | |
| 45 | +} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java
| ... | ... | @@ -1,41 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * Copyright (C) 2010 SERPRO | |
| 4 | - * ---------------------------------------------------------------------------- | |
| 5 | - * This file is part of Demoiselle Framework. | |
| 6 | - * | |
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | - * as published by the Free Software Foundation. | |
| 10 | - * | |
| 11 | - * This program is distributed in the hope that it will be useful, | |
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - * GNU General Public License for more details. | |
| 15 | - * | |
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | - * ---------------------------------------------------------------------------- | |
| 21 | - * Este arquivo é parte do Framework Demoiselle. | |
| 22 | - * | |
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | - * do Software Livre (FSF). | |
| 26 | - * | |
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | - * para maiores detalhes. | |
| 31 | - * | |
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | - */ | |
| 37 | -package br.gov.frameworkdemoiselle.configuration.field.clazz; | |
| 38 | - | |
| 39 | -public class PropertiesClassFieldConfig extends AbstractClassFieldConfig { | |
| 40 | - | |
| 41 | -} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassNotFoundFieldConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package br.gov.frameworkdemoiselle.configuration.field.clazz; | |
| 38 | + | |
| 39 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; | |
| 40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | |
| 41 | + | |
| 42 | +@Configuration(type = PROPERTIES) | |
| 43 | +public class PropertiesClassNotFoundFieldConfig extends AbstractClassNotFoundFieldConfig { | |
| 44 | + | |
| 45 | +} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesExistentClassFieldConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package br.gov.frameworkdemoiselle.configuration.field.clazz; | |
| 38 | + | |
| 39 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; | |
| 40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | |
| 41 | + | |
| 42 | +@Configuration(type = PROPERTIES) | |
| 43 | +public class PropertiesExistentClassFieldConfig extends AbstractExistentClassFieldConfig { | |
| 44 | + | |
| 45 | +} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/notnull/ConfigurationNotNullFieldTest.java
| ... | ... | @@ -37,11 +37,14 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.configuration.field.notnull; |
| 38 | 38 | |
| 39 | 39 | import static junit.framework.Assert.assertEquals; |
| 40 | +import static junit.framework.Assert.fail; | |
| 40 | 41 | |
| 41 | 42 | import java.io.File; |
| 42 | 43 | |
| 43 | 44 | import javax.inject.Inject; |
| 44 | 45 | |
| 46 | +import junit.framework.Assert; | |
| 47 | + | |
| 45 | 48 | import org.jboss.arquillian.container.test.api.Deployment; |
| 46 | 49 | import org.jboss.arquillian.junit.Arquillian; |
| 47 | 50 | import org.jboss.shrinkwrap.api.asset.FileAsset; |
| ... | ... | @@ -94,18 +97,33 @@ public class ConfigurationNotNullFieldTest extends AbstractConfigurationTest { |
| 94 | 97 | assertEquals(expected, filledFieldConfig.getIntegerNotNull()); |
| 95 | 98 | } |
| 96 | 99 | |
| 97 | - @Test(expected = ConfigurationException.class) | |
| 100 | + @Test | |
| 98 | 101 | public void loadFieldNotNullFromEmptyProperty() { |
| 99 | - emptyFieldsConfig.getIntegerNotNull(); | |
| 102 | + try { | |
| 103 | + emptyFieldsConfig.getIntegerNotNull(); | |
| 104 | + fail(); | |
| 105 | + } catch (ConfigurationException cause) { | |
| 106 | + Assert.assertEquals(NullPointerException.class, cause.getCause().getClass()); | |
| 107 | + } | |
| 100 | 108 | } |
| 101 | 109 | |
| 102 | - @Test(expected = ConfigurationException.class) | |
| 110 | + @Test | |
| 103 | 111 | public void loadFieldFromPropertyFileWithoutNotNullField() { |
| 104 | - withoutNotNullField.getIntegerNotNull(); | |
| 112 | + try { | |
| 113 | + withoutNotNullField.getIntegerNotNull(); | |
| 114 | + fail(); | |
| 115 | + } catch (ConfigurationException cause) { | |
| 116 | + Assert.assertEquals(NullPointerException.class, cause.getCause().getClass()); | |
| 117 | + } | |
| 105 | 118 | } |
| 106 | 119 | |
| 107 | - @Test(expected = ConfigurationException.class) | |
| 120 | + @Test | |
| 108 | 121 | public void loadFieldNotNullFromInexistentPropertyFile() { |
| 109 | - noFileConfig.getIntegerNotNull(); | |
| 122 | + try { | |
| 123 | + noFileConfig.getIntegerNotNull(); | |
| 124 | + fail(); | |
| 125 | + } catch (ConfigurationException cause) { | |
| 126 | + Assert.assertEquals(NullPointerException.class, cause.getCause().getClass()); | |
| 127 | + } | |
| 110 | 128 | } |
| 111 | 129 | } | ... | ... |
impl/core/src/test/resources/configuration/field/class/demoiselle.properties
| ... | ... | @@ -33,9 +33,8 @@ |
| 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 | 35 | |
| 36 | -existentTypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.AbstractClassFieldConfig.MyClass | |
| 37 | -existentUntypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.AbstractClassFieldConfig.MyClass | |
| 36 | +existentTypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.MyClass | |
| 37 | +existentUntypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.MyClass | |
| 38 | 38 | nonExistentTypedClass=com.fake.NonExistentClass |
| 39 | 39 | nonExistentUntypedClass=com.fake.NonExistentClass |
| 40 | -forcingTypedClassCastException=java.lang.String | |
| 41 | 40 | forcingClassCastException=java.lang.String | ... | ... |