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 a2897ec..740f4b8 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 @@ -64,6 +64,7 @@ import br.gov.frameworkdemoiselle.configuration.ConfigurationException; import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; +import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.Reflections; import br.gov.frameworkdemoiselle.util.ResourceBundle; import br.gov.frameworkdemoiselle.util.Strings; @@ -91,8 +92,9 @@ public class ConfigurationLoader implements Serializable { */ public void load(Object object) throws ConfigurationException { Class config = object.getClass(); - - if (!CoreBootstrap.isAnnotatedType(config)) { + CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class); + + if (!bootstrap.isAnnotatedType(config)) { config = config.getSuperclass(); getLogger().debug(getBundle().getString("proxy-detected", config, config.getClass().getSuperclass())); } @@ -209,24 +211,24 @@ public class ConfigurationLoader implements Serializable { * @return a configuration */ private org.apache.commons.configuration.Configuration getConfiguration(String resource, ConfigType type) { - org.apache.commons.configuration.Configuration config = null; + org.apache.commons.configuration.Configuration result = null; try { URL url; switch (type) { case SYSTEM: - config = new SystemConfiguration(); + result = new SystemConfiguration(); break; case PROPERTIES: url = getResourceAsURL(resource + ".properties"); - config = new DataConfiguration(new PropertiesConfiguration(url)); + result = new DataConfiguration(new PropertiesConfiguration(url)); break; case XML: url = getResourceAsURL(resource + ".xml"); - config = new DataConfiguration(new XMLConfiguration(url)); + result = new DataConfiguration(new XMLConfiguration(url)); break; default: @@ -239,7 +241,7 @@ public class ConfigurationLoader implements Serializable { resource), cause); } - return config; + return result; } @SuppressWarnings("unchecked") @@ -250,9 +252,13 @@ public class ConfigurationLoader implements Serializable { if (fieldClass.isArray()) { value = getArray(key, field, config); + } else if (fieldClass.equals(Properties.class)) { value = getProperty(key, config); + } else if (fieldClass.equals(Class.class)) { + value = getClass(key, field, config); + } else { value = getBasic(key, field, config); } @@ -267,7 +273,6 @@ public class ConfigurationLoader implements Serializable { try { Method method; - String methodName = "get"; methodName += Strings.firstToUpper(fieldClass.getSimpleName()); @@ -293,11 +298,9 @@ public class ConfigurationLoader implements Serializable { try { Method method; - String methodName = "get"; methodName += discoveryGenericType(field); - methodName += Strings.firstToUpper(fieldClass.getSimpleName()); if (!fieldClass.isPrimitive()) { @@ -317,6 +320,25 @@ public class ConfigurationLoader implements Serializable { return value; } + private Object getClass(String key, Field field, org.apache.commons.configuration.Configuration config) { + Object value = null; + + try { + String canonicalName = config.getString(key); + + if (canonicalName != null) { + ClassLoader classLoader = getClassLoaderForClass(canonicalName); + value = Class.forName(canonicalName, true, classLoader); + } + + } catch (Exception cause) { + // TODO Lançar a mensagem correta + throw new ConfigurationException(null, cause); + } + + return value; + } + /** * Discovery the Generic's type. for example: the generic's type of List list is an Integer type * diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfig.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfig.java index f0642ec..e87925b 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfig.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfig.java @@ -38,8 +38,11 @@ package br.gov.frameworkdemoiselle.internal.configuration; import java.io.Serializable; -import br.gov.frameworkdemoiselle.annotation.Name; import br.gov.frameworkdemoiselle.configuration.Configuration; +import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthenticator; +import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthorizer; +import br.gov.frameworkdemoiselle.security.Authenticator; +import br.gov.frameworkdemoiselle.security.Authorizer; /** * A SecurityConfig object is responsible for specifying which security configurations should be used for a @@ -52,9 +55,12 @@ public class SecurityConfig implements Serializable { private static final long serialVersionUID = 1L; - @Name("enabled") private boolean enabled = true; + private Class authenticatorClass = DefaultAuthenticator.class; + + private Class authorizerClass = DefaultAuthorizer.class; + /** * Tells whether or not the security is enabled for the current application. This value could be defined in the * demoiselle.properties file, using the key frameworkdemoiselle.security.enabled. @@ -65,4 +71,12 @@ public class SecurityConfig implements Serializable { public boolean isEnabled() { return enabled; } + + public Class getAuthenticatorClass() { + return authenticatorClass; + } + + public Class getAuthorizerClass() { + return authorizerClass; + } } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/TransactionConfig.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/TransactionConfig.java new file mode 100644 index 0000000..0ad964d --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/TransactionConfig.java @@ -0,0 +1,55 @@ +/* + * 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.internal.configuration; + +import java.io.Serializable; + +import br.gov.frameworkdemoiselle.configuration.Configuration; +import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; +import br.gov.frameworkdemoiselle.transaction.Transaction; + +@Configuration(prefix = "frameworkdemoiselle.transaction") +public class TransactionConfig implements Serializable { + + private static final long serialVersionUID = 1L; + + private Class transactionClass = DefaultTransaction.class; + + public Class getTransactionClass() { + return transactionClass; + } +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java index 7883d50..db160c2 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java @@ -67,25 +67,27 @@ public class SecurityContextImpl implements SecurityContext { private Authorizer authorizer; private Authenticator getAuthenticator() { - if (authenticator == null) { + if (this.authenticator == null) { AuthenticatorBootstrap bootstrap = Beans.getReference(AuthenticatorBootstrap.class); + Class clazz = getConfig().getAuthenticatorClass(); + clazz = StrategySelector.getClass(clazz, bootstrap.getCache()); - authenticator = StrategySelector.getReference("frameworkdemoiselle.security.authenticator.class", - Authenticator.class, DefaultAuthenticator.class, bootstrap.getCache()); + this.authenticator = Beans.getReference(clazz); } - return authenticator; + return this.authenticator; } private Authorizer getAuthorizer() { - if (authorizer == null) { + if (this.authorizer == null) { AuthorizerBootstrap bootstrap = Beans.getReference(AuthorizerBootstrap.class); + Class clazz = getConfig().getAuthorizerClass(); + clazz = StrategySelector.getClass(clazz, bootstrap.getCache()); - authorizer = StrategySelector.getReference("frameworkdemoiselle.security.authorizer.class", - Authorizer.class, DefaultAuthorizer.class, bootstrap.getCache()); + this.authorizer = Beans.getReference(clazz); } - return authorizer; + return this.authorizer; } /** diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java index d620198..47d52da 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java @@ -38,22 +38,10 @@ package br.gov.frameworkdemoiselle.internal.implementation; import static br.gov.frameworkdemoiselle.annotation.Priority.MIN_PRIORITY; -import java.io.FileNotFoundException; import java.io.Serializable; -import java.net.URL; import java.util.List; -import java.util.Locale; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.PropertiesConfiguration; import br.gov.frameworkdemoiselle.annotation.Priority; -import br.gov.frameworkdemoiselle.configuration.ConfigurationException; -import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; -import br.gov.frameworkdemoiselle.util.Beans; -import br.gov.frameworkdemoiselle.util.ResourceBundle; -import br.gov.frameworkdemoiselle.util.Strings; public final class StrategySelector implements Serializable { @@ -70,27 +58,48 @@ public final class StrategySelector implements Serializable { private StrategySelector() { } - public static T getReference(String configKey, Class strategyType, Class defaultType, - List> options) { - T result = getExplicitReference(configKey, strategyType, defaultType); + public static Class getClass(Class configClass/* , Class defaultClass */, + List> optionalClasses) { + Class result = configClass; - if (result.getClass() == defaultType) { - result = getPriorityReference(options); + if (configClass == getDefaultClass(optionalClasses)) { + result = getPriorityReference(optionalClasses); } return result; } - public static T getPriorityReference(List> options) { - Class selected = null; + public static Class getDefaultClass(List> optionalClasses) { + Class result = null; + + for (Class optionalClass : optionalClasses) { + Priority priority = optionalClass.getAnnotation(Priority.class); - for (Class option : options) { + if (priority != null && priority.value() == CORE_PRIORITY) { + result = optionalClass; + break; + } + } + + return result; + } + + /* + * public static T getReference(String configKey, Class strategyType, Class defaultType, List> + * options) { T result = getExplicitReference(configKey, strategyType, defaultType); if (result.getClass() == + * defaultType) { result = getPriorityReference(options); } return result; } + */ + + public static Class getPriorityReference(List> options) { + Class selected = null; + + for (Class option : options) { if (selected == null || getPriority(option) < getPriority(selected)) { selected = option; } } - return Beans.getReference(selected); + return selected; } private static int getPriority(Class type) { @@ -104,49 +113,28 @@ public final class StrategySelector implements Serializable { return result; } - public static T getExplicitReference(String configKey, Class strategyType, Class defaultType) { - Class selectedType = loadSelected(configKey, strategyType, defaultType); - return Beans.getReference(selectedType); - } - - @SuppressWarnings("unchecked") - private static Class loadSelected(String configKey, Class strategyType, Class defaultType) { - ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", - Beans.getReference(Locale.class)); - - Class result = null; - String canonicalName = null; - String typeName = strategyType.getSimpleName().toLowerCase(); - String key = null; - - try { - URL url = ConfigurationLoader.getResourceAsURL("demoiselle.properties"); - Configuration config = new PropertiesConfiguration(url); - canonicalName = config.getString(configKey, defaultType.getCanonicalName()); - - ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(canonicalName); - if (classLoader == null) { - classLoader = Thread.currentThread().getContextClassLoader(); - } - - result = (Class) Class.forName(canonicalName, false, classLoader); - result.asSubclass(strategyType); - - } catch (org.apache.commons.configuration.ConfigurationException cause) { - throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); - - } catch (ClassNotFoundException cause) { - key = Strings.getString("{0}-class-not-found", typeName); - throw new ConfigurationException(bundle.getString(key, canonicalName)); - - } catch (FileNotFoundException e) { - throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); - - } catch (ClassCastException cause) { - key = Strings.getString("{0}-class-must-be-of-type", typeName); - throw new ConfigurationException(bundle.getString(key, canonicalName, strategyType)); - } - - return result; - } + /* + * public static T getExplicitReference(String configKey, Class strategyType, Class defaultType) { + * Class selectedType = loadSelected(configKey, strategyType, defaultType); return + * Beans.getReference(selectedType); } + */ + + /* + * @SuppressWarnings("unchecked") private static Class loadSelected(String configKey, Class strategyType, + * Class defaultType) { ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", + * Beans.getReference(Locale.class)); Class result = null; String canonicalName = null; String typeName = + * strategyType.getSimpleName().toLowerCase(); String key = null; try { URL url = + * ConfigurationLoader.getResourceAsURL("demoiselle.properties"); Configuration config = new + * PropertiesConfiguration(url); canonicalName = config.getString(configKey, defaultType.getCanonicalName()); + * ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(canonicalName); if (classLoader == null) { + * classLoader = Thread.currentThread().getContextClassLoader(); } result = (Class) Class.forName(canonicalName, + * false, classLoader); result.asSubclass(strategyType); } catch + * (org.apache.commons.configuration.ConfigurationException cause) { throw new + * ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); } catch + * (ClassNotFoundException cause) { key = Strings.getString("{0}-class-not-found", typeName); throw new + * ConfigurationException(bundle.getString(key, canonicalName)); } catch (FileNotFoundException e) { throw new + * ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); } catch (ClassCastException + * cause) { key = Strings.getString("{0}-class-must-be-of-type", typeName); throw new + * ConfigurationException(bundle.getString(key, canonicalName, strategyType)); } return result; } + */ } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java index a707baf..d2fd6a0 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java @@ -39,6 +39,7 @@ package br.gov.frameworkdemoiselle.internal.implementation; import javax.inject.Named; import br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap; +import br.gov.frameworkdemoiselle.internal.configuration.TransactionConfig; import br.gov.frameworkdemoiselle.transaction.Transaction; import br.gov.frameworkdemoiselle.transaction.TransactionContext; import br.gov.frameworkdemoiselle.util.Beans; @@ -58,9 +59,10 @@ public class TransactionContextImpl implements TransactionContext { private Transaction getTransaction() { if (this.transaction == null) { TransactionBootstrap bootstrap = Beans.getReference(TransactionBootstrap.class); + Class clazz = getConfig().getTransactionClass(); + clazz = StrategySelector.getClass(clazz, bootstrap.getCache()); - this.transaction = StrategySelector.getReference("frameworkdemoiselle.transaction.class", - Transaction.class, DefaultTransaction.class, bootstrap.getCache()); + this.transaction = Beans.getReference(clazz); } return this.transaction; @@ -70,4 +72,8 @@ public class TransactionContextImpl implements TransactionContext { public Transaction getCurrentTransaction() { return getTransaction(); } + + private TransactionConfig getConfig() { + return Beans.getReference(TransactionConfig.class); + } } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithArrayTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithArrayTest.java index f740373..5b60a92 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithArrayTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithArrayTest.java @@ -35,10 +35,11 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. */ package br.gov.frameworkdemoiselle.internal.configuration; -import org.junit.Ignore; + +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.junit.Assert.assertEquals; -import static org.powermock.api.easymock.PowerMock.mockStatic; +import static org.powermock.api.easymock.PowerMock.replay; import java.awt.Color; import java.math.BigDecimal; @@ -54,7 +55,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; import org.slf4j.Logger; @@ -64,63 +64,88 @@ import br.gov.frameworkdemoiselle.configuration.Configuration; import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; import br.gov.frameworkdemoiselle.util.ResourceBundle; -@Ignore @RunWith(PowerMockRunner.class) -@PrepareForTest(CoreBootstrap.class) public class ConfigurationLoaderWithArrayTest { private ConfigurationLoader configurationLoader; - @Configuration(type = ConfigType.PROPERTIES , resource = "configuration-with-array") + @Configuration(type = ConfigType.PROPERTIES, resource = "configuration-with-array") public class ConfigurationPropertiesWithArray { - + /* * All methods supported by org.apache.commons.configuration.DataConfiguration class for array */ - + protected BigDecimal[] bigDecimalArray; + protected BigInteger[] bigIntegerArray; + protected boolean[] booleanArray; + protected byte[] byteArray; + protected Calendar[] calendarArray; + protected Color[] colorArray; + protected Date[] dateArray; + protected double[] doubleArray; + protected float[] floatArray; + protected int[] integerArray; + protected Locale[] localeArray; + protected long[] longArray; + protected short[] shortArray; + protected URL[] urlArray; + protected String[] stringArray; - + } - + @Configuration(type = ConfigType.XML, resource = "configuration-with-array") public class ConfigurationXMLWithArray { - + /* * All methods supported by org.apache.commons.configuration.DataConfiguration class for array */ - + protected BigDecimal[] bigDecimalArray; + protected BigInteger[] bigIntegerArray; + protected boolean[] booleanArray; + protected byte[] byteArray; + protected Calendar[] calendarArray; + protected Color[] colorArray; + protected Date[] dateArray; + protected double[] doubleArray; + protected float[] floatArray; + protected int[] integerArray; + protected Locale[] localeArray; + protected long[] longArray; + protected short[] shortArray; + protected URL[] urlArray; + protected String[] stringArray; - + } - @Before public void setUp() throws Exception { @@ -140,178 +165,176 @@ public class ConfigurationLoaderWithArrayTest { @Test public void testConfigurationPropertiesWithIntegerArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Integer integerValue = config.integerArray[0]; - + assertEquals(Integer.class, integerValue.getClass()); assertEquals(Integer.MAX_VALUE, integerValue.intValue()); assertEquals(4, config.integerArray.length); } - - + @Test public void testConfigurationPropertiesWithShortArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Short shortValue = config.shortArray[0]; - + assertEquals(Short.class, shortValue.getClass()); assertEquals(Short.MAX_VALUE, shortValue.shortValue()); assertEquals(4, config.shortArray.length); } - + @Test public void testConfigurationPropertiesWithByteArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Byte byteValue = config.byteArray[0]; - + assertEquals(Byte.class, byteValue.getClass()); assertEquals(Byte.MAX_VALUE, byteValue.byteValue()); assertEquals(8, config.byteArray.length); } - + @Test public void testConfigurationPropertiesWithBooleanArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Boolean booleanValue = config.booleanArray[0]; - + assertEquals(Boolean.class, booleanValue.getClass()); assertEquals(2, config.booleanArray.length); } - + @Test public void testConfigurationPropertiesWithLongArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Long longValue = config.longArray[0]; - + assertEquals(Long.class, longValue.getClass()); assertEquals(Long.MAX_VALUE, longValue.longValue()); assertEquals(5, config.longArray.length); } - + @Test public void testConfigurationPropertiesWithFloatArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Float floatValue = config.floatArray[0]; - + assertEquals(Float.class, floatValue.getClass()); assertEquals(Float.MAX_VALUE, floatValue.floatValue(), 1); assertEquals(5, config.floatArray.length); } - + @Test public void testConfigurationPropertiesWithDoubleArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Double doubleValue = config.doubleArray[0]; - + assertEquals(Double.class, doubleValue.getClass()); assertEquals(Double.MAX_VALUE, doubleValue.doubleValue(), 1); assertEquals(3, config.doubleArray.length); } - + @Test public void testConfigurationPropertiesWithBigDecimalArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + BigDecimal bigDecimalValue = config.bigDecimalArray[0]; - + assertEquals(BigDecimal.class, bigDecimalValue.getClass()); assertEquals(3, config.bigDecimalArray.length); } - + @Test public void testConfigurationPropertiesWithBigIntegerArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + BigInteger bigIntegerValue = config.bigIntegerArray[0]; - + assertEquals(BigInteger.class, bigIntegerValue.getClass()); assertEquals(3, config.bigIntegerArray.length); } - + @Test public void testConfigurationPropertiesWithCalendarArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Calendar calendarValue = config.calendarArray[0]; - + GregorianCalendar calendar = new GregorianCalendar(2012, Calendar.JUNE, 14, 10, 10); - + assertEquals(Calendar.class, calendarValue.getClass().getSuperclass()); assertEquals(calendar.getTimeInMillis(), calendarValue.getTimeInMillis()); assertEquals(3, config.calendarArray.length); } - + @Test public void testConfigurationPropertiesWithDateArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Date dateValue = config.dateArray[0]; - + GregorianCalendar calendar = new GregorianCalendar(2012, Calendar.AUGUST, 14, 18, 10, 50); - + Date date = new Date(calendar.getTimeInMillis()); - + assertEquals(Date.class, dateValue.getClass()); assertEquals(date.getTime(), dateValue.getTime()); assertEquals(3, config.dateArray.length); } - + @Test public void testConfigurationPropertiesWithColorArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Color colorValue = config.colorArray[0]; - + assertEquals(Color.class, colorValue.getClass()); assertEquals(Color.gray, colorValue); assertEquals(3, config.colorArray.length); } - + @Test public void testConfigurationPropertiesWithLocaleArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + Locale localeValue = config.localeArray[0]; Locale localeValue2 = config.localeArray[1]; - + assertEquals(Locale.class, localeValue.getClass()); assertEquals(Locale.ENGLISH, localeValue); assertEquals("BR", localeValue2.getCountry()); assertEquals(3, config.localeArray.length); } - + @Test public void testConfigurationPropertiesWithURLArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + URL urlValue = config.urlArray[0]; - + URL otherURL = null; - + try { otherURL = new URL("http://www.test.com"); + } catch (Exception e) { + } - catch(Exception e) { - - } - + assertEquals(URL.class, urlValue.getClass()); assertEquals(otherURL, urlValue); assertEquals(3, config.urlArray.length); } - + @Test public void testConfigurationPropertiesWithStringArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); - + String stringValue = config.stringArray[0]; - + assertEquals(String.class, stringValue.getClass()); assertEquals("Test", stringValue); assertEquals(3, config.stringArray.length); @@ -320,189 +343,188 @@ public class ConfigurationLoaderWithArrayTest { private ConfigurationPropertiesWithArray prepareConfigurationPropertiesWithArray() { ConfigurationPropertiesWithArray config = new ConfigurationPropertiesWithArray(); - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); + CoreBootstrap coreBootstrap = createMock(CoreBootstrap.class); + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); + + replay(coreBootstrap); configurationLoader.load(config); return config; } - + @Test public void testConfigurationXMLWithIntegerArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Integer integerValue = config.integerArray[0]; - + assertEquals(Integer.class, integerValue.getClass()); assertEquals(Integer.MAX_VALUE, integerValue.intValue()); assertEquals(4, config.integerArray.length); } - - + @Test public void testConfigurationXMLWithShortArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Short shortValue = config.shortArray[0]; - + assertEquals(Short.class, shortValue.getClass()); assertEquals(Short.MAX_VALUE, shortValue.shortValue()); assertEquals(4, config.shortArray.length); } - + @Test public void testConfigurationXMLWithByteArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Byte byteValue = config.byteArray[0]; - + assertEquals(Byte.class, byteValue.getClass()); assertEquals(Byte.MAX_VALUE, byteValue.byteValue()); assertEquals(8, config.byteArray.length); } - + @Test public void testConfigurationXMLWithBooleanArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Boolean booleanValue = config.booleanArray[0]; - + assertEquals(Boolean.class, booleanValue.getClass()); assertEquals(2, config.booleanArray.length); } - + @Test public void testConfigurationXMLWithLongArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Long longValue = config.longArray[0]; - + assertEquals(Long.class, longValue.getClass()); assertEquals(Long.MAX_VALUE, longValue.longValue()); assertEquals(5, config.longArray.length); } - + @Test public void testConfigurationXMLWithFloatArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Float floatValue = config.floatArray[0]; - + assertEquals(Float.class, floatValue.getClass()); assertEquals(Float.MAX_VALUE, floatValue.floatValue(), 1); assertEquals(5, config.floatArray.length); } - + @Test public void testConfigurationXMLWithDoubleArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Double doubleValue = config.doubleArray[0]; - + assertEquals(Double.class, doubleValue.getClass()); assertEquals(Double.MAX_VALUE, doubleValue.doubleValue(), 1); assertEquals(3, config.doubleArray.length); } - + @Test public void testConfigurationXMLWithBigDecimalArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + BigDecimal bigDecimalValue = config.bigDecimalArray[0]; - + assertEquals(BigDecimal.class, bigDecimalValue.getClass()); assertEquals(3, config.bigDecimalArray.length); } - + @Test public void testConfigurationXMLWithBigIntegerArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + BigInteger bigIntegerValue = config.bigIntegerArray[0]; - + assertEquals(BigInteger.class, bigIntegerValue.getClass()); assertEquals(3, config.bigIntegerArray.length); } - + @Test public void testConfigurationXMLWithCalendarArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Calendar calendarValue = config.calendarArray[0]; - + GregorianCalendar calendar = new GregorianCalendar(2012, Calendar.JUNE, 14, 10, 10); - + assertEquals(Calendar.class, calendarValue.getClass().getSuperclass()); assertEquals(calendar.getTimeInMillis(), calendarValue.getTimeInMillis()); assertEquals(3, config.calendarArray.length); } - + @Test public void testConfigurationXMLWithDateArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Date dateValue = config.dateArray[0]; - + GregorianCalendar calendar = new GregorianCalendar(2012, Calendar.AUGUST, 14, 18, 10, 50); - + Date date = new Date(calendar.getTimeInMillis()); - + assertEquals(Date.class, dateValue.getClass()); assertEquals(date.getTime(), dateValue.getTime()); assertEquals(3, config.dateArray.length); } - + @Test public void testConfigurationXMLWithColorArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Color colorValue = config.colorArray[0]; - + assertEquals(Color.class, colorValue.getClass()); assertEquals(Color.gray, colorValue); assertEquals(3, config.colorArray.length); } - + @Test public void testConfigurationXMLWithLocaleArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + Locale localeValue = config.localeArray[0]; Locale localeValue2 = config.localeArray[1]; - + assertEquals(Locale.class, localeValue.getClass()); assertEquals(Locale.ENGLISH, localeValue); assertEquals("BR", localeValue2.getCountry()); assertEquals(3, config.localeArray.length); } - + @Test public void testConfigurationXMLWithURLArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + URL urlValue = config.urlArray[0]; - + URL otherURL = null; - + try { otherURL = new URL("http://www.test.com"); + } catch (Exception e) { + } - catch(Exception e) { - - } - + assertEquals(URL.class, urlValue.getClass()); assertEquals(otherURL, urlValue); assertEquals(3, config.urlArray.length); } - + @Test public void testConfigurationXMLWithStringArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); - + String stringValue = config.stringArray[0]; - + assertEquals(String.class, stringValue.getClass()); assertEquals("Test", stringValue); assertEquals(3, config.stringArray.length); @@ -511,9 +533,10 @@ public class ConfigurationLoaderWithArrayTest { private ConfigurationXMLWithArray prepareConfigurationXMLWithArray() { ConfigurationXMLWithArray config = new ConfigurationXMLWithArray(); - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); + CoreBootstrap coreBootstrap = createMock(CoreBootstrap.class); + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); + + replay(CoreBootstrap.class); configurationLoader.load(config); return config; diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithListTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithListTest.java index 9194c8b..96b23ef 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithListTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithListTest.java @@ -35,10 +35,11 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. */ package br.gov.frameworkdemoiselle.internal.configuration; -import org.junit.Ignore; + +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.junit.Assert.assertEquals; -import static org.powermock.api.easymock.PowerMock.mockStatic; +import static org.powermock.api.easymock.PowerMock.replay; import java.awt.Color; import java.math.BigDecimal; @@ -52,10 +53,10 @@ import java.util.Locale; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; import org.slf4j.Logger; @@ -67,7 +68,6 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; @Ignore @RunWith(PowerMockRunner.class) -@PrepareForTest(CoreBootstrap.class) public class ConfigurationLoaderWithListTest { private ConfigurationLoader configurationLoader; @@ -344,9 +344,10 @@ public class ConfigurationLoaderWithListTest { private ConfigurationPropertiesWithList prepareConfigurationPropertiesWithList() { ConfigurationPropertiesWithList config = new ConfigurationPropertiesWithList(); - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); + CoreBootstrap coreBootstrap = createMock(CoreBootstrap.class); + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); + + replay(coreBootstrap); configurationLoader.load(config); return config; @@ -533,9 +534,10 @@ public class ConfigurationLoaderWithListTest { private ConfigurationXMLWithList prepareConfigurationXMLWithList() { ConfigurationXMLWithList config = new ConfigurationXMLWithList(); - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); + CoreBootstrap coreBootstrap = createMock(CoreBootstrap.class); + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); + + replay(coreBootstrap); configurationLoader.load(config); return config; diff --git a/impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java b/impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java index 2ceec96..59123ee 100644 --- a/impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java +++ b/impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java @@ -1,101 +1,101 @@ -/* - * 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.internal.configuration; -import org.junit.Ignore; -import static org.easymock.EasyMock.expect; -import static org.junit.Assert.assertEquals; -import static org.powermock.api.easymock.PowerMock.mockStatic; - -import java.util.Locale; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; -import org.slf4j.Logger; - -import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; -import br.gov.frameworkdemoiselle.util.ResourceBundle; - -/** - * @author e-saito - */ -/** - * @author 80342167553 - */ -@Ignore -@RunWith(PowerMockRunner.class) -@PrepareForTest(CoreBootstrap.class) -public class EntityManagerConfigTest { - - private EntityManagerConfig config = new EntityManagerConfig(); - - @Before - public void setUp() throws Exception { - Logger logger = PowerMock.createMock(Logger.class); - ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); - - ConfigurationLoader configurationLoader = new ConfigurationLoader(); - - Whitebox.setInternalState(configurationLoader, "bundle", bundle); - Whitebox.setInternalState(configurationLoader, "logger", logger); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - } - - @After - public void tearDown() throws Exception { - config = null; - } - - /** - * Test method for - * {@link br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig#getPersistenceUnitName()}. - */ - @Test - public void testGetPersistenceUnitName() { - assertEquals("PersistenceUnitName", config.getPersistenceUnitName()); - } -} +///* +// * 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.internal.configuration; +//import org.junit.Ignore; +//import static org.easymock.EasyMock.expect; +//import static org.junit.Assert.assertEquals; +//import static org.powermock.api.easymock.PowerMock.mockStatic; +// +//import java.util.Locale; +// +//import org.junit.After; +//import org.junit.Before; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.powermock.api.easymock.PowerMock; +//import org.powermock.core.classloader.annotations.PrepareForTest; +//import org.powermock.modules.junit4.PowerMockRunner; +//import org.powermock.reflect.Whitebox; +//import org.slf4j.Logger; +// +//import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; +//import br.gov.frameworkdemoiselle.util.ResourceBundle; +// +///** +// * @author e-saito +// */ +///** +// * @author 80342167553 +// */ +//@Ignore +//@RunWith(PowerMockRunner.class) +//@PrepareForTest(CoreBootstrap.class) +//public class EntityManagerConfigTest { +// +// private EntityManagerConfig config = new EntityManagerConfig(); +// +// @Before +// public void setUp() throws Exception { +// Logger logger = PowerMock.createMock(Logger.class); +// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); +// +// ConfigurationLoader configurationLoader = new ConfigurationLoader(); +// +// Whitebox.setInternalState(configurationLoader, "bundle", bundle); +// Whitebox.setInternalState(configurationLoader, "logger", logger); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// } +// +// @After +// public void tearDown() throws Exception { +// config = null; +// } +// +// /** +// * Test method for +// * {@link br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig#getPersistenceUnitName()}. +// */ +// @Test +// public void testGetPersistenceUnitName() { +// assertEquals("PersistenceUnitName", config.getPersistenceUnitName()); +// } +//} -- libgit2 0.21.2