From d7ed5885ae146d8fd9bcfec665355f778023ae9a Mon Sep 17 00:00:00 2001 From: Emerson Oliveira Date: Wed, 3 Apr 2013 09:36:25 -0300 Subject: [PATCH] Implementação dos testes de carregamento de configuração do tipo Class --- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java | 25 ++++++++++++++++++++++++- impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassCastFieldConfig.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassFieldConfig.java | 73 ------------------------------------------------------------------------- impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractExistentClassFieldConfig.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java | 39 ++++++++++++++++++++++----------------- impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/MyClass.java | 5 +++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassCastFieldConfig.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java | 41 ----------------------------------------- impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassNotFoundFieldConfig.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesExistentClassFieldConfig.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/notnull/ConfigurationNotNullFieldTest.java | 30 ++++++++++++++++++++++++------ impl/core/src/test/resources/configuration/field/class/demoiselle.properties | 5 ++--- 13 files changed, 362 insertions(+), 141 deletions(-) create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassCastFieldConfig.java delete mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassFieldConfig.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractExistentClassFieldConfig.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/MyClass.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassCastFieldConfig.java delete mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassNotFoundFieldConfig.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesExistentClassFieldConfig.java diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java index 9f11204..c906293 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java @@ -41,6 +41,8 @@ import static br.gov.frameworkdemoiselle.configuration.ConfigType.SYSTEM; import java.io.Serializable; import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.util.List; import javax.validation.constraints.NotNull; @@ -183,6 +185,8 @@ public class ConfigurationLoader implements Serializable { if (field.getType().isArray()) { value = getArrayValue(field, key); + } else if (field.getType() == Class.class) { + value = getClassValue(field, key); } else { value = getPrimitiveOrWrappedValue(field, key); } @@ -195,6 +199,25 @@ public class ConfigurationLoader implements Serializable { Reflections.getFieldValue(field, this.object)); } + private Object getClassValue(Field field, String key) { + Object value = null; + + String canonicalName = this.configuration.getString(key.toString()); + + if (canonicalName != null) { + ClassLoader classLoader = Reflections.getClassLoaderForClass(canonicalName); + + try { + value = Class.forName(canonicalName, true, classLoader); + } catch (ClassNotFoundException cause) { + // TODO Lançar a mensagem correta + throw new ConfigurationException(null, cause); + } + } + + return value; + } + @SuppressWarnings("unchecked") private Object getPrimitiveOrWrappedValue(Field field, String key) { Object value; @@ -235,7 +258,7 @@ public class ConfigurationLoader implements Serializable { private void validateValue(Field field) { if (field.isAnnotationPresent(NotNull.class) && Reflections.getFieldValue(field, this.object) == null) { - throw new ConfigurationException(""); + throw new ConfigurationException("", new NullPointerException()); // TODO: Pegar mensagem do Bundle e verificar como as mensagens de log estão implementadas } } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassCastFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassCastFieldConfig.java new file mode 100644 index 0000000..fed35dd --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassCastFieldConfig.java @@ -0,0 +1,46 @@ +/* + * 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.clazz; + +public abstract class AbstractClassCastFieldConfig { + + private Class forcingClassCastException; + + public Class getForcingClassCastException() { + return forcingClassCastException; + } +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassFieldConfig.java deleted file mode 100644 index e0c3dd7..0000000 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassFieldConfig.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.clazz; - -public abstract class AbstractClassFieldConfig { - - private Class existentTypedClass; - - private Class existentUntypedClass; - - private Class nonExistentTypedClass; - - private Class nonExistentUntypedClass; - - private Class forcingClassCastException; - - public Class getExistentTypedClass() { - return existentTypedClass; - } - - public Class getExistentUntypedClass() { - return existentUntypedClass; - } - - public Class getNonExistentTypedClass() { - return nonExistentTypedClass; - } - - public Class getNonExistentUntypedClass() { - return nonExistentUntypedClass; - } - - public Class getForcingClassCastException() { - return forcingClassCastException; - } - - public static class MyClass { - } -} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassNotFoundFieldConfig.java new file mode 100644 index 0000000..a347923 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassNotFoundFieldConfig.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.clazz; + +public abstract class AbstractClassNotFoundFieldConfig { + + private Class nonExistentTypedClass; + + private Class nonExistentUntypedClass; + + public Class getNonExistentTypedClass() { + return nonExistentTypedClass; + } + + public Class getNonExistentUntypedClass() { + return nonExistentUntypedClass; + } +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractExistentClassFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractExistentClassFieldConfig.java new file mode 100644 index 0000000..631a1e7 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractExistentClassFieldConfig.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.clazz; + +public abstract class AbstractExistentClassFieldConfig { + + private Class existentTypedClass; + + private Class existentUntypedClass; + + public Class getExistentTypedClass() { + return existentTypedClass; + } + + public Class getExistentUntypedClass() { + return existentUntypedClass; + } +} 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 3083388..9cd9f65 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 @@ -37,13 +37,12 @@ package br.gov.frameworkdemoiselle.configuration.field.clazz; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; import java.io.File; import javax.inject.Inject; -import junit.framework.Assert; - import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.asset.FileAsset; @@ -53,13 +52,18 @@ import org.junit.runner.RunWith; import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; import br.gov.frameworkdemoiselle.configuration.ConfigurationException; -import br.gov.frameworkdemoiselle.configuration.field.clazz.AbstractClassFieldConfig.MyClass; @RunWith(Arquillian.class) public class ConfigurationClassFieldTest extends AbstractConfigurationTest { @Inject - private PropertiesClassFieldConfig propertiesConfig; + private PropertiesExistentClassFieldConfig propertiesExistentConfig; + + @Inject + private PropertiesClassNotFoundFieldConfig propertiesNotFoundConfig; + + @Inject + private PropertiesClassCastFieldConfig propertiesCastConfig; @Deployment public static JavaArchive createDeployment() { @@ -79,40 +83,41 @@ public class ConfigurationClassFieldTest extends AbstractConfigurationTest { public void loadExistentTypedClass() { Class expected = MyClass.class; - assertEquals(expected, propertiesConfig.getExistentTypedClass()); + assertEquals(expected, propertiesExistentConfig.getExistentTypedClass()); } @Test public void loadExistentUntypedClass() { Class expected = MyClass.class; - assertEquals(expected, propertiesConfig.getExistentUntypedClass()); + assertEquals(expected, propertiesExistentConfig.getExistentUntypedClass()); } @Test public void loadNonExistentTypedClass() { try { - propertiesConfig.getNonExistentTypedClass(); + propertiesNotFoundConfig.getNonExistentTypedClass(); + fail(); } catch (ConfigurationException cause) { - Assert.assertEquals(ClassNotFoundException.class, cause.getCause()); + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); } } @Test public void loadNonExistentUntypedClass() { try { - propertiesConfig.getNonExistentUntypedClass(); + propertiesNotFoundConfig.getNonExistentUntypedClass(); + fail(); } catch (ConfigurationException cause) { - Assert.assertEquals(ClassNotFoundException.class, cause.getCause()); + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); } } - @Test - public void loadForcingClassCastException() { - try { - propertiesConfig.getForcingClassCastException(); - } catch (ConfigurationException cause) { - Assert.assertEquals(ClassCastException.class, cause.getCause()); - } + @Test(expected = ClassCastException.class) + public void loadForcingClassCastException() throws IllegalAccessException, InstantiationException { + Class clazz = propertiesCastConfig.getForcingClassCastException(); + + @SuppressWarnings("unused") + MyClass myClass = clazz.newInstance(); } } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/MyClass.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/MyClass.java new file mode 100644 index 0000000..4e3c8fd --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/MyClass.java @@ -0,0 +1,5 @@ +package br.gov.frameworkdemoiselle.configuration.field.clazz; + +public class MyClass { + +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassCastFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassCastFieldConfig.java new file mode 100644 index 0000000..9969216 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassCastFieldConfig.java @@ -0,0 +1,45 @@ +/* + * 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.clazz; + +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(type = PROPERTIES) +public class PropertiesClassCastFieldConfig extends AbstractClassCastFieldConfig { + +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java deleted file mode 100644 index 7631715..0000000 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.clazz; - -public class PropertiesClassFieldConfig extends AbstractClassFieldConfig { - -} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassNotFoundFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassNotFoundFieldConfig.java new file mode 100644 index 0000000..a28a929 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassNotFoundFieldConfig.java @@ -0,0 +1,45 @@ +/* + * 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.clazz; + +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(type = PROPERTIES) +public class PropertiesClassNotFoundFieldConfig extends AbstractClassNotFoundFieldConfig { + +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesExistentClassFieldConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesExistentClassFieldConfig.java new file mode 100644 index 0000000..f39fb59 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesExistentClassFieldConfig.java @@ -0,0 +1,45 @@ +/* + * 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.clazz; + +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(type = PROPERTIES) +public class PropertiesExistentClassFieldConfig extends AbstractExistentClassFieldConfig { + +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/notnull/ConfigurationNotNullFieldTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/notnull/ConfigurationNotNullFieldTest.java index 005d3a8..ff37b93 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/notnull/ConfigurationNotNullFieldTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/notnull/ConfigurationNotNullFieldTest.java @@ -37,11 +37,14 @@ package br.gov.frameworkdemoiselle.configuration.field.notnull; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; import java.io.File; import javax.inject.Inject; +import junit.framework.Assert; + import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.asset.FileAsset; @@ -94,18 +97,33 @@ public class ConfigurationNotNullFieldTest extends AbstractConfigurationTest { assertEquals(expected, filledFieldConfig.getIntegerNotNull()); } - @Test(expected = ConfigurationException.class) + @Test public void loadFieldNotNullFromEmptyProperty() { - emptyFieldsConfig.getIntegerNotNull(); + try { + emptyFieldsConfig.getIntegerNotNull(); + fail(); + } catch (ConfigurationException cause) { + Assert.assertEquals(NullPointerException.class, cause.getCause().getClass()); + } } - @Test(expected = ConfigurationException.class) + @Test public void loadFieldFromPropertyFileWithoutNotNullField() { - withoutNotNullField.getIntegerNotNull(); + try { + withoutNotNullField.getIntegerNotNull(); + fail(); + } catch (ConfigurationException cause) { + Assert.assertEquals(NullPointerException.class, cause.getCause().getClass()); + } } - @Test(expected = ConfigurationException.class) + @Test public void loadFieldNotNullFromInexistentPropertyFile() { - noFileConfig.getIntegerNotNull(); + try { + noFileConfig.getIntegerNotNull(); + fail(); + } catch (ConfigurationException cause) { + Assert.assertEquals(NullPointerException.class, cause.getCause().getClass()); + } } } diff --git a/impl/core/src/test/resources/configuration/field/class/demoiselle.properties b/impl/core/src/test/resources/configuration/field/class/demoiselle.properties index 9d8961a..9d8c08e 100644 --- a/impl/core/src/test/resources/configuration/field/class/demoiselle.properties +++ b/impl/core/src/test/resources/configuration/field/class/demoiselle.properties @@ -33,9 +33,8 @@ # ou escreva para a Fundação do Software Livre (FSF) Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. -existentTypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.AbstractClassFieldConfig.MyClass -existentUntypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.AbstractClassFieldConfig.MyClass +existentTypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.MyClass +existentUntypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.MyClass nonExistentTypedClass=com.fake.NonExistentClass nonExistentUntypedClass=com.fake.NonExistentClass -forcingTypedClassCastException=java.lang.String forcingClassCastException=java.lang.String -- libgit2 0.21.2