You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2025/09/24 15:55:15 UTC
(sling-org-apache-sling-servlets-post) 01/01: SLING-12944 Add failing IT
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch bugfix/SLING-12944-support-non-jcr-properties
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-post.git
commit 9eedc0bb76bc0ff40731319c90810c25da3dc307
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Sep 24 17:54:07 2025 +0200
SLING-12944 Add failing IT
---
pom.xml | 66 +++++++++++-
.../post/impl/operations/ModifyOperationIT.java | 120 +++++++++++++++++++++
2 files changed, 184 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 93f053d..6881d30 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,6 +66,11 @@
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.jetbrains</groupId>
+ <artifactId>annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@@ -144,8 +149,20 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.testing</artifactId>
- <version>2.1.2</version>
+ <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>
+ <!-- older version not runnable with Java 14+-->
+ <version>4.0.0-1.62.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
+ <version>3.5.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -166,6 +183,25 @@
<version>2.0.1</version>
<scope>test</scope>
</dependency>
+ <!-- only transitively used by sling-mock but otherwise downgraded due to nearest first strategy and commons.testing using an ancient version-->
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.api</artifactId>
+ <version>2.4.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-jackrabbit-api</artifactId>
+ <version>1.62.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.testing</artifactId>
+ <version>2.1.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -224,6 +260,32 @@
<excludePackageNames>org.apache.sling.servlets.post.impl</excludePackageNames>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <classpathDependencyExcludes>
+ <!-- use newer jackrabbit-oak-api instead of jackrabbit-api to be compliant with Oak 1.62.0 (which works on Java14+)-->
+ <classpathDependencyExclude>*:jackrabbit-api</classpathDependencyExclude>
+ <!-- use newer jackrabbit-jcr-commons required for Oak 1.62.0 -->
+ <classpathDependencyExclude>*:jackrabbit-jcr-commons</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ <additionalClasspathDependencies>
+ <additionalClasspathDependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-commons</artifactId>
+ <version>2.20.9</version>
+ </additionalClasspathDependency>
+ </additionalClasspathDependencies>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
diff --git a/src/test/java/org/apache/sling/servlets/post/impl/operations/ModifyOperationIT.java b/src/test/java/org/apache/sling/servlets/post/impl/operations/ModifyOperationIT.java
new file mode 100644
index 0000000..11d1922
--- /dev/null
+++ b/src/test/java/org/apache/sling/servlets/post/impl/operations/ModifyOperationIT.java
@@ -0,0 +1,120 @@
+/*
+ * 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.servlets.post.impl.operations;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.sling.api.SlingJakartaHttpServletRequest;
+import org.apache.sling.api.request.builder.Builders;
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceDecorator;
+import org.apache.sling.api.resource.ResourceWrapper;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.ModifiableValueMapDecorator;
+import org.apache.sling.servlets.post.AbstractJakartaPostResponse;
+import org.apache.sling.servlets.post.JakartaPostResponse;
+import org.apache.sling.servlets.post.Modification;
+import org.apache.sling.servlets.post.exceptions.PreconditionViolatedPersistenceException;
+import org.apache.sling.servlets.post.exceptions.TemporaryPersistenceException;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.jetbrains.annotations.NotNull;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Execute with maven-failsafe-plugin as this requires a slightly patched classpath
+ * to make the test runnable with Java 17+ which requires a newer Oak version than we are supporting with the actual bundle
+ */
+public class ModifyOperationIT {
+
+ @Rule
+ public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+
+ /**
+ * A resource decorator that decorates the resource to add a property "foo" with value "bar"
+ * to the modifiable value map which is not backed by the JCR node.
+ */
+ private static final class TestResourceDecorator implements ResourceDecorator {
+
+ @Override
+ public Resource decorate(@NotNull Resource resource) {
+ return new ResourceWrapper(resource) {
+
+ public @NotNull ModifiableValueMap getModifiableValueMap() {
+ Map<String, Object> properties = new HashMap<>(super.getValueMap());
+ properties.put("foo", "bar");
+ return new ModifiableValueMapDecorator(properties);
+ }
+
+ @Override
+ public @NotNull ValueMap getValueMap() {
+ return getModifiableValueMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <AdapterType> AdapterType adaptTo(@NotNull Class<AdapterType> type) {
+ if (type == ModifiableValueMap.class) {
+ return (AdapterType) getModifiableValueMap();
+ } else if (type == ValueMap.class) {
+ return (AdapterType) getValueMap();
+ }
+ return super.adaptTo(type);
+ }
+ };
+ }
+ }
+
+ @Test
+ public void testModifyingPropertyNotBackedByJcrNode()
+ throws PreconditionViolatedPersistenceException, TemporaryPersistenceException, PersistenceException {
+ ModifyOperation op = new ModifyOperation();
+ Resource resource = context.create().resource("/test", "prop1", "value1");
+ context.registerService(ResourceDecorator.class, new TestResourceDecorator());
+ SlingJakartaHttpServletRequest request = Builders.newRequestBuilder(resource)
+ .withParameter("foo", "bar2")
+ .buildJakartaRequest();
+
+ JakartaPostResponse response = new AbstractJakartaPostResponse() {
+ @Override
+ protected void doSend(HttpServletResponse response) throws IOException {}
+
+ @Override
+ public void onChange(String type, String... arguments) {}
+
+ @Override
+ public String getPath() {
+ return "/test";
+ }
+ };
+ final List<Modification> changes = new java.util.ArrayList<>();
+ op.doRun(request, response, changes);
+
+ assertEquals(1, changes.size());
+ }
+}