From b3aa22eb3c51b659050a8c7a8021977f6b248643 Mon Sep 17 00:00:00 2001 From: Cleverson Sacramento Date: Wed, 3 Apr 2013 07:15:17 -0300 Subject: [PATCH] Implementação dos testes de carregamento do de configurações do Class. --- 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/ConfigurationClassFieldTest.java | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java | 41 +++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/configuration/field/class/demoiselle.properties | 41 +++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/configuration/field/class/demoiselle.xml | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 316 insertions(+), 0 deletions(-) create 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/ConfigurationClassFieldTest.java create mode 100644 impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java create mode 100644 impl/core/src/test/resources/configuration/field/class/demoiselle.properties create mode 100644 impl/core/src/test/resources/configuration/field/class/demoiselle.xml 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 new file mode 100644 index 0000000..e0c3dd7 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/AbstractClassFieldConfig.java @@ -0,0 +1,73 @@ +/* + * 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/ConfigurationClassFieldTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java new file mode 100644 index 0000000..3083388 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/ConfigurationClassFieldTest.java @@ -0,0 +1,118 @@ +/* + * 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 junit.framework.Assert.assertEquals; + +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; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +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; + + @Deployment + public static JavaArchive createDeployment() { + 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").addAsResource( + new FileAsset(new File("src/test/resources/configuration/field/class/demoiselle.xml")), + "demoiselle.xml"); + + return deployment; + } + + @Test + public void loadExistentTypedClass() { + Class expected = MyClass.class; + + assertEquals(expected, propertiesConfig.getExistentTypedClass()); + } + + @Test + public void loadExistentUntypedClass() { + Class expected = MyClass.class; + + assertEquals(expected, propertiesConfig.getExistentUntypedClass()); + } + + @Test + public void loadNonExistentTypedClass() { + try { + propertiesConfig.getNonExistentTypedClass(); + } catch (ConfigurationException cause) { + Assert.assertEquals(ClassNotFoundException.class, cause.getCause()); + } + } + + @Test + public void loadNonExistentUntypedClass() { + try { + propertiesConfig.getNonExistentUntypedClass(); + } catch (ConfigurationException cause) { + Assert.assertEquals(ClassNotFoundException.class, cause.getCause()); + } + } + + @Test + public void loadForcingClassCastException() { + try { + propertiesConfig.getForcingClassCastException(); + } catch (ConfigurationException cause) { + Assert.assertEquals(ClassCastException.class, cause.getCause()); + } + } +} 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 new file mode 100644 index 0000000..7631715 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/clazz/PropertiesClassFieldConfig.java @@ -0,0 +1,41 @@ +/* + * 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/resources/configuration/field/class/demoiselle.properties b/impl/core/src/test/resources/configuration/field/class/demoiselle.properties new file mode 100644 index 0000000..9d8961a --- /dev/null +++ b/impl/core/src/test/resources/configuration/field/class/demoiselle.properties @@ -0,0 +1,41 @@ +# 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. + +existentTypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.AbstractClassFieldConfig.MyClass +existentUntypedClass=br.gov.frameworkdemoiselle.configuration.field.clazz.AbstractClassFieldConfig.MyClass +nonExistentTypedClass=com.fake.NonExistentClass +nonExistentUntypedClass=com.fake.NonExistentClass +forcingTypedClassCastException=java.lang.String +forcingClassCastException=java.lang.String diff --git a/impl/core/src/test/resources/configuration/field/class/demoiselle.xml b/impl/core/src/test/resources/configuration/field/class/demoiselle.xml new file mode 100644 index 0000000..62ee827 --- /dev/null +++ b/impl/core/src/test/resources/configuration/field/class/demoiselle.xml @@ -0,0 +1,43 @@ + + + + 1 + 2 + demoiselle framework + demoiselle,framework + -- libgit2 0.21.2