diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/AbstractDefaultValueConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/AbstractDefaultValueConfig.java new file mode 100644 index 0000000..39c47a4 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/AbstractDefaultValueConfig.java @@ -0,0 +1,61 @@ +/* + * 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.defaultvalue; + + +public abstract class AbstractDefaultValueConfig { + + private String stringDefaultWithoutKey = "Valor inicializado e sem chave em arquivo de propriedade"; + + private String stringDefaultWithKey = "Valor inicializado e com chave em arquivo de propriedade"; + + public String getStringDefaultWithoutKey() { + return stringDefaultWithoutKey; + } + + public String getStringDefaultWithKey() { + return stringDefaultWithKey; + } + + public void setStringDefaultWithoutKey(String stringDefaultWithoutKey) { + this.stringDefaultWithoutKey = stringDefaultWithoutKey; + } + + public void setStringDefaultWithKey(String stringDefaultWithKey) { + this.stringDefaultWithKey = stringDefaultWithKey; + } +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/ConfigurationDefaultValueTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/ConfigurationDefaultValueTest.java new file mode 100644 index 0000000..9047a6d --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/ConfigurationDefaultValueTest.java @@ -0,0 +1,100 @@ +/* + * 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.defaultvalue; + +import static junit.framework.Assert.assertEquals; + +import java.io.File; + +import javax.inject.Inject; + +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; + +@RunWith(Arquillian.class) +public class ConfigurationDefaultValueTest extends AbstractConfigurationTest { + + @Inject + private FilledDefaultValueConfig filledFieldConfig; + + @Inject + private EmptyDefaultValueConfig emptyFieldsConfig; + + @Inject + private PropertyWithInexistenceFileConfig noFileConfig; + + @Deployment + public static JavaArchive createDeployment() { + JavaArchive deployment = createConfigurationDeployment(); + + deployment.addPackages(true, ConfigurationDefaultValueTest.class.getPackage()); + deployment.addAsResource( + new FileAsset(new File("src/test/resources/configuration/field/basic/demoiselle.properties")), + "demoiselle.properties").addAsResource( + new FileAsset(new File("src/test/resources/configuration/field/basic/demoiselle.xml")), + "demoiselle.xml"); + + return deployment; + } + + @Test + public void loadDefaultValueWithoutKey(){ + String expected = "Valor inicializado e sem chave em arquivo de propriedade"; + + assertEquals(expected, filledFieldConfig.getStringDefaultWithoutKey()); + assertEquals(expected, emptyFieldsConfig.getStringDefaultWithoutKey()); + assertEquals(expected, noFileConfig.getStringDefaultWithoutKey()); + } + + //@Test(expected = ConfigurationException.class) + /*TODO: Lançar exceção quando uma chave adicionada em arquivo de configuração não + * tiver valor associado*/ + public void loadDefaultValueWithKey(){ + String expectedFilled = "Valor inicializado do arquivo de propriedade"; + String expectedNoFile = "Valor inicializado e com chave em arquivo de propriedade"; + + assertEquals(expectedFilled, filledFieldConfig.getStringDefaultWithKey()); + assertEquals(expectedNoFile, noFileConfig.getStringDefaultWithKey()); + emptyFieldsConfig.getStringDefaultWithKey(); + } +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/EmptyDefaultValueConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/EmptyDefaultValueConfig.java new file mode 100644 index 0000000..22ec8aa --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/EmptyDefaultValueConfig.java @@ -0,0 +1,44 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.configuration.defaultvalue; + +import static br.gov.frameworkdemoiselle.configuration.ConfigType.XML; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(resource = "demoiselle", type = XML) +public class EmptyDefaultValueConfig extends AbstractDefaultValueConfig{ +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/FilledDefaultValueConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/FilledDefaultValueConfig.java new file mode 100644 index 0000000..86be9c4 --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/FilledDefaultValueConfig.java @@ -0,0 +1,44 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.configuration.defaultvalue; + +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(resource = "demoiselle", type = PROPERTIES) +public class FilledDefaultValueConfig extends AbstractDefaultValueConfig{ +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/PropertyWithInexistenceFileConfig.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/PropertyWithInexistenceFileConfig.java new file mode 100644 index 0000000..0e3fe2c --- /dev/null +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/defaultvalue/PropertyWithInexistenceFileConfig.java @@ -0,0 +1,43 @@ +/* + * 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.defaultvalue; + +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(resource = "nofile") +public class PropertyWithInexistenceFileConfig extends AbstractDefaultValueConfig{ +} -- libgit2 0.21.2