You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2014/06/04 21:38:55 UTC

svn commit: r1600469 [2/2] - in /sling/trunk/bundles/extensions/models: api/src/main/java/org/apache/sling/models/annotations/injectorspecific/ api/src/main/java/org/apache/sling/models/spi/injectorspecific/ impl/ impl/src/main/java/org/apache/sling/mo...

Added: sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java?rev=1600469&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java (added)
+++ sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java Wed Jun  4 19:38:55 2014
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.models.impl;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.apache.sling.models.impl.injectors.BindingsInjector;
+import org.apache.sling.models.impl.injectors.ChildResourceInjector;
+import org.apache.sling.models.impl.injectors.OSGiServiceInjector;
+import org.apache.sling.models.impl.injectors.RequestAttributeInjector;
+import org.apache.sling.models.impl.injectors.ValueMapInjector;
+import org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(MockitoJUnitRunner.class)
+public class InjectorSpecificAnnotationTest {
+
+    @Mock
+    private ComponentContext componentCtx;
+
+    @Mock
+    private BundleContext bundleContext;
+
+    @Mock
+    private SlingHttpServletRequest request;
+
+    @Mock
+    private Logger log;
+
+    private ModelAdapterFactory factory;
+
+    private OSGiServiceInjector osgiInjector;
+
+    @Before
+    public void setup() {
+        when(componentCtx.getBundleContext()).thenReturn(bundleContext);
+        factory = new ModelAdapterFactory();
+        factory.activate(componentCtx);
+
+        osgiInjector = new OSGiServiceInjector();
+        osgiInjector.activate(componentCtx);
+
+        factory.bindInjector(new BindingsInjector(),
+                Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 1L));
+        factory.bindInjector(new ValueMapInjector(),
+                Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 2L));
+        factory.bindInjector(new ChildResourceInjector(),
+                Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 3L));
+        factory.bindInjector(new RequestAttributeInjector(),
+                Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 4L));
+        factory.bindInjector(osgiInjector, Collections.<String, Object> singletonMap(Constants.SERVICE_ID, 5L));
+        SlingBindings bindings = new SlingBindings();
+        bindings.setLog(log);
+        Mockito.when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
+
+    }
+
+    @Test
+    public void testSimpleValueModel() {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("first", "first-value");
+        map.put("second", "second-value");
+        ValueMap vm = new ValueMapDecorator(map);
+
+        Resource res = mock(Resource.class);
+        when(res.adaptTo(ValueMap.class)).thenReturn(vm);
+        when(request.getResource()).thenReturn(res);
+
+        InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
+        assertNotNull("Could not instanciate model", model);
+        assertEquals("first-value", model.getFirst());
+        assertEquals("second-value", model.getSecond());
+    }
+
+    @Test
+    public void testOrderForValueAnnotation() {
+        // make sure that that the correct injection is used
+        // make sure that log is adapted from value map
+        // and not coming from request attribute
+        Logger logFromValueMap = LoggerFactory.getLogger(this.getClass());
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("first", "first-value");
+        map.put("log", logFromValueMap);
+        ValueMap vm = new ValueMapDecorator(map);
+
+        Resource res = mock(Resource.class);
+        when(res.adaptTo(ValueMap.class)).thenReturn(vm);
+        when(request.getResource()).thenReturn(res);
+
+        InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
+        assertNotNull("Could not instanciate model", model);
+        assertEquals("first-value", model.getFirst());
+        assertEquals(logFromValueMap, model.getLog());
+    }
+
+    @Test
+    public void testOSGiService() throws InvalidSyntaxException {
+        ServiceReference ref = mock(ServiceReference.class);
+        Logger log = mock(Logger.class);
+        when(bundleContext.getServiceReferences(Logger.class.getName(), null)).thenReturn(
+                new ServiceReference[] { ref });
+        when(bundleContext.getService(ref)).thenReturn(log);
+
+        InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
+        assertNotNull("Could not instanciate model", model);
+        assertEquals(log, model.getService());
+    }
+
+    @Test
+    public void testScriptVariable() throws InvalidSyntaxException {
+        SlingBindings bindings = new SlingBindings();
+        SlingScriptHelper helper = mock(SlingScriptHelper.class);
+        bindings.setSling(helper);
+        when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
+
+        InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
+        assertNotNull("Could not instanciate model", model);
+        assertEquals(helper, model.getHelper());
+    }
+
+    @Test
+    public void testRequestAttribute() throws InvalidSyntaxException {
+        Object attribute = new Object();
+        when(request.getAttribute("attribute")).thenReturn(attribute);
+
+        InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
+        assertNotNull("Could not instanciate model", model);
+        assertEquals(attribute, model.getRequestAttribute());
+    }
+
+    @Test
+    public void testChildResource() {
+        Resource res = mock(Resource.class);
+        Resource child = mock(Resource.class);
+        when(res.getChild("child1")).thenReturn(child);
+        when(request.getResource()).thenReturn(res);
+
+        InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
+        assertNotNull("Could not instanciate model", model);
+        assertEquals(child, model.getChildResource());
+    }
+}

Modified: sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java?rev=1600469&r1=1600468&r2=1600469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java (original)
+++ sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/MultipleInjectorTest.java Wed Jun  4 19:38:55 2014
@@ -88,6 +88,7 @@ public class MultipleInjectorTest {
         assertEquals(obj.firstAttribute, bindingsValue);
 
         verifyNoMoreInteractions(attributesInjector);
+        verify(bindingsInjector).createAnnotationProcessor(any(), any(AnnotatedElement.class));
         verify(bindingsInjector).getValue(eq(request), eq("firstAttribute"), eq(String.class), any(AnnotatedElement.class), any(DisposalCallbackRegistry.class));
         verifyNoMoreInteractions(bindingsInjector);
     }

Modified: sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/PostConstructTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/PostConstructTest.java?rev=1600469&r1=1600468&r2=1600469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/PostConstructTest.java (original)
+++ sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/PostConstructTest.java Wed Jun  4 19:38:55 2014
@@ -49,7 +49,7 @@ public class PostConstructTest {
         ModelAdapterFactory factory = new ModelAdapterFactory();
         factory.activate(componentCtx);
         // no injectors are necessary
-        
+
         SubClass sc = factory.getAdapter(r, SubClass.class);
         assertTrue(sc.getPostConstructCalledTimestampInSub() > sc.getPostConstructCalledTimestampInSuper());
         assertTrue(sc.getPostConstructCalledTimestampInSuper() > 0);

Added: sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotation.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotation.java?rev=1600469&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotation.java (added)
+++ sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotation.java Wed Jun  4 19:38:55 2014
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.models.impl.injector;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.apache.sling.models.spi.injectorspecific.InjectAnnotation;
+
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+@InjectAnnotation
+public @interface CustomAnnotation {
+
+}

Added: sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotationInjector.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotationInjector.java?rev=1600469&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotationInjector.java (added)
+++ sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/CustomAnnotationInjector.java Wed Jun  4 19:38:55 2014
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.models.impl.injector;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Type;
+
+import org.apache.sling.models.spi.DisposalCallbackRegistry;
+import org.apache.sling.models.spi.injectorspecific.AbstractInjectAnnotationProcessor;
+import org.apache.sling.models.spi.injectorspecific.InjectAnnotationProcessor;
+import org.apache.sling.models.spi.injectorspecific.InjectAnnotationProcessorFactory;
+
+public class CustomAnnotationInjector implements InjectAnnotationProcessorFactory {
+
+    @Override
+    public String getName() {
+        return "with-annotation";
+    }
+
+    @Override
+    public Object getValue(Object adaptable, String name, Type declaredType, AnnotatedElement element,
+            DisposalCallbackRegistry callbackRegistry) {
+        if (name.equals("customString")) {
+            return "custom value";
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public InjectAnnotationProcessor createAnnotationProcessor(Object adaptable, AnnotatedElement element) {
+        if (element.isAnnotationPresent(CustomAnnotation.class)) {
+            return new Processor();
+        } else {
+            return null;
+        }
+    }
+
+    private class Processor extends AbstractInjectAnnotationProcessor {
+
+        @Override
+        public boolean hasDefault() {
+            return true;
+        }
+
+        @Override
+        public Object getDefault() {
+            return "default value";
+        }
+    }
+
+}

Copied: sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/SimpleInjector.java (from r1599279, sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/SimpleInjector.java?p2=sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/SimpleInjector.java&p1=sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java&r1=1599279&r2=1600469&rev=1600469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java (original)
+++ sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/impl/injector/SimpleInjector.java Wed Jun  4 19:38:55 2014
@@ -14,33 +14,26 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.models.impl.injectors;
+package org.apache.sling.models.impl.injector;
 
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Type;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.api.resource.Resource;
 import org.apache.sling.models.spi.DisposalCallbackRegistry;
 import org.apache.sling.models.spi.Injector;
-import org.osgi.framework.Constants;
 
-@Component
-@Service
-@Property(name = Constants.SERVICE_RANKING, intValue = 3000)
-public class ChildResourceInjector implements Injector {
+public class SimpleInjector implements Injector {
 
     @Override
     public String getName() {
-        return "child-resources";
+        return "test";
     }
 
     @Override
-    public Object getValue(Object adaptable, String name, Type declaredType, AnnotatedElement element, DisposalCallbackRegistry callbackRegistry) {
-        if (adaptable instanceof Resource) {
-            return ((Resource) adaptable).getChild(name);
+    public Object getValue(Object adaptable, String name, Type declaredType, AnnotatedElement element,
+            DisposalCallbackRegistry callbackRegistry) {
+        if (name.equals("testString") && declaredType.equals(String.class)) {
+            return "test string";
         } else {
             return null;
         }

Added: sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/testmodels/classes/InjectorSpecificAnnotationModel.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/testmodels/classes/InjectorSpecificAnnotationModel.java?rev=1600469&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/testmodels/classes/InjectorSpecificAnnotationModel.java (added)
+++ sling/trunk/bundles/extensions/models/impl/src/test/java/org/apache/sling/models/testmodels/classes/InjectorSpecificAnnotationModel.java Wed Jun  4 19:38:55 2014
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.models.testmodels.classes;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.injectorspecific.ChildResource;
+import org.apache.sling.models.annotations.injectorspecific.OSGiService;
+import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
+import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
+import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
+import org.slf4j.Logger;
+
+@Model(adaptables = SlingHttpServletRequest.class)
+public class InjectorSpecificAnnotationModel {
+
+    @ValueMapValue(optional = true)
+    private String first;
+
+    @ValueMapValue(name = "second", optional = true)
+    private String secondWithOtherName;
+
+    @ValueMapValue(optional = true)
+    private Logger log;
+
+    @ScriptVariable(optional = true, name = "sling")
+    private SlingScriptHelper helper;
+
+    @RequestAttribute(optional = true, name = "attribute")
+    private Object requestAttribute;
+
+    @OSGiService(optional = true)
+    private Logger service;
+
+    @ChildResource(optional = true, name = "child1")
+    private Resource childResource;
+
+    public String getFirst() {
+        return first;
+    }
+
+    public String getSecond() {
+        return secondWithOtherName;
+    }
+
+    public Logger getLog() {
+        return log;
+    }
+
+    public Logger getService() {
+        return service;
+    }
+
+    public SlingScriptHelper getHelper() {
+        return helper;
+    }
+
+    public Object getRequestAttribute() {
+        return requestAttribute;
+    }
+
+    public Resource getChildResource() {
+        return childResource;
+    }
+
+}

Added: sling/trunk/bundles/extensions/models/integration-tests/src/main/java/org/apache/sling/models/it/InjectorSpecificAnnotationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/integration-tests/src/main/java/org/apache/sling/models/it/InjectorSpecificAnnotationTest.java?rev=1600469&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/models/integration-tests/src/main/java/org/apache/sling/models/it/InjectorSpecificAnnotationTest.java (added)
+++ sling/trunk/bundles/extensions/models/integration-tests/src/main/java/org/apache/sling/models/it/InjectorSpecificAnnotationTest.java Wed Jun  4 19:38:55 2014
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.models.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.sling.api.adapter.AdapterManager;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
+import org.apache.sling.junit.annotations.TestReference;
+import org.apache.sling.models.it.models.SlingPropertyAnnotationTestModel;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SlingAnnotationsTestRunner.class)
+public class InjectorSpecificAnnotationTest {
+
+    @TestReference
+    private ResourceResolverFactory rrFactory;
+
+    @TestReference
+    private AdapterManager adapterManager;
+
+    @Test
+    public void test() throws Exception {
+	String value = RandomStringUtils.randomAlphanumeric(10);
+
+	ResourceResolver resolver = null;
+	Node createdNode = null;
+	try {
+	    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);
+	    session.save();
+
+	    Resource resource = resolver.getResource(createdNode.getPath());
+
+	    SlingPropertyAnnotationTestModel model = resource.adaptTo(SlingPropertyAnnotationTestModel.class);
+
+	    assertNotNull("Model is null", model);
+	    assertEquals("Test Property is not set correctly", value, model.getTestProperty());
+	} finally {
+	    if (createdNode != null) {
+		createdNode.remove();
+	    }
+	    if (resolver != null) {
+		resolver.close();
+	    }
+	}
+    }
+}

Added: sling/trunk/bundles/extensions/models/integration-tests/src/main/java/org/apache/sling/models/it/models/SlingPropertyAnnotationTestModel.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/integration-tests/src/main/java/org/apache/sling/models/it/models/SlingPropertyAnnotationTestModel.java?rev=1600469&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/models/integration-tests/src/main/java/org/apache/sling/models/it/models/SlingPropertyAnnotationTestModel.java (added)
+++ sling/trunk/bundles/extensions/models/integration-tests/src/main/java/org/apache/sling/models/it/models/SlingPropertyAnnotationTestModel.java Wed Jun  4 19:38:55 2014
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.models.it.models;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
+
+@Model(adaptables=Resource.class)
+public class SlingPropertyAnnotationTestModel {
+	
+    @ValueMapValue
+    private String testProperty;
+    
+    public String getTestProperty() {
+        return testProperty;
+    }
+}