Author: hlship
Date: Thu Oct 30 13:09:25 2008
New Revision: 709233
URL: http://svn.apache.org/viewvc?rev=709233&view=rev
Log:
TAP5-318: Tapestry should identify where in the template undefined components
(with id, but no type or matching embedded component) are located
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateParserImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElement.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/model/ComponentModel.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageLinkContext.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageLoaderImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/ComponentPageElementImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java
Thu Oct 30 13:09:25 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 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.
@@ -14,10 +14,11 @@
package org.apache.tapestry5.internal.parser;
+import org.apache.tapestry5.ioc.Location;
import org.apache.tapestry5.ioc.Resource;
import java.util.List;
-import java.util.Set;
+import java.util.Map;
/**
* A parsed component template, containing all the tokens parsed from the
template.
@@ -40,8 +41,11 @@
List<TemplateToken> getTokens();
/**
- * Returns a set of strings corresponding to [EMAIL PROTECTED]
org.apache.tapestry5.internal.parser.StartComponentToken}s
- * within the template that have a non-blank id attribute.
+ * Identifies [EMAIL PROTECTED]
org.apache.tapestry5.internal.parser.StartComponentToken}s with a non-blank id,
mapping the
+ * id to its location (within the template). This is used to report
unmatched ids (where the component, or its
+ * super-classes, do not define an embedded component).
+ *
+ * @see org.apache.tapestry5.annotations.Component (used to define an
embedded component)
*/
- Set<String> getComponentIds();
+ Map<String, Location> getComponentIds();
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java
Thu Oct 30 13:09:25 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 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.
@@ -14,12 +14,13 @@
package org.apache.tapestry5.internal.parser;
+import org.apache.tapestry5.ioc.Location;
import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newSet;
import java.util.List;
-import java.util.Set;
+import java.util.Map;
public class ComponentTemplateImpl implements ComponentTemplate
{
@@ -27,7 +28,7 @@
private final List<TemplateToken> tokens;
- private final Set<String> componentIds;
+ private final Map<String, Location> componentIds;
/**
* @param resource the resource from which the template was parsed
@@ -35,11 +36,11 @@
* @param componentIds ids of components defined in the template
*/
public ComponentTemplateImpl(Resource resource, List<TemplateToken> tokens,
- Set<String> componentIds)
+ Map<String, Location> componentIds)
{
this.resource = resource;
this.tokens = newList(tokens);
- this.componentIds = newSet(componentIds);
+ this.componentIds = CollectionFactory.newMap(componentIds);
}
public Resource getResource()
@@ -52,7 +53,7 @@
return tokens;
}
- public Set<String> getComponentIds()
+ public Map<String, Location> getComponentIds()
{
return componentIds;
}
@@ -64,5 +65,4 @@
{
return false;
}
-
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
Thu Oct 30 13:09:25 2008
@@ -21,6 +21,7 @@
import org.apache.tapestry5.internal.parser.TemplateToken;
import org.apache.tapestry5.internal.util.MultiKey;
import org.apache.tapestry5.internal.util.URLChangeTracker;
+import org.apache.tapestry5.ioc.Location;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.model.ComponentModel;
@@ -28,7 +29,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
/**
* Service implementation that manages a cache of parsed component templates.
@@ -56,7 +56,7 @@
private final ComponentTemplate missingTemplate = new ComponentTemplate()
{
- public Set<String> getComponentIds()
+ public Map<String, Location> getComponentIds()
{
return null;
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
Thu Oct 30 13:09:25 2008
@@ -441,24 +441,22 @@
// Pre-allocate ids to avoid later name collisions.
// Don't have a case-insensitive Set, so we'll make due with a Map
- Map<String, Boolean> embeddedIds =
CollectionFactory.newCaseInsensitiveMap();
-
- for (String id : loadingComponentModel.getEmbeddedComponentIds())
- embeddedIds.put(id, true);
+ Map<String, Boolean> embeddedIds =
collectedEmbeddedComponentIds(loadingComponentModel);
idAllocator.clear();
- for (String id : template.getComponentIds())
+ final Map<String, Location> componentIdsMap =
template.getComponentIds();
+
+ for (String id : componentIdsMap.keySet())
{
idAllocator.allocateId(id);
embeddedIds.remove(id);
}
if (!embeddedIds.isEmpty())
- throw new TapestryException(
-
ServicesMessages.embeddedComponentsNotInTemplate(embeddedIds.keySet(),
componentClassName),
- loadingElement.getLocation(),
- null);
+ throw new RuntimeException(
+
ServicesMessages.embeddedComponentsNotInTemplate(embeddedIds.keySet(),
componentClassName,
+
template.getResource()));
addAttributesAsComponentBindings = false;
@@ -546,6 +544,23 @@
// as the ComponentTemplate is valid.
}
+ /**
+ * Returns a pseudo-set (a case insensitive map where the values are
always true) for all the embedded component ids
+ * in the component.
+ *
+ * @param componentModel
+ * @return map whose keys are the embedded component ids
+ */
+ private Map<String, Boolean> collectedEmbeddedComponentIds(ComponentModel
componentModel)
+ {
+ Map<String, Boolean> result =
CollectionFactory.newCaseInsensitiveMap();
+
+ for (String id : componentModel.getEmbeddedComponentIds())
+ result.put(id, true);
+
+ return result;
+ }
+
private void cdata(CDATAToken token)
{
final String content = token.getContent();
@@ -624,17 +639,19 @@
// Initial guess: the type from the token (but this may be null in
many cases).
String embeddedType = token.getComponentType();
+ // This may be null for an anonymous component.
String embeddedId = token.getId();
String embeddedComponentClassName = null;
+ final EmbeddedComponentModel embeddedModel = embeddedId == null
+ ? null
+ :
loadingComponentModel.getEmbeddedComponentModel(embeddedId);
+
// We know that if embeddedId is null, embeddedType is not.
if (embeddedId == null) embeddedId = generateEmbeddedId(embeddedType,
idAllocator);
- final EmbeddedComponentModel embeddedModel = loadingComponentModel
- .getEmbeddedComponentModel(embeddedId);
-
if (embeddedModel != null)
{
String modelType = embeddedModel.getComponentType();
@@ -647,7 +664,10 @@
embeddedComponentClassName = embeddedModel.getComponentClassName();
}
- if (InternalUtils.isBlank(embeddedType) &&
InternalUtils.isBlank(embeddedComponentClassName))
+ // We only have the embeddedModel if the embeddedId was specified. If
embeddedType was ommitted
+ // and
+
+ if (InternalUtils.isBlank(embeddedType) && embeddedModel == null)
throw new TapestryException(
ServicesMessages.noTypeForEmbeddedComponent(embeddedId,
loadingComponentModel.getComponentClassName()),
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ServicesMessages.java
Thu Oct 30 13:09:25 2008
@@ -130,10 +130,11 @@
return MESSAGES.format("no-type-for-embedded-component", embeddedId,
componentClassName);
}
- static String embeddedComponentsNotInTemplate(Collection<String> ids,
String componentClassName)
+ static String embeddedComponentsNotInTemplate(Collection<String> ids,
String componentClassName,
+ Resource templateResource)
{
return MESSAGES.format("embedded-components-not-in-template",
InternalUtils.joinSorted(ids),
- componentClassName);
+ componentClassName,
InternalUtils.lastTerm(componentClassName), templateResource);
}
static String bindingSourceFailure(String expression, Throwable cause)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateParserImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateParserImpl.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateParserImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateParserImpl.java
Thu Oct 30 13:09:25 2008
@@ -22,7 +22,6 @@
import org.apache.tapestry5.ioc.annotations.Scope;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.LocationImpl;
import org.apache.tapestry5.ioc.internal.util.TapestryException;
@@ -36,7 +35,6 @@
import java.net.URL;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -100,11 +98,11 @@
* events, we need to accumlate the [EMAIL PROTECTED]
org.apache.tapestry5.internal.parser.DefineNamespacePrefixToken}s ahead
* of time to get the correct ordering in the output tokens list.
*/
- private final List<DefineNamespacePrefixToken> defineNamespaceTokens =
newList();
+ private final List<DefineNamespacePrefixToken> defineNamespaceTokens =
CollectionFactory.newList();
// Non-blank ids from start component elements
- private final Set<String> componentIds = CollectionFactory.newSet();
+ private final Map<String, Location> componentIds =
CollectionFactory.newMap();
// Used to accumulate text provided by the characters() method. Even
contiguous characters may
// be broken up across multiple invocations due to parser internals. We
accumulate those
@@ -532,7 +530,8 @@
* @param namespaceURI the namespace URI for the element (or the empty
string)
* @param elementName the name of the element (to be assigned to the
new token), may be null for a component in
* the Tapestry namespace
- * @param identifiedType the type of the element, usually null, but may be
the component type derived from
+ * @param identifiedType the type of the element, usually null, but may be
the component type derived from elewment
+ * name
*/
private void startPossibleComponent(Attributes attributes, String
namespaceURI, String elementName,
String identifiedType)
@@ -547,7 +546,7 @@
String mixins = null;
int count = attributes.getLength();
Location location = getCurrentLocation();
- List<TemplateToken> attributeTokens = newList();
+ List<TemplateToken> attributeTokens = CollectionFactory.newList();
for (int i = 0; i < count; i++)
{
@@ -614,7 +613,8 @@
tokens.addAll(attributeTokens);
- if (id != null) componentIds.add(id);
+ if (id != null)
+ componentIds.put(id, location);
// TODO: Is there value in having different end elements for
components vs. ordinary
// elements?
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElement.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElement.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElement.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElement.java
Thu Oct 30 13:09:25 2008
@@ -71,12 +71,6 @@
void addBlock(String blockId, Block block);
/**
- * Adds a component to its container. The embedded component's id must be
unique within the container (after the id
- * is converted to lower case).
- */
- void addEmbeddedElement(ComponentPageElement child);
-
- /**
* Adds a mixin.
*
* @param instantiator used to instantiate an instance of the mixin
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
Thu Oct 30 13:09:25 2008
@@ -597,7 +597,7 @@
this(page, null, null, null, instantiator, null, pageResources);
}
- public void addEmbeddedElement(ComponentPageElement child)
+ void addEmbeddedElement(ComponentPageElement child)
{
if (children == null) children =
CollectionFactory.newCaseInsensitiveMap();
@@ -811,12 +811,11 @@
public ComponentPageElement getEmbeddedElement(String embeddedId)
{
- ComponentPageElement embeddedElement = InternalUtils.get(children,
embeddedId
- .toLowerCase());
+ ComponentPageElement embeddedElement = InternalUtils.get(children,
embeddedId);
if (embeddedElement == null)
{
- Set<String> ids = children == null ? null : children.keySet();
+ Set<String> ids = InternalUtils.keys(children);
throw new
TapestryException(StructureMessages.noSuchComponent(this, embeddedId, ids),
this, null);
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/model/ComponentModel.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/model/ComponentModel.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/model/ComponentModel.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/model/ComponentModel.java
Thu Oct 30 13:09:25 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -27,7 +27,7 @@
* component model is immutable. During <em>construction</em> time, when the
class is being transformed and loaded, the
* model is mutable.
*
- * @see MutableComponentModel
+ * @see org.apache.tapestry5.model.MutableComponentModel
*/
public interface ComponentModel
{
@@ -44,12 +44,12 @@
/**
* Returns the ids of all embedded components defined within the component
class (via the [EMAIL PROTECTED]
- * org.apache.tapestry5.annotations.Component} annotation).
+ * org.apache.tapestry5.annotations.Component} annotation), including
those defined by any super-class.
*/
List<String> getEmbeddedComponentIds();
/**
- * Returns an embedded component.
+ * Returns an embedded component defined by this component or by a
super-class.
*
* @param componentId the id of the embedded component
* @return the embedded component model, or null if no component exists
with that id
@@ -67,6 +67,8 @@
/**
* Returns object that will be used to log warnings and errors related to
this component.
+ *
+ * @see org.apache.tapestry5.annotations.Log
*/
Logger getLogger();
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/services/ServicesStrings.properties
Thu Oct 30 13:09:25 2008
@@ -37,7 +37,7 @@
You should not provide a type attribute in the template when defining an
embedded component within the component class.
no-type-for-embedded-component=Embedded component '%s' has no type. You should
specify a type in the component template, \
or define the component inside class %s using the @Component annotation on a
private instance variable.
-embedded-components-not-in-template=Embedded component(s) %s are defined
within component class %s, but are not present in the component template.
+embedded-components-not-in-template=Embedded component(s) %s are defined
within component class %s (or a super-class of %s), but are not present in the
component template (%s).
binding-source-failure=Could not convert '%s' into a component parameter
binding: %s
page-name-unresolved=Unable to resolve class name %s to a logical page name.
context-index-out-of-range=Method %s has more parameters than there are
context values for this component event.
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
Thu Oct 30 13:09:25 2008
@@ -2367,6 +2367,6 @@
start("Components Not In Template Demo");
assertTextPresent(
- "Embedded component(s) form are defined within component class
org.apache.tapestry5.integration.app1.pages.ComponentsNotInTemplateDemo, but
are not present in the component template.");
+ "Embedded component(s) form are defined within component class
org.apache.tapestry5.integration.app1.pages.ComponentsNotInTemplateDemo");
}
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageLinkContext.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageLinkContext.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageLinkContext.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageLinkContext.java
Thu Oct 30 13:09:25 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 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.
@@ -17,14 +17,17 @@
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.ioc.annotations.Inject;
+import java.util.Arrays;
+import java.util.List;
+
public class PageLinkContext
{
@Inject
private ComponentResources resources;
- public Object[] getComputedContext()
+ public List getComputedContext()
{
- return new Object[] { "fred", 7, true };
+ return Arrays.asList("fred", 7, true);
}
public String getUnsafeCharacters()
@@ -39,7 +42,6 @@
Object onActionFromNullContext()
{
- return resources.createPageLink("target", true, new Object[] { null });
+ return resources.createPageLink("target", true, new Object[] {null});
}
-
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageLoaderImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageLoaderImplTest.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageLoaderImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageLoaderImplTest.java
Thu Oct 30 13:09:25 2008
@@ -21,14 +21,16 @@
import org.apache.tapestry5.internal.structure.ComponentPageElement;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import org.apache.tapestry5.ioc.Location;
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.TapestryException;
import org.apache.tapestry5.model.ComponentModel;
import org.apache.tapestry5.model.EmbeddedComponentModel;
import org.apache.tapestry5.services.ComponentClassResolver;
import org.testng.annotations.Test;
-import java.util.Arrays;
import java.util.Locale;
+import java.util.Map;
public class PageLoaderImplTest extends InternalBaseTestCase
{
@@ -50,7 +52,14 @@
ComponentModel model = mockComponentModel();
ComponentTemplate template = mockComponentTemplate();
ComponentClassResolver resolver = mockComponentClassResolver();
- Location l = mockLocation();
+ Location bazLocation = mockLocation();
+ Location biffLocation = mockLocation();
+ Resource r = mockResource();
+
+ Map<String, Location> componentIds = CollectionFactory.newMap();
+
+ componentIds.put("baz", bazLocation);
+ componentIds.put("biff", biffLocation);
train_resolvePageNameToClassName(resolver, LOGICAL_PAGE_NAME,
PAGE_CLASS_NAME);
@@ -67,9 +76,9 @@
train_getEmbeddedIds(model, "foo", "bar", "baz");
- train_getComponentIds(template, "baz", "biff");
+ expect(template.getComponentIds()).andReturn(componentIds);
- train_getLocation(rootElement, l);
+ expect(template.getResource()).andReturn(r);
replay();
@@ -80,11 +89,9 @@
loader.loadPage(LOGICAL_PAGE_NAME, LOCALE);
unreachable();
}
- catch (TapestryException ex)
+ catch (RuntimeException ex)
{
- assertEquals(ex.getMessage(),
ServicesMessages.embeddedComponentsNotInTemplate(Arrays.asList("foo", "bar"),
-
PAGE_CLASS_NAME));
- assertSame(ex.getLocation(), l);
+ assertMessageContains(ex, "bar, foo", PAGE_CLASS_NAME);
}
verify();
@@ -103,6 +110,10 @@
Location l = mockLocation();
ComponentClassResolver resolver = mockComponentClassResolver();
+ Map<String, Location> componentIds = CollectionFactory.newMap();
+
+ componentIds.put("foo", l);
+
train_resolvePageNameToClassName(resolver, LOGICAL_PAGE_NAME,
PAGE_CLASS_NAME);
train_newRootComponentElement(elementFactory, PAGE_CLASS_NAME,
rootElement, LOCALE);
@@ -117,7 +128,7 @@
train_getEmbeddedIds(model, "foo");
- train_getComponentIds(template, "foo");
+ expect(template.getComponentIds()).andReturn(componentIds);
train_getTokens(template, new StartComponentToken(null, "foo", "Fred",
null, l), new EndElementToken(null));
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
Thu Oct 30 13:09:25 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -20,7 +20,7 @@
import org.apache.tapestry5.ioc.Location;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.internal.util.ClasspathResource;
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newSet;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.TapestryException;
import org.apache.tapestry5.test.TapestryTestConstants;
import org.testng.annotations.DataProvider;
@@ -29,7 +29,7 @@
import static java.lang.String.format;
import java.util.Arrays;
import java.util.List;
-import java.util.Set;
+import java.util.Map;
/**
* This is used to test the template parser ... and in some cases, the
underlying behavior of the SAX APIs.
@@ -374,7 +374,7 @@
assertTrue(EndElementToken.class.isInstance(tokens.get(2)));
- assertEquals(template.getComponentIds(), Arrays.asList("fred"));
+ assertEquals(template.getComponentIds().keySet(),
Arrays.asList("fred"));
}
@Test
@@ -470,9 +470,9 @@
{
ComponentTemplate template = parse("component_ids.tml");
- Set<String> ids = template.getComponentIds();
+ Map<String, Location> map = template.getComponentIds();
- assertEquals(ids, newSet(Arrays.asList("bomb", "border", "zebra")));
+ assertEquals(map.keySet(),
CollectionFactory.newSet(Arrays.asList("bomb", "border", "zebra")));
}
@Test
@@ -509,7 +509,6 @@
TextToken t1 = get(tokens, 1);
assertEquals(t1.getText().replaceAll("\\s+", " "), " ${expansions must
be on a single line} ");
-
}
@Test
@@ -612,27 +611,26 @@
{
return new Object[][] {
- { "mixin_requires_id_or_type.tml",
+ {"mixin_requires_id_or_type.tml",
"You may not specify mixins for element <span> because
it does not represent a component (which requires either an id attribute or a
type attribute).",
- 2 },
+ 2},
- { "illegal_nesting_within_body_element.tml", "Element 'xyz' is
nested within a Tapestry body element",
- 2 },
+ {"illegal_nesting_within_body_element.tml", "Element 'xyz' is
nested within a Tapestry body element",
+ 2},
- { "unexpected_attribute_in_parameter_element.tml",
+ {"unexpected_attribute_in_parameter_element.tml",
"Element <parameter> does not support an attribute
named 'grok'. The only allowed attribute name is 'name'.",
- 4 },
+ 4},
- { "name_attribute_of_parameter_element_omitted.tml",
- "The name attribute of the <parameter> element must be
specified.", 4 },
+ {"name_attribute_of_parameter_element_omitted.tml",
+ "The name attribute of the <parameter> element must be
specified.", 4},
- { "name_attribute_of_parameter_element_blank.tml",
- "The name attribute of the <parameter> element must be
specified.", 4 },
+ {"name_attribute_of_parameter_element_blank.tml",
+ "The name attribute of the <parameter> element must be
specified.", 4},
- { "unexpected_attribute_in_block_element.tml",
+ {"unexpected_attribute_in_block_element.tml",
"Element <block> does not support an attribute named
'name'. The only allowed attribute name is 'id'.",
- 3 },
-
+ 3},
};
}
@@ -659,8 +657,8 @@
@DataProvider(name = "doctype_parsed_correctly_data")
public Object[][] doctype_parsed_correctly_data()
{
- return new Object[][] { { "xhtml1_strict_doctype.tml" }, {
"xhtml1_transitional_doctype.tml" },
- { "xhtml1_frameset_doctype.tml" } };
+ return new Object[][] {{"xhtml1_strict_doctype.tml"},
{"xhtml1_transitional_doctype.tml"},
+ {"xhtml1_frameset_doctype.tml"}};
}
@Test(dataProvider = "doctype_parsed_correctly_data")
@@ -677,26 +675,26 @@
{
return new Object[][] {
- { "xhtml1_strict_doctype.tml", "html", "-//W3C//DTD XHTML 1.0
Strict//EN",
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" },
+ {"xhtml1_strict_doctype.tml", "html", "-//W3C//DTD XHTML 1.0
Strict//EN",
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"},
- { "xhtml1_transitional_doctype.tml", "html", "-//W3C//DTD
XHTML 1.0 Transitional//EN",
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" },
+ {"xhtml1_transitional_doctype.tml", "html", "-//W3C//DTD XHTML
1.0 Transitional//EN",
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"},
- { "xhtml1_frameset_doctype.tml", "html", "-//W3C//DTD XHTML
1.0 Frameset//EN",
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"
},
+ {"xhtml1_frameset_doctype.tml", "html", "-//W3C//DTD XHTML 1.0
Frameset//EN",
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"},
- { "html4_strict_doctype.tml", "HTML", "-//W3C//DTD HTML
4.01//EN",
- "http://www.w3.org/TR/html4/strict.dtd" },
+ {"html4_strict_doctype.tml", "HTML", "-//W3C//DTD HTML
4.01//EN",
+ "http://www.w3.org/TR/html4/strict.dtd"},
- { "html4_transitional_doctype.tml", "HTML", "-//W3C//DTD HTML
4.01 Transitional//EN",
- "http://www.w3.org/TR/html4/loose.dtd" },
+ {"html4_transitional_doctype.tml", "HTML", "-//W3C//DTD HTML
4.01 Transitional//EN",
+ "http://www.w3.org/TR/html4/loose.dtd"},
- { "html4_frameset_doctype.tml", "HTML", "-//W3C//DTD HTML 4.01
Frameset//EN",
- "http://www.w3.org/TR/html4/frameset.dtd" },
+ {"html4_frameset_doctype.tml", "HTML", "-//W3C//DTD HTML 4.01
Frameset//EN",
+ "http://www.w3.org/TR/html4/frameset.dtd"},
- { "system_doctype.xml", "foo", null,
-
"src/test/resources/org/apache/tapestry5/internal/services/simple.dtd" } };
+ {"system_doctype.xml", "foo", null,
+
"src/test/resources/org/apache/tapestry5/internal/services/simple.dtd"}};
}
@Test(dataProvider = "doctype_token_added_correctly_data")
@@ -765,7 +763,6 @@
TextToken token2 = get(tokens, 2);
assertEquals(token2.getText(), "\n" + " some text\n" + " ");
-
}
@Test
@@ -782,6 +779,5 @@
TextToken token5 = get(tokens, 5);
assertEquals(token5.getText(), "\nis maintained.\n");
-
}
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/ComponentPageElementImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/ComponentPageElementImplTest.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/ComponentPageElementImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/ComponentPageElementImplTest.java
Thu Oct 30 13:09:25 2008
@@ -400,7 +400,6 @@
Page page = newPage(PAGE_NAME);
Component component = mockComponent();
ComponentModel model = mockComponentModel();
- TypeCoercer coercer = mockTypeCoercer();
Logger logger = mockLogger();
train_getLogger(model, logger);
@@ -410,7 +409,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins,
null);
+ ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins,
null);
cpe.addEmbeddedElement(new ComponentPageElementImpl(page, cpe,
"nested", null, ins2, null, null));
try
@@ -435,7 +434,6 @@
ComponentModel model = mockComponentModel();
ComponentPageElement childElement = mockComponentPageElement();
Component childComponent = mockComponent();
- TypeCoercer coercer = mockTypeCoercer();
Logger logger = mockLogger();
train_getLogger(model, logger);
@@ -447,7 +445,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins,
null);
+ ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins,
null);
cpe.addEmbeddedElement(childElement);
@@ -468,7 +466,6 @@
ComponentModel model = mockComponentModel();
ComponentPageElement child1 = mockComponentPageElement();
ComponentPageElement child2 = mockComponentPageElement();
- TypeCoercer coercer = mockTypeCoercer();
Location l = mockLocation();
Logger logger = mockLogger();
@@ -483,7 +480,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins,
null);
+ ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins,
null);
cpe.addEmbeddedElement(child1);
@@ -566,7 +563,6 @@
}
verify();
-
}
@Test
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java
Thu Oct 30 13:09:25 2008
@@ -28,7 +28,6 @@
import org.apache.tapestry5.ioc.def.ContributionDef;
import org.apache.tapestry5.ioc.def.ModuleDef;
import org.apache.tapestry5.ioc.internal.InternalRegistry;
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newSet;
import org.apache.tapestry5.ioc.internal.util.MessagesImpl;
import org.apache.tapestry5.ioc.services.ClassPropertyAdapter;
import org.apache.tapestry5.ioc.services.PropertyAccess;
@@ -295,11 +294,6 @@
expect(template.getTokens()).andReturn(Arrays.asList(tokens));
}
- protected final void train_getComponentIds(ComponentTemplate template,
String... ids)
- {
-
expect(template.getComponentIds()).andReturn(newSet(Arrays.asList(ids)));
- }
-
protected final void train_getEmbeddedIds(ComponentModel model, String...
ids)
{
expect(model.getEmbeddedComponentIds()).andReturn(Arrays.asList(ids));
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
Thu Oct 30 13:09:25 2008
@@ -440,6 +440,15 @@
return keys;
}
+ public static <K, V> Set<K> keys(Map<K, V> map)
+ {
+ if (map == null)
+ return Collections.emptySet();
+
+ return map.keySet();
+ }
+
+
/**
* Gets a value from a map (which may be null).
*
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java?rev=709233&r1=709232&r2=709233&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
Thu Oct 30 13:09:25 2008
@@ -544,4 +544,21 @@
verify();
}
+
+ @Test
+ public void keys_on_null_is_empty()
+ {
+ assertTrue(InternalUtils.keys(null).isEmpty());
+ }
+
+ @Test
+ public void keys_on_actual_map()
+ {
+ Map<String, Integer> map = CollectionFactory.newMap();
+
+ map.put("frobozz", 41);
+ map.put("gnip", 97);
+
+ assertSame(InternalUtils.keys(map), map.keySet());
+ }
}