Author: hlship
Date: Wed Sep 28 20:10:10 2011
New Revision: 1177038
URL: http://svn.apache.org/viewvc?rev=1177038&view=rev
Log:
TAP5-1676: When an @InjectComponent annotation fails due to missing component,
it should identify the class name and field for the injection
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PageLoadErrorTests.groovy
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingEmbeddedComponent.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java?rev=1177038&r1=1177037&r2=1177038&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java
Wed Sep 28 20:10:10 2011
@@ -18,6 +18,7 @@ import org.apache.tapestry5.ComponentRes
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.internal.services.ComponentClassCache;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.util.UnknownValueException;
import org.apache.tapestry5.model.MutableComponentModel;
import org.apache.tapestry5.plastic.*;
import org.apache.tapestry5.runtime.Component;
@@ -62,7 +63,14 @@ public class InjectComponentWorker imple
private void load()
{
- embedded = resources.getEmbeddedComponent(componentId);
+ try
+ {
+ embedded = resources.getEmbeddedComponent(componentId);
+ } catch (UnknownValueException ex)
+ {
+ throw new RuntimeException(String.format("Unable to inject
component into field %s of class %s: %s",
+ fieldName, getComponentClassName(), ex.getMessage()),
ex);
+ }
Class fieldType = classCache.forName(type);
@@ -70,9 +78,14 @@ public class InjectComponentWorker imple
throw new RuntimeException(
String
.format(
- "Unable to inject component '%s' into
field %s of component %s. Class %s is not assignable to a field of type %s.",
- componentId, fieldName,
resources.getCompleteId(), embedded.getClass()
- .getName(), fieldType.getName()));
+ "Unable to inject component '%s' into
field %s of %s. Class %s is not assignable to a field of type %s.",
+ componentId, fieldName,
getComponentClassName(),
+ embedded.getClass().getName(),
fieldType.getName()));
+ }
+
+ private String getComponentClassName()
+ {
+ return resources.getComponentModel().getComponentClassName();
}
public Object get(Object instance, InstanceContext context)
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml?rev=1177038&r1=1177037&r2=1177038&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml Wed Sep 28
20:10:10 2011
@@ -194,7 +194,10 @@
<a href="parameterconflictdemo">Parameter Conflict Demo</a> -- checks
for subclass parameters conflicting with
base class parameters
</li>
-
+ <li>
+ <a href="missingembeddedcomponent">Missing Embedded Component</a> --
@InjectComponent for component not in
+ template
+ </li>
</ul>
</html>
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PageLoadErrorTests.groovy
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PageLoadErrorTests.groovy?rev=1177038&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PageLoadErrorTests.groovy
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PageLoadErrorTests.groovy
Wed Sep 28 20:10:10 2011
@@ -0,0 +1,16 @@
+package org.apache.tapestry5.integration.app1
+
+import org.apache.tapestry5.test.SeleniumTestCase
+import org.testng.annotations.Test
+
+class PageLoadErrorTests extends SeleniumTestCase
+{
+
+ @Test
+ void
check_correct_reporting_of_missing_embedded_component_with_InjectComponent()
+ {
+ openLinks "Missing Embedded Component"
+
+ assertTextPresent "Unable to inject component into field missing of
class org.apache.tapestry5.integration.app1.pages.MissingEmbeddedComponent",
"Component MissingEmbeddedComponent does not contain embedded component
'missing'."
+ }
+}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java?rev=1177038&r1=1177037&r2=1177038&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
Wed Sep 28 20:10:10 2011
@@ -171,7 +171,7 @@ public class CoreBehaviorsTests extends
{
openLinks("InjectComponentMismatch");
- assertTextPresent("Unable to inject component 'form' into field form
of component InjectComponentMismatch. Class
org.apache.tapestry5.corelib.components.BeanEditForm is not assignable to a
field of type org.apache.tapestry5.corelib.components.Form.");
+ assertTextPresent("Unable to inject component 'form' into field form
of org.apache.tapestry5.integration.app1.pages.InjectComponentMismatch. Class
org.apache.tapestry5.corelib.components.BeanEditForm is not assignable to a
field of type org.apache.tapestry5.corelib.components.Form.");
}
@Test
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingEmbeddedComponent.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingEmbeddedComponent.java?rev=1177038&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingEmbeddedComponent.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingEmbeddedComponent.java
Wed Sep 28 20:10:10 2011
@@ -0,0 +1,10 @@
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.annotations.InjectComponent;
+import org.apache.tapestry5.corelib.components.TextField;
+
+public class MissingEmbeddedComponent
+{
+ @InjectComponent
+ private TextField missing;
+}