From e8f5f178dd65b148aa8655ce571d6ddaeafc2c02 Mon Sep 17 00:00:00 2001 From: Dancovich Date: Wed, 9 Oct 2013 11:31:17 -0300 Subject: [PATCH] Refatorado e criado teste para extrator de configuração em ENUM. --- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationEnumValueExtractor.java | 2 +- impl/core/src/test/java/configuration/field/enumeration/AbstractEnumValueConfig.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/configuration/field/enumeration/ConfigurationEnumValueTest.java | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/configuration/field/enumeration/ListOfEnum.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/configuration/field/enumeration/PropertiesEnumConfig.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/configuration/field/enumeration/WrongPropertyEnumConfig.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/configuration/field/enumeration/XmlEnumConfig.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/configuration/field/enumeration/demoiselle.properties | 37 +++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/configuration/field/enumeration/demoiselle.xml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 407 insertions(+), 1 deletion(-) create mode 100644 impl/core/src/test/java/configuration/field/enumeration/AbstractEnumValueConfig.java create mode 100644 impl/core/src/test/java/configuration/field/enumeration/ConfigurationEnumValueTest.java create mode 100644 impl/core/src/test/java/configuration/field/enumeration/ListOfEnum.java create mode 100644 impl/core/src/test/java/configuration/field/enumeration/PropertiesEnumConfig.java create mode 100644 impl/core/src/test/java/configuration/field/enumeration/WrongPropertyEnumConfig.java create mode 100644 impl/core/src/test/java/configuration/field/enumeration/XmlEnumConfig.java create mode 100644 impl/core/src/test/resources/configuration/field/enumeration/demoiselle.properties create mode 100644 impl/core/src/test/resources/configuration/field/enumeration/demoiselle.xml diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationEnumValueExtractor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationEnumValueExtractor.java index 61d6cc3..9e99e64 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationEnumValueExtractor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationEnumValueExtractor.java @@ -62,7 +62,7 @@ public class ConfigurationEnumValueExtractor implements ConfigurationValueExtrac Object enums[] = field.getType().getEnumConstants(); for (int i=0; i)enums[i]).toString().equalsIgnoreCase(value) ){ + if ( ((Enum)enums[i]).name().equals(value) ){ return enums[i]; } } diff --git a/impl/core/src/test/java/configuration/field/enumeration/AbstractEnumValueConfig.java b/impl/core/src/test/java/configuration/field/enumeration/AbstractEnumValueConfig.java new file mode 100644 index 0000000..932b171 --- /dev/null +++ b/impl/core/src/test/java/configuration/field/enumeration/AbstractEnumValueConfig.java @@ -0,0 +1,56 @@ +/* + * 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 configuration.field.enumeration; + +import java.io.Serializable; + +public abstract class AbstractEnumValueConfig implements Serializable { + + private static final long serialVersionUID = 1L; + + private ListOfEnum enumValue; + + private ListOfEnum anotherValue; + + public ListOfEnum getEnumValue() { + return enumValue; + } + + public ListOfEnum getAnotherValue() { + return anotherValue; + } +} diff --git a/impl/core/src/test/java/configuration/field/enumeration/ConfigurationEnumValueTest.java b/impl/core/src/test/java/configuration/field/enumeration/ConfigurationEnumValueTest.java new file mode 100644 index 0000000..2885b11 --- /dev/null +++ b/impl/core/src/test/java/configuration/field/enumeration/ConfigurationEnumValueTest.java @@ -0,0 +1,83 @@ +/* + * 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 configuration.field.enumeration; + +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import test.Tests; +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; + +@RunWith(Arquillian.class) +public class ConfigurationEnumValueTest { + + private static final String PATH = "src/test/resources/configuration/field/enumeration"; + + @Inject + private PropertiesEnumConfig propertiesEnumConfig; + + @Inject + private XmlEnumConfig xmlEnumConfig; + + @Inject + private WrongPropertyEnumConfig wrongPropertyEnumConfig; + + @Deployment + public static JavaArchive createDeployment() { + JavaArchive deployment = Tests.createDeployment(ConfigurationEnumValueTest.class); + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.xml"), "demoiselle.xml"); + return deployment; + } + + @Test + public void loadEnumConfig(){ + Assert.assertEquals(ListOfEnum.VALUE_2, propertiesEnumConfig.getEnumValue()); + Assert.assertEquals(ListOfEnum.VALUE_2, xmlEnumConfig.getEnumValue()); + } + + @Test(expected=ConfigurationException.class) + public void checkConverstionException(){ + wrongPropertyEnumConfig.getAnotherValue(); + } +} diff --git a/impl/core/src/test/java/configuration/field/enumeration/ListOfEnum.java b/impl/core/src/test/java/configuration/field/enumeration/ListOfEnum.java new file mode 100644 index 0000000..d3269bf --- /dev/null +++ b/impl/core/src/test/java/configuration/field/enumeration/ListOfEnum.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 configuration.field.enumeration; + + +public enum ListOfEnum { + + VALUE_1 , VALUE_2 , VALUE_3; + +} diff --git a/impl/core/src/test/java/configuration/field/enumeration/PropertiesEnumConfig.java b/impl/core/src/test/java/configuration/field/enumeration/PropertiesEnumConfig.java new file mode 100644 index 0000000..b0ea23c --- /dev/null +++ b/impl/core/src/test/java/configuration/field/enumeration/PropertiesEnumConfig.java @@ -0,0 +1,47 @@ +/* + * 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 configuration.field.enumeration; + +import br.gov.frameworkdemoiselle.configuration.ConfigType; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(resource="demoiselle" , type=ConfigType.PROPERTIES , prefix="prefix1") +public class PropertiesEnumConfig extends AbstractEnumValueConfig { + + private static final long serialVersionUID = 1L; + +} diff --git a/impl/core/src/test/java/configuration/field/enumeration/WrongPropertyEnumConfig.java b/impl/core/src/test/java/configuration/field/enumeration/WrongPropertyEnumConfig.java new file mode 100644 index 0000000..a73687d --- /dev/null +++ b/impl/core/src/test/java/configuration/field/enumeration/WrongPropertyEnumConfig.java @@ -0,0 +1,47 @@ +/* + * 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 configuration.field.enumeration; + +import br.gov.frameworkdemoiselle.configuration.ConfigType; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(resource="demoiselle" , type=ConfigType.PROPERTIES , prefix="prefix2") +public class WrongPropertyEnumConfig extends AbstractEnumValueConfig { + + private static final long serialVersionUID = 1L; + +} diff --git a/impl/core/src/test/java/configuration/field/enumeration/XmlEnumConfig.java b/impl/core/src/test/java/configuration/field/enumeration/XmlEnumConfig.java new file mode 100644 index 0000000..2e4ecce --- /dev/null +++ b/impl/core/src/test/java/configuration/field/enumeration/XmlEnumConfig.java @@ -0,0 +1,47 @@ +/* + * 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 configuration.field.enumeration; + +import br.gov.frameworkdemoiselle.configuration.ConfigType; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(resource="demoiselle" , type=ConfigType.XML , prefix="prefix1") +public class XmlEnumConfig extends AbstractEnumValueConfig { + + private static final long serialVersionUID = 1L; + +} diff --git a/impl/core/src/test/resources/configuration/field/enumeration/demoiselle.properties b/impl/core/src/test/resources/configuration/field/enumeration/demoiselle.properties new file mode 100644 index 0000000..02d7aed --- /dev/null +++ b/impl/core/src/test/resources/configuration/field/enumeration/demoiselle.properties @@ -0,0 +1,37 @@ +# 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. + +prefix1.enumValue=VALUE_2 +prefix2.anotherValue=value_2 diff --git a/impl/core/src/test/resources/configuration/field/enumeration/demoiselle.xml b/impl/core/src/test/resources/configuration/field/enumeration/demoiselle.xml new file mode 100644 index 0000000..8d653c9 --- /dev/null +++ b/impl/core/src/test/resources/configuration/field/enumeration/demoiselle.xml @@ -0,0 +1,45 @@ + + + + + VALUE_2 + + + value_2 + + -- libgit2 0.21.2