adding integration test showing child property injection
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1745233 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index ae51b2a..df91e58 100644
--- a/pom.xml
+++ b/pom.xml
@@ -280,13 +280,13 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.api</artifactId>
- <version>1.2.3-SNAPSHOT</version>
+ <version>1.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
- <version>1.2.7-SNAPSHOT</version>
+ <version>1.2.8</version>
<scope>provided</scope>
</dependency>
<!-- not part of launchpad 7 (see SLING-4710) -->
diff --git a/src/main/java/org/apache/sling/models/it/SimpleTest.java b/src/main/java/org/apache/sling/models/it/SimpleTest.java
index 704e239..72d4386 100644
--- a/src/main/java/org/apache/sling/models/it/SimpleTest.java
+++ b/src/main/java/org/apache/sling/models/it/SimpleTest.java
@@ -42,6 +42,7 @@
private ResourceResolverFactory rrFactory;
private String value;
+ private String childValue;
private ResourceResolver resolver;
private Resource resource;
private Node createdNode;
@@ -49,12 +50,15 @@
@Before
public void setUp() throws Exception {
value = RandomStringUtils.randomAlphanumeric(10);
+ childValue = RandomStringUtils.randomAlphanumeric(10);
- resolver = rrFactory.getAdministrativeResourceResolver(null);
+ resolver = rrFactory.getAdministrativeResourceResolver(null);
Session session = resolver.adaptTo(Session.class);
Node rootNode = session.getRootNode();
createdNode = rootNode.addNode("test_" + RandomStringUtils.randomAlphanumeric(10));
createdNode.setProperty("testProperty", value);
+ Node child = createdNode.addNode("child");
+ child.setProperty("childProperty", childValue);
session.save();
resource = resolver.getResource(createdNode.getPath());
@@ -76,6 +80,7 @@
assertNotNull("Model is null", model);
assertEquals("Test Property is not set correctly", value, model.getTestProperty());
+ assertEquals("Child Test Property is not set correctly", childValue, model.getChildProperty());
assertNotNull("Filters is null", model.getFilters());
assertSame("Adaptable is not injected", resource, model.getResource());
}
diff --git a/src/main/java/org/apache/sling/models/it/models/FieldInjectionTestModel.java b/src/main/java/org/apache/sling/models/it/models/FieldInjectionTestModel.java
index c5c39d5..8b47086 100644
--- a/src/main/java/org/apache/sling/models/it/models/FieldInjectionTestModel.java
+++ b/src/main/java/org/apache/sling/models/it/models/FieldInjectionTestModel.java
@@ -19,10 +19,13 @@
import java.util.List;
import javax.inject.Inject;
+import javax.inject.Named;
import javax.servlet.Filter;
import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.Optional;
@Model(adaptables=Resource.class)
public class FieldInjectionTestModel {
@@ -30,6 +33,10 @@
@Inject
private String testProperty;
+ @Inject @Optional
+ @Named("child/childProperty")
+ private String childProperty;
+
@Inject
private List<Filter> filters;
@@ -43,6 +50,8 @@
return testProperty;
}
+ public String getChildProperty() { return childProperty; }
+
public List<Filter> getFilters() {
return filters;
}