You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Howard Lewis Ship <hl...@gmail.com> on 2006/12/20 19:20:40 UTC

PageTester / InAppInvocation / Link / LinkImpl

I'm seeing where you are going with this.

However, I'm troubled by the necessity to cast from Link to LinkImpl, and
the need for different components to know about the InAppInvocationMap.

How about if we invert things; have components pass themselves to
LinkFactory and let LinkFactory deal with the InAppInvocationMap?  You may
be able to get rid of some methods from LinkImpl as well.

... and Kent, I think you're seeing how hard it is to name things well :-)

I'm thinking that an InAppInvocation may actually be a kind of Entrypoint
that may be referenced from the client.  Which is to say, any URL that the
client can send to the server and get a response from represents an
Entrypoint.  Different Entrypoints represent different Application
Behaviors.  Perhaps Behavior is also a better term for InAppInvocation?
Just some naming brainstorming!


---------- Forwarded message ----------
From: freemant@apache.org <fr...@apache.org>
Date: Dec 20, 2006 1:29 AM
Subject: svn commit: r488996 - in
/tapestry/tapestry5/tapestry-core/trunk/src:
main/java/org/apache/tapestry/internal/services/
main/java/org/apache/tapestry/test/pagelevel/
test/java/org/apache/tapestry/integration/app2/pages/
test/java/org/apache/tapestry/int...
To: commits@tapestry.apache.org

Author: freemant
Date: Wed Dec 20 01:29:16 2006
New Revision: 488996

URL: http://svn.apache.org/viewvc?view=rev&rev=488996
Log:
Added support for preferred language in PageTester.

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetter.java
(with props)
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java
(with props)
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/services/
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/services/LocaleAppModule.java
(with props)
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java
(with props)
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java
(with props)
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html
(with props)
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale_fr.html
(with props)
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationFilter.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/ActionLinkTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/FormTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/IfTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LoopTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationFilterTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForIf.html

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
Wed Dec 20 01:29:16 2006
@@ -262,13 +262,19 @@
     public void
contributeRequestFilters(OrderedConfiguration<RequestFilter> configuration,
             @InjectService("tapestry.RequestGlobals")
             final RequestGlobals requestGlobals, @Inject("${
tapestry.file-check-interval}")
-            long checkInterval, @Inject("${tapestry.supported-locales}")
-            String localeNames)
+            long checkInterval, @InjectService("LocalizationSetter")
+            LocalizationSetter localizationSetter)
     {
         configuration.add("CheckForUpdates", new
CheckForUpdatesFilter(_updateListenerHub,
                 checkInterval), "before:*.*");

-        configuration.add("Localization", new
LocalizationFilter(_threadLocale, localeNames));
+        configuration.add("Localization", new
LocalizationFilter(localizationSetter));
+    }
+
+    public LocalizationSetter buildLocalizationSetter(@Inject("${
tapestry.supported-locales}")
+    String localeNames)
+    {
+        return new LocalizationSetterImpl(_threadLocale, localeNames);
     }

     /**

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationFilter.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationFilter.java?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationFilter.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationFilter.java
Wed Dec 20 01:29:16 2006
@@ -14,15 +14,8 @@

package org.apache.tapestry.internal.services;

-import static
org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
-import static
org.apache.tapestry.ioc.internal.util.CollectionFactory.newThreadSafeMap;
-
import java.io.IOException;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;

-import org.apache.tapestry.ioc.services.ThreadLocale;
import org.apache.tapestry.services.Request;
import org.apache.tapestry.services.RequestFilter;
import org.apache.tapestry.services.RequestHandler;
@@ -35,93 +28,19 @@
  */
public class LocalizationFilter implements RequestFilter
{
-    private final ThreadLocale _threadLocale;
-
-    private final Locale _defaultLocale;
-
-    private final Set<String> _acceptedLocaleNames;
-
-    private final Map<String, Locale> _localeCache = newThreadSafeMap();
-
-    public LocalizationFilter(ThreadLocale threadLocale, String
acceptedLocaleNames)
+    private final LocalizationSetter _setter;
+
+    public LocalizationFilter(LocalizationSetter setter)
     {
-        _threadLocale = threadLocale;
-
-        String[] names = acceptedLocaleNames.split(",");
-
-        _defaultLocale = toLocale(names[0]);
-
-        _acceptedLocaleNames = newSet(names);
-    }
-
-    Locale toLocale(String localeName)
-    {
-        Locale result = _localeCache.get(localeName);
-
-        if (result == null)
-        {
-            result = constructLocale(localeName);
-            _localeCache.put(localeName, result);
-        }
-
-        return result;
-    }
-
-    private Locale constructLocale(String name)
-    {
-        String[] terms = name.split("_");
-
-        switch (terms.length)
-        {
-            case 1:
-                return new Locale(terms[0], "");
-
-            case 2:
-                return new Locale(terms[0], terms[1]);
-
-            case 3:
-
-                return new Locale(terms[0], terms[1], terms[2]);
-
-            default:
-
-                throw new IllegalArgumentException();
-        }
+        _setter = setter;
     }

     public boolean service(Request request, Response response,
RequestHandler handler)
             throws IOException
     {
-        Locale locale = extractLocaleFromRequest(request);
-
-        _threadLocale.setLocale(locale);
+        _setter.setThreadLocale(request.getLocale());

         return handler.service(request, response);
-    }
-
-    public Locale extractLocaleFromRequest(Request request)
-    {
-        String localeName = request.getLocale().toString();
-
-        while (true)
-        {
-            if (_acceptedLocaleNames.contains(localeName))
-                return toLocale(localeName);
-
-            localeName = stripTerm(localeName);
-
-            if (localeName.length() == 0)
-                break;
-        }
-
-        return _defaultLocale;
-    }
-
-    static String stripTerm(String localeName)
-    {
-        int scorex = localeName.lastIndexOf('_');
-
-        return scorex < 0 ? "" : localeName.substring(0, scorex);
     }

}

Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetter.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetter.java?view=auto&rev=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetter.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetter.java
Wed Dec 20 01:29:16 2006
@@ -0,0 +1,28 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import java.util.Locale;
+
+/**
+ * Sets the thread's locale given a desired locale. Note that the desired
locale is just a hint. It
+ * wil try to honor it but there is no guarantee that it will be used as
is.
+ */
+public interface LocalizationSetter
+{
+
+    void setThreadLocale(Locale desiredLocale);
+
+}
\ No newline at end of file

Propchange:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java?view=auto&rev=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java
Wed Dec 20 01:29:16 2006
@@ -0,0 +1,118 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import static
org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
+import static
org.apache.tapestry.ioc.internal.util.CollectionFactory.newThreadSafeMap;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tapestry.ioc.services.ThreadLocale;
+
+/**
+ * Given a set of supported locales, for a specified desired locale, sets
the current thread's
+ * locale to a supported locale that is closest to the desired.
+ */
+public class LocalizationSetterImpl implements LocalizationSetter
+{
+    private final ThreadLocale _threadLocale;
+
+    private final Locale _defaultLocale;
+
+    private final Set<String> _acceptedLocaleNames;
+
+    private final Map<String, Locale> _localeCache = newThreadSafeMap();
+
+    public LocalizationSetterImpl(ThreadLocale threadLocale, String
acceptedLocaleNames)
+    {
+        _threadLocale = threadLocale;
+
+        String[] names = acceptedLocaleNames.split(",");
+
+        _defaultLocale = toLocale(names[0]);
+
+        _acceptedLocaleNames = newSet(names);
+    }
+
+    Locale toLocale(String localeName)
+    {
+        Locale result = _localeCache.get(localeName);
+
+        if (result == null)
+        {
+            result = constructLocale(localeName);
+            _localeCache.put(localeName, result);
+        }
+
+        return result;
+    }
+
+    private Locale constructLocale(String name)
+    {
+        String[] terms = name.split("_");
+
+        switch (terms.length)
+        {
+            case 1:
+                return new Locale(terms[0], "");
+
+            case 2:
+                return new Locale(terms[0], terms[1]);
+
+            case 3:
+
+                return new Locale(terms[0], terms[1], terms[2]);
+
+            default:
+
+                throw new IllegalArgumentException();
+        }
+    }
+
+    public void setThreadLocale(Locale desiredLocale)
+    {
+        Locale locale = findClosestAcceptedLocale(desiredLocale);
+
+        _threadLocale.setLocale(locale);
+    }
+
+    private Locale findClosestAcceptedLocale(Locale desiredLocale)
+    {
+        String localeName = desiredLocale.toString();
+
+        while (true)
+        {
+            if (_acceptedLocaleNames.contains(localeName))
+                return toLocale(localeName);
+
+            localeName = stripTerm(localeName);
+
+            if (localeName.length() == 0)
+                break;
+        }
+
+        return _defaultLocale;
+    }
+
+    static String stripTerm(String localeName)
+    {
+        int scorex = localeName.lastIndexOf('_');
+
+        return scorex < 0 ? "" : localeName.substring(0, scorex);
+    }
+
+}

Propchange:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
Wed Dec 20 01:29:16 2006
@@ -17,6 +17,7 @@
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap
;

import java.util.Collections;
+import java.util.Locale;
import java.util.Map;

import org.apache.tapestry.dom.Document;
@@ -25,6 +26,7 @@
import org.apache.tapestry.internal.TapestryAppInitializer;
import org.apache.tapestry.internal.services.ActionLinkTarget;
import org.apache.tapestry.internal.services.InAppInvocation;
+import org.apache.tapestry.internal.services.LocalizationSetter;
import org.apache.tapestry.internal.services.PageLinkTarget;
import org.apache.tapestry.ioc.Registry;
import org.apache.tapestry.ioc.internal.util.Defense;
@@ -49,6 +51,10 @@

     private StrategyRegistry<InAppInvoker> _invokerRegistry;

+    private Locale _preferedLanguage;
+
+    private LocalizationSetter _localizationSetter;
+
     /**
      * Initializes a PageTester without overriding any services.
      *
@@ -75,6 +81,9 @@
     {
         _registry = new TapestryAppInitializer(appPackage, appName, "test",
                 addDefaultOverrides(serviceOverrides)).getRegistry();
+        _localizationSetter = _registry.getService(
+                "tapestry.internal.LocalizationSetter",
+                LocalizationSetter.class);
         buildInvokersRegistry();
     }

@@ -170,10 +179,19 @@
         // It is critical to clear the map before invoking an invocation
(render a page or click a
         // link).
         _invocationMap.clear();
+        setThreadLocale();
         InAppInvoker invoker = _invokerRegistry.getByInstance(
invocation.getTarget());
         return invoker.invoke(invocation);
     }

+    private void setThreadLocale()
+    {
+        if (_preferedLanguage != null)
+        {
+            _localizationSetter.setThreadLocale(_preferedLanguage);
+        }
+    }
+
     /**
      * Simulates a submission of the form specified. The caller can specify
values for the form
      * fields.
@@ -214,5 +232,10 @@
     private boolean isHiddenFormField(Element element)
     {
         return element.getName().equals("input") && "hidden".equals(
element.getAttribute("type"));
+    }
+
+    public void setPreferedLanguage(Locale preferedLanguage)
+    {
+        _preferedLanguage = preferedLanguage;
     }
}

Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java?view=auto&rev=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java
Wed Dec 20 01:29:16 2006
@@ -0,0 +1,23 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.integration.app2.pages;
+
+import org.apache.tapestry.annotations.ComponentClass;
+
+@ComponentClass
+public class TestPageForLocale
+{
+
+}

Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/services/LocaleAppModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/services/LocaleAppModule.java?view=auto&rev=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/services/LocaleAppModule.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/services/LocaleAppModule.java
Wed Dec 20 01:29:16 2006
@@ -0,0 +1,29 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.integration.app2.services;
+
+import org.apache.tapestry.ioc.MappedConfiguration;
+import org.apache.tapestry.ioc.annotations.Contribute;
+
+public class LocaleAppModule
+{
+       @Contribute("tapestry.ioc.ApplicationDefaults")
+       public static void contributeApplicationDefaults(
+                       MappedConfiguration<String, String> configuration)
+       {
+               configuration.add("tapestry.supported-locales", "en,fr,de");
+       }
+
+}

Propchange:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/services/LocaleAppModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/ActionLinkTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/ActionLinkTest.java?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/ActionLinkTest.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/ActionLinkTest.java
Wed Dec 20 01:29:16 2006
@@ -18,6 +18,7 @@
import org.apache.tapestry.dom.Element;
import org.apache.tapestry.test.pagelevel.PageTester;
import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class ActionLinkTest extends Assert
@@ -36,6 +37,7 @@
         assertTrue(doc.toString().contains("You chose: 123"));
     }

+    @AfterMethod
     public void after()
     {
         if (_tester != null)

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/FormTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/FormTest.java?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/FormTest.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/FormTest.java
Wed Dec 20 01:29:16 2006
@@ -21,6 +21,7 @@
import org.apache.tapestry.ioc.internal.util.CollectionFactory;
import org.apache.tapestry.test.pagelevel.PageTester;
import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class FormTest extends Assert
@@ -41,6 +42,7 @@
         assertTrue(doc.toString().contains("You entered: hello"));
     }

+    @AfterMethod
     public void after()
     {
         if (_tester != null)

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/IfTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/IfTest.java?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/IfTest.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/IfTest.java
Wed Dec 20 01:29:16 2006
@@ -17,30 +17,32 @@
import org.apache.tapestry.dom.Document;
import org.apache.tapestry.test.pagelevel.PageTester;
import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class IfTest extends Assert
{
-    private PageTester tester;
+    private PageTester _tester;

     @Test
     public void render()
     {
         String appPackage = "org.apache.tapestry.integration.app2";
         String appName = "";
-        tester = new PageTester(appPackage, appName);
-        Document doc = tester.renderPage("TestPageForIf");
+        _tester = new PageTester(appPackage, appName);
+        Document doc = _tester.renderPage("TestPageForIf");
         assertNotNull(doc.getElementById("1"));
         assertNotNull(doc.getElementById("3"));
         assertNull(doc.getElementById("2"));
         assertNull(doc.getElementById("4"));
     }

+    @AfterMethod
     public void after()
     {
-        if (tester != null)
+        if (_tester != null)
         {
-            tester.shutdown();
+            _tester.shutdown();
         }
     }
}

Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java?view=auto&rev=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java
Wed Dec 20 01:29:16 2006
@@ -0,0 +1,62 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.integration.pagelevel;
+
+import java.util.Locale;
+
+import org.apache.tapestry.dom.Document;
+import org.apache.tapestry.test.pagelevel.PageTester;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class LocaleTest extends Assert
+{
+    private PageTester _tester;
+
+    @Test
+    public void no_preferred_language()
+    {
+        Document doc = _tester.renderPage("TestPageForLocale");
+        assertEquals(doc.getElementById("id1").getChildText(), "English
page");
+    }
+
+    @Test
+    public void prefer_canada_french()
+    {
+        _tester.setPreferedLanguage(Locale.CANADA_FRENCH);
+        Document doc = _tester.renderPage("TestPageForLocale");
+        assertEquals(doc.getElementById("id1").getChildText(), "French
page");
+    }
+
+    @BeforeMethod
+    public void before()
+    {
+        String appPackage = "org.apache.tapestry.integration.app2";
+        // LocaleAppModule.java has configured support for a certain
locales.
+        String appName = "LocaleApp";
+        _tester = new PageTester(appPackage, appName);
+    }
+
+    @AfterMethod
+    public void after()
+    {
+        if (_tester != null)
+        {
+            _tester.shutdown();
+        }
+    }
+}

Propchange:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LoopTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LoopTest.java?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LoopTest.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LoopTest.java
Wed Dec 20 01:29:16 2006
@@ -17,6 +17,7 @@
import org.apache.tapestry.dom.Document;
import org.apache.tapestry.test.pagelevel.PageTester;
import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class LoopTest extends Assert
@@ -34,6 +35,7 @@
         assertEquals(doc.getElementById("1").getChildText(), "xyz");
     }

+    @AfterMethod
     public void after()
     {
         if (_tester != null)

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationFilterTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationFilterTest.java?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationFilterTest.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationFilterTest.java
Wed Dec 20 01:29:16 2006
@@ -17,7 +17,6 @@
import java.io.IOException;
import java.util.Locale;

-import org.apache.tapestry.ioc.services.ThreadLocale;
import org.apache.tapestry.services.Request;
import org.apache.tapestry.services.RequestFilter;
import org.apache.tapestry.services.RequestHandler;
@@ -28,94 +27,27 @@
public class LocalizationFilterTest extends TapestryTestCase
{
     @Test
-    public void locale_split()
+    public void set_locale_and_service() throws IOException
     {
-        assertEquals(LocalizationFilter.stripTerm("foo_bar_Baz"),
"foo_bar");
-        assertEquals(LocalizationFilter.stripTerm("foo_bar"), "foo");
-        assertEquals(LocalizationFilter.stripTerm("foo"), "");
-    }
-
-    @Test
-    public void to_locale_is_cached()
-    {
-        LocalizationFilter filter = new LocalizationFilter(null, "en");
-
-        Locale l1 = filter.toLocale("en");
-
-        assertEquals(l1.toString(), "en");
-
-        checkLocale(l1, "en", "", "");
-
-        assertSame(filter.toLocale("en"), l1);
-    }
-
-    private void checkLocale(Locale l, String expectedLanguage, String
expectedCountry,
-            String expectedVariant)
-    {
-        assertEquals(l.getLanguage(), expectedLanguage);
-        assertEquals(l.getCountry(), expectedCountry);
-        assertEquals(l.getVariant(), expectedVariant);
-    }
-
-    @Test
-    public void to_locale()
-    {
-        LocalizationFilter filter = new LocalizationFilter(null, "en");
-
-        checkLocale(filter.toLocale("en"), "en", "", "");
-        checkLocale(filter.toLocale("klingon_Gach"), "klingon", "GACH",
"");
-        checkLocale(filter.toLocale("klingon_Gach_snuff"), "klingon",
"GACH", "snuff");
-    }
-
-    @Test
-    public void known_locale() throws IOException
-    {
-        ThreadLocale threadLocale = newThreadLocale();
         RequestHandler handler = newRequestHandler();
         Request request = newRequest();
         Response response = newResponse();
+        LocalizationSetter setter = newMock(LocalizationSetter.class);

         train_getLocale(request, Locale.CANADA_FRENCH);

-        // We don't actually verify that setLocale() occurs before
service(),
+        // We don't actually verify that setThreadLocale() occurs before
service(),
         // but sometimes you just have to trust that the code executes in
the
         // order its written.
-
-        threadLocale.setLocale(Locale.FRENCH);
+        setter.setThreadLocale(Locale.CANADA_FRENCH);

         train_service(handler, request, response, true);

         replay();

-        RequestFilter filter = new LocalizationFilter(threadLocale,
"en,fr");
+        RequestFilter filter = new LocalizationFilter(setter);

         assertTrue(filter.service(request, response, handler));
-
-        verify();
-    }
-
-    @Test
-    public void unknown_locale_uses_default_locale() throws IOException
-    {
-        ThreadLocale threadLocale = newThreadLocale();
-        RequestHandler handler = newRequestHandler();
-        Request request = newRequest();
-        Response response = newResponse();
-
-        train_getLocale(request, Locale.JAPANESE);
-
-        // This time, no real match, so the default (the first locale in
the list)
-        // will be used.
-
-        threadLocale.setLocale(Locale.ENGLISH);
-
-        train_service(handler, request, response, false);
-
-        replay();
-
-        RequestFilter filter = new LocalizationFilter(threadLocale,
"en,fr");
-
-        assertFalse(filter.service(request, response, handler));

         verify();
     }

Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java?view=auto&rev=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java
Wed Dec 20 01:29:16 2006
@@ -0,0 +1,102 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import java.util.Locale;
+
+import org.apache.tapestry.ioc.services.ThreadLocale;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class LocalizationSetterTest extends Assert
+{
+    private static class ThreadLocaleImpl implements ThreadLocale
+    {
+        public Locale _locale;
+
+        public void setLocale(Locale locale)
+        {
+            _locale = locale;
+        }
+
+        public Locale getLocale()
+        {
+            return _locale;
+        }
+
+    }
+
+    @Test
+    public void locale_split()
+    {
+        assertEquals(LocalizationSetterImpl.stripTerm("foo_bar_Baz"),
"foo_bar");
+        assertEquals(LocalizationSetterImpl.stripTerm("foo_bar"), "foo");
+        assertEquals(LocalizationSetterImpl.stripTerm("foo"), "");
+    }
+
+    @Test
+    public void to_locale_is_cached()
+    {
+        LocalizationSetterImpl filter = new LocalizationSetterImpl(null,
"en");
+
+        Locale l1 = filter.toLocale("en");
+
+        assertEquals(l1.toString(), "en");
+
+        checkLocale(l1, "en", "", "");
+
+        assertSame(filter.toLocale("en"), l1);
+    }
+
+    private void checkLocale(Locale l, String expectedLanguage, String
expectedCountry,
+            String expectedVariant)
+    {
+        assertEquals(l.getLanguage(), expectedLanguage);
+        assertEquals(l.getCountry(), expectedCountry);
+        assertEquals(l.getVariant(), expectedVariant);
+    }
+
+    @Test
+    public void to_locale()
+    {
+        LocalizationSetterImpl filter = new LocalizationSetterImpl(null,
"en");
+
+        checkLocale(filter.toLocale("en"), "en", "", "");
+        checkLocale(filter.toLocale("klingon_Gach"), "klingon", "GACH",
"");
+        checkLocale(filter.toLocale("klingon_Gach_snuff"), "klingon",
"GACH", "snuff");
+    }
+
+    @Test
+    public void known_locale()
+    {
+        ThreadLocale threadLocale = new ThreadLocaleImpl();
+        threadLocale.setLocale(Locale.FRENCH);
+        LocalizationSetter setter = new
LocalizationSetterImpl(threadLocale, "en,fr");
+        setter.setThreadLocale(Locale.CANADA_FRENCH);
+        assertEquals(threadLocale.getLocale(), Locale.FRENCH);
+
+    }
+
+    @Test
+    public void unknown_locale_uses_default_locale()
+    {
+        ThreadLocale threadLocale = new ThreadLocaleImpl();
+        threadLocale.setLocale(Locale.FRENCH);
+        LocalizationSetter setter = new
LocalizationSetterImpl(threadLocale, "en,fr");
+        setter.setThreadLocale(Locale.JAPANESE);
+        assertEquals(threadLocale.getLocale(), Locale.ENGLISH);
+    }
+
+}

Propchange:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForIf.html
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForIf.html?view=diff&rev=488996&r1=488995&r2=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForIf.html
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForIf.html
Wed Dec 20 01:29:16 2006
@@ -11,4 +11,4 @@
<t:comp type="If" test="property2">
        <p id="4">222.</p>
</t:comp>
-</html>
\ No newline at end of file
+</html>

Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html?view=auto&rev=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html
Wed Dec 20 01:29:16 2006
@@ -0,0 +1,3 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+<p id="id1">English page</p>
+</html>
\ No newline at end of file

Propchange:
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale_fr.html
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale_fr.html?view=auto&rev=488996
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale_fr.html
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale_fr.html
Wed Dec 20 01:29:16 2006
@@ -0,0 +1,3 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+<p id="id1">French page</p>
+</html>
\ No newline at end of file

Propchange:
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale_fr.html
------------------------------------------------------------------------------
    svn:eol-style = native




-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

Re: PageTester / InAppInvocation / Link / LinkImpl

Posted by Kent Tong <ke...@cpttm.org.mo>.
Howard Lewis Ship <hlship <at> gmail.com> writes:

> However, I'm troubled by the necessity to cast from Link to LinkImpl, and
> the need for different components to know about the InAppInvocationMap.
> 
> How about if we invert things; have components pass themselves to
> LinkFactory and let LinkFactory deal with the InAppInvocationMap?  You may
> be able to get rid of some methods from LinkImpl as well.

Thanks for the suggestion. Done.

Now the createLink() methods in LinkFactory takes an extra parameter:
the Element so that it can map it to the invocation object it's going 
to create. 

I am not entirely happy with this though as it seems pointless for
the caller (why need the Element?). An alternative approach is to
let MarkupWriterImpl accepts a Link object like:

   Link link = linkFactory.createLink(...);
   writer.element("a", "href", link, ...);

Then it will associate the invocation object with the element. What do
you think?

> ... and Kent, I think you're seeing how hard it is to name things well 
> 
> I'm thinking that an InAppInvocation may actually be a kind of Entrypoint
> that may be referenced from the client.  Which is to say, any URL that the
> client can send to the server and get a response from represents an
> Entrypoint.  Different Entrypoints represent different Application
> Behaviors.  Perhaps Behavior is also a better term for InAppInvocation?
> Just some naming brainstorming!

As InAppInvocation contains query parameters, in my view it is more an
invocation (a call) than an entry point (a callee). What I hate is
the part of "InApp". An alternative is ComponentInvocation as this is
what it is concerned with (components or pages).




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org