[seam-commits] Seam SVN: r10672 - in modules/trunk: international and 11 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Apr 28 03:36:10 EDT 2009
Author: dan.j.allen
Date: 2009-04-28 03:36:10 -0400 (Tue, 28 Apr 2009)
New Revision: 10672
Added:
modules/trunk/international/src/test/java/org/jboss/seam/international/InterpolatorTest.java
modules/trunk/international/src/test/java/org/jboss/seam/international/LocaleProducerTest.java
modules/trunk/international/src/test/java/org/jboss/seam/international/LocaleProducerUnitTest.java
modules/trunk/international/src/test/resources/
modules/trunk/international/src/test/resources/org/
modules/trunk/international/src/test/resources/org/jboss/
modules/trunk/international/src/test/resources/org/jboss/testharness/
modules/trunk/international/src/test/resources/org/jboss/testharness/impl/
modules/trunk/international/src/test/resources/org/jboss/testharness/impl/packaging/
modules/trunk/international/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/
modules/trunk/international/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/default/
modules/trunk/international/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/default/beans.xml
modules/trunk/international/src/test/resources/test-suite.xml
Modified:
modules/trunk/el/src/test/java/org/jboss/seam/el/SeamELResolverUnitTest.java
modules/trunk/international/pom.xml
modules/trunk/international/src/main/java/org/jboss/seam/international/Interpolator.java
modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleProducer.java
Log:
add some tests for EL-related components
Modified: modules/trunk/el/src/test/java/org/jboss/seam/el/SeamELResolverUnitTest.java
===================================================================
--- modules/trunk/el/src/test/java/org/jboss/seam/el/SeamELResolverUnitTest.java 2009-04-28 06:19:42 UTC (rev 10671)
+++ modules/trunk/el/src/test/java/org/jboss/seam/el/SeamELResolverUnitTest.java 2009-04-28 07:36:10 UTC (rev 10672)
@@ -13,7 +13,7 @@
/**
* Verify that the magic properties are properly resolved
- * by the {@link SeamELResolver}.
+ * by the {@link SeamELResolver} on the base objects passed in.
*
* @author Dan Allen
* @see SeamELResolver
@@ -76,6 +76,7 @@
assertEquals(result, 3);
assertTrue(ctx.isPropertyResolved());
}
+
@Test
public void testMapBogusProperty()
Modified: modules/trunk/international/pom.xml
===================================================================
--- modules/trunk/international/pom.xml 2009-04-28 06:19:42 UTC (rev 10671)
+++ modules/trunk/international/pom.xml 2009-04-28 07:36:10 UTC (rev 10672)
@@ -14,31 +14,104 @@
<version>3.0.0-SNAPSHOT</version>
<name>Seam Internationalization Module</name>
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/test-suite.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
<dependencies>
+
+ <!-- TODO pull up test dependencies -->
<dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-core-test</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.test-harness</groupId>
+ <artifactId>jboss-test-harness</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.test-harness</groupId>
+ <artifactId>jboss-test-harness</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- we don't have a generic javax.ejb 3.1 api yet -->
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0-Alpha1</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>jboss-jaxrpc</artifactId>
+ <groupId>jbossws</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jboss-transaction-api</artifactId>
+ <groupId>org.jboss.javaee</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jboss-jaxrpc</artifactId>
+ <groupId>jboss.jbossws</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seam-el</artifactId>
</dependency>
+
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
+
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<scope>provided</scope>
</dependency>
+
<dependency>
<groupId>org.jboss.webbeans</groupId>
<artifactId>jsr299-api</artifactId>
<scope>provided</scope>
</dependency>
+
<dependency>
<groupId>org.jboss.webbeans</groupId>
<artifactId>webbeans-logging</artifactId>
<!-- provided? -->
</dependency>
+
</dependencies>
</project>
Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/Interpolator.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/Interpolator.java 2009-04-28 06:19:42 UTC (rev 10671)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/Interpolator.java 2009-04-28 07:36:10 UTC (rev 10672)
@@ -15,14 +15,13 @@
*
* @author Gavin King
*/
+public
@Dependent
-public class Interpolator
+class Interpolator
{
private static final LogProvider log = Logging.getLogProvider(Interpolator.class);
- // QUESTION should this be Manager, then lookup by type?
@Current Expressions expressions;
-
@Current Locale locale;
/**
Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleProducer.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleProducer.java 2009-04-28 06:19:42 UTC (rev 10671)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleProducer.java 2009-04-28 07:36:10 UTC (rev 10672)
@@ -1,6 +1,6 @@
package org.jboss.seam.international;
-import javax.annotation.Named;
+import javax.context.Dependent;
import javax.inject.Produces;
/**
@@ -10,11 +10,13 @@
*
* @author Gavin King
*/
-public class LocaleProducer
+public
+ at Dependent
+class LocaleProducer
{
public
@Produces
- @Named java.util.Locale getLocale()
+ java.util.Locale getLocale()
{
return java.util.Locale.getDefault();
}
Added: modules/trunk/international/src/test/java/org/jboss/seam/international/InterpolatorTest.java
===================================================================
--- modules/trunk/international/src/test/java/org/jboss/seam/international/InterpolatorTest.java (rev 0)
+++ modules/trunk/international/src/test/java/org/jboss/seam/international/InterpolatorTest.java 2009-04-28 07:36:10 UTC (rev 10672)
@@ -0,0 +1,120 @@
+package org.jboss.seam.international;
+
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import org.jboss.seam.el.AbstractELResolver;
+import static org.testng.Assert.*;
+
+import org.jboss.seam.el.Expressions;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.webbeans.test.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+/**
+ * Verify that the {@link Interpolator} properly resolves both EL value
+ * expressions and positional substitutions, while also honoring the
+ * {@link Locale} returns by the {@link LocalProducer}.
+ *
+ * @author Dan Allen
+ * @see Interpolator
+ * @see Expressions
+ * @see LocaleProducer
+ */
+ at Artifact(addCurrentPackage = false)
+ at Classes({Interpolator.class, Expressions.class, LocaleProducer.class})
+public class InterpolatorTest extends AbstractWebBeansTest
+{
+ @Override
+ public void beforeMethod()
+ {
+ super.beforeMethod();
+ installTestFixtureELResolver();
+ }
+
+ @Test
+ public void testValueExpressionInterpolation()
+ {
+ String result = getInterpolatorInstance().interpolate("Hey #{name}!");
+ assertEquals(result, "Hey Dan!");
+ }
+
+ @Test
+ public void testParameterSubstitution()
+ {
+ String result = getInterpolatorInstance().interpolate("The two planets between the Earth and the Sun are {0} and {1}.", "Mercury", "Venus");
+ assertEquals(result, "The two planets between the Earth and the Sun are Mercury and Venus.");
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testInterpolateExceedsMaxParameters()
+ {
+ getInterpolatorInstance().interpolate("doesn't matter", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
+ }
+
+ @Test
+ public void testMultipleValueExpressionsAndParameters()
+ {
+ String result = getInterpolatorInstance().interpolate("#{name}, meet {0}. {0}, meet #{name}. Everyone, meet {1}.", "Pete", "Gavin");
+ assertEquals(result, "Dan, meet Pete. Pete, meet Dan. Everyone, meet Gavin.");
+ }
+
+ @Test
+ public void testFormatWithProperLocale()
+ {
+ Locale current = Locale.getDefault();
+ try {
+ Calendar cal = Calendar.getInstance();
+ cal.set(2009, 5, 2);
+ Locale.setDefault(Locale.US);
+ String result = getInterpolatorInstance().interpolate("On {0,date} there was a disturbance in Java EE.", cal.getTime());
+ assertEquals(result, "On Jun 2, 2009 there was a disturbance in Java EE.");
+
+ Locale.setDefault(Locale.FRANCE);
+ result = getInterpolatorInstance().interpolate("On {0,date} there was a disturbance in Java EE.", cal.getTime());
+ assertEquals(result, "On 2 juin 2009 there was a disturbance in Java EE.");
+ }
+ finally {
+ Locale.setDefault(current);
+ }
+ }
+
+ private Interpolator getInterpolatorInstance() {
+ return getCurrentManager().getInstanceByType(Interpolator.class);
+ }
+
+ private void installTestFixtureELResolver()
+ {
+ Map<Object, Object> fixture = new HashMap<Object, Object>();
+ fixture.put("name", "Dan");
+ Expressions expressions = getCurrentManager().getInstanceByType(Expressions.class);
+ // FIXME wow this is a hack
+ ((CompositeELResolver) expressions.getELContext().getELResolver()).add(new TestFixtureELResolver(fixture));
+ }
+
+ public class TestFixtureELResolver extends AbstractELResolver
+ {
+ private Map<Object, Object> data;
+
+ public TestFixtureELResolver(Map<Object, Object> data)
+ {
+ this.data = data;
+ }
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property)
+ {
+ if (base == null && data.containsKey(property))
+ {
+ context.setPropertyResolved(true);
+ return data.get(property);
+ }
+
+ return null;
+ }
+ }
+}
Added: modules/trunk/international/src/test/java/org/jboss/seam/international/LocaleProducerTest.java
===================================================================
--- modules/trunk/international/src/test/java/org/jboss/seam/international/LocaleProducerTest.java (rev 0)
+++ modules/trunk/international/src/test/java/org/jboss/seam/international/LocaleProducerTest.java 2009-04-28 07:36:10 UTC (rev 10672)
@@ -0,0 +1,27 @@
+package org.jboss.seam.international;
+
+import static org.testng.Assert.*;
+
+import java.util.Locale;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.webbeans.test.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+/**
+ * Ensure that the {@link LocaleProducer} returns the
+ * default locale when the type {@link Locale} is resolved.
+ *
+ * @author Dan Allen
+ */
+ at Artifact(addCurrentPackage = false)
+ at Classes(LocaleProducer.class)
+public class LocaleProducerTest extends AbstractWebBeansTest
+{
+ @Test
+ public void testDefaultIsJvmDefault()
+ {
+ Locale result = getCurrentManager().getInstanceByType(Locale.class);
+ assertEquals(result.toString(), Locale.getDefault().toString());
+ }
+}
Added: modules/trunk/international/src/test/java/org/jboss/seam/international/LocaleProducerUnitTest.java
===================================================================
--- modules/trunk/international/src/test/java/org/jboss/seam/international/LocaleProducerUnitTest.java (rev 0)
+++ modules/trunk/international/src/test/java/org/jboss/seam/international/LocaleProducerUnitTest.java 2009-04-28 07:36:10 UTC (rev 10672)
@@ -0,0 +1,23 @@
+package org.jboss.seam.international;
+
+import java.util.Locale;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+/**
+ * Verify that the default {@link LocalProducer} returns the
+ * default locale of the JVM.
+ *
+ * @author Dan Allen
+ */
+public class LocaleProducerUnitTest
+{
+ @Test
+ public void testLocaleIsJvmDefault()
+ {
+ LocaleProducer producer = new LocaleProducer();
+ Locale result = producer.getLocale();
+ assertNotNull(result);
+ assertEquals(result.toString(), Locale.getDefault().toString());
+ }
+}
Added: modules/trunk/international/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/default/beans.xml
===================================================================
Added: modules/trunk/international/src/test/resources/test-suite.xml
===================================================================
--- modules/trunk/international/src/test/resources/test-suite.xml (rev 0)
+++ modules/trunk/international/src/test/resources/test-suite.xml 2009-04-28 07:36:10 UTC (rev 10672)
@@ -0,0 +1,15 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="Seam International Module Unit Tests" verbose="1">
+ <test name="Seam International Module Unit Tests">
+ <!--
+ <method-selectors>
+ <method-selector>
+ <selector-class name="org.jboss.testharness.impl.testng.DisableIntegrationTestsMethodSelector"/>
+ </method-selector>
+ </method-selectors>
+ -->
+ <packages>
+ <package name="org.jboss.seam.international"/>
+ </packages>
+ </test>
+</suite>
More information about the seam-commits
mailing list