joerghoh commented on code in PR #12:
URL: 
https://github.com/apache/sling-org-apache-sling-installer-provider-jcr/pull/12#discussion_r4701378060


##########
src/test/java/org/apache/sling/installer/provider/jcr/impl/JcrHandleUpdateTest.java:
##########
@@ -87,7 +87,7 @@ public void testHandleDeeplyNestedDirectoryPaths() throws 
Exception {
         // Given: Deeply nested configuration paths
         String[] nestedPaths = {
             "/apps/myapp/config/install/" + TEST_CONFIG_NAME + ".config",
-            "/libs/sling/installer/provider/jcr/" + TEST_CONFIG_NAME + 
".config"
+            "/apps/sling/installer/provider/jcr/" + TEST_CONFIG_NAME + 
".config"
         };

Review Comment:
   I don't see why this change is necessary; can we remove it?



##########
src/test/java/org/apache/sling/installer/provider/jcr/impl/JcrHandleUpdateTest.java:
##########
@@ -43,20 +43,20 @@ public class JcrHandleUpdateTest extends JcrInstallTestBase 
{
     private static final String EXPECTED_JSON_EXTENSION = ".cfg.json";
     
     private static final String TEST_CONFIG_NAME = "testConfiguration";
-    private static final String TEST_CONFIG_PATH = "/path/to/" + 
TEST_CONFIG_NAME;
     private static final String APPS_BASE_PATH = "/apps/myapp";
     private static final String LIBS_BASE_PATH = "/libs/sling";
+    private static final String TEST_CONFIG_PATH = APPS_BASE_PATH + "/config/" 
+ TEST_CONFIG_NAME;
 
     /**
      * Tests URL transformation for various configuration file extensions.
      * 
-     * Verifies that different file extensions (.config, .properties, .cfg, 
.xml, .json)
-     * are properly converted to the standardized .cfg.json format.
+     * Verifies that the configuration file extensions supported by the 
installer
+     * (.config, .properties, .cfg) are properly converted to the standardized 
.cfg.json format.
      */
     @Test
     public void testTransformConfigurationFileExtensionsToStandardizedFormat() 
throws Exception {
         // Given: Various configuration file extensions
-        String[] fileExtensions = {".config", ".properties", ".cfg", ".xml", 
".json"};
+        String[] fileExtensions = {".config", ".properties", ".cfg"};

Review Comment:
   Why did you remove the ``.xml`` and ``.json`` extensions here? Are they 
covered elsewhere?



##########
src/test/java/org/apache/sling/installer/provider/jcr/impl/JcrHandleUpdateTest.java:
##########
@@ -158,7 +158,7 @@ public void testHandleVariousConfigurationIdentifiers() 
throws Exception {
             );
             
             // Then: URL should be transformed correctly
-            String expectedUrl = JCR_INSTALL_SCHEME + "/path/to/" + identifier 
+ EXPECTED_JSON_EXTENSION;
+            String expectedUrl = JCR_INSTALL_SCHEME + APPS_BASE_PATH + 
"/config/" + identifier + EXPECTED_JSON_EXTENSION;

Review Comment:
   same as above



##########
src/test/java/org/apache/sling/installer/provider/jcr/impl/JcrHandleUpdateTest.java:
##########
@@ -192,31 +192,95 @@ public void 
testProcessConfigurationUpdatesWithDataPayload() throws Exception {
     }
 
     /**
-     * Tests URL transformation for different root path priorities.
-     * 
-     * Validates that configuration updates in different root paths
-     * (/apps, /libs) are handled consistently.
+     * Tests that configurations from a lower priority root path (/libs) are
+     * written back below the root path with the highest priority (/apps).
      */
     @Test
-    public void testHandleDifferentRootPathPriorities() throws Exception {
-        // Given: Different root paths with varying priorities
-        String[] rootPaths = {APPS_BASE_PATH, LIBS_BASE_PATH};
-        
-        for (String rootPath : rootPaths) {
-            // When: Handling update in different root path
-            String originalUrl = JCR_INSTALL_SCHEME + rootPath + "/" + 
TEST_CONFIG_NAME + ".config";
+    public void testWriteBackToRootPathWithHighestPriority() throws Exception {
+        String originalUrl = JCR_INSTALL_SCHEME + LIBS_BASE_PATH + "/config/" 
+ TEST_CONFIG_NAME + ".config";
+        UpdateResult updateResult = installer.handleUpdate(
+            CONFIG_RESOURCE_TYPE,
+            TEST_CONFIG_NAME,
+            originalUrl,
+            new Hashtable<>(),
+            null
+        );
+
+        assertEquals(JCR_INSTALL_SCHEME + "/apps/sling/config/" + 
TEST_CONFIG_NAME + EXPECTED_JSON_EXTENSION,
+                updateResult.getURL());
+    }
+
+    /**
+     * Tests that the extension is removed from the re-rooted path, even if the
+     * original root path has a different length than the highest priority 
root path.
+     */
+    @Test
+    public void testWriteBackFromRootPathWithDifferentLength() throws 
Exception {
+        String originalUrl = JCR_INSTALL_SCHEME + 
"/custom/myapp/config/org.example.MyService.config";
+        UpdateResult updateResult = installer.handleUpdate(
+            CONFIG_RESOURCE_TYPE,
+            "org.example.MyService",
+            originalUrl,
+            new Hashtable<>(),
+            null
+        );
+
+        assertEquals(JCR_INSTALL_SCHEME + 
"/apps/myapp/config/org.example.MyService" + EXPECTED_JSON_EXTENSION,
+                updateResult.getURL());
+    }
+
+    /**
+     * Tests that a configuration node named after the PID without any 
extension
+     * (e.g. a node of type sling:OsgiConfig) keeps its full PID on write back.
+     */
+    @Test
+    public void testKeepPidOfConfigurationWithoutExtension() throws Exception {
+        String[] pids = {
+            "com.adobe.granite.csrf.impl.CSRFFilter",

Review Comment:
   please remove these Adobe specific names, there are plenty of names on the 
Sling side to choose from :-)



##########
src/test/java/org/apache/sling/installer/provider/jcr/impl/JcrHandleUpdateTest.java:
##########
@@ -242,7 +306,7 @@ public void testHandleComplexPathsWithMultipleDots() throws 
Exception {
         );
         
         // Then: Only the final extension should be transformed
-        String expectedUrl = JCR_INSTALL_SCHEME + 
"/path/to/my.configName.file" + EXPECTED_JSON_EXTENSION;
+        String expectedUrl = JCR_INSTALL_SCHEME + APPS_BASE_PATH + 
"/config/my.configName.file" + EXPECTED_JSON_EXTENSION;

Review Comment:
   same as above



##########
src/test/java/org/apache/sling/installer/provider/jcr/impl/JcrHandleUpdateTest.java:
##########
@@ -148,7 +148,7 @@ public void testHandleVariousConfigurationIdentifiers() 
throws Exception {
         
         for (String identifier : configIdentifiers) {
             // When: Handling update with different identifier
-            String originalUrl = JCR_INSTALL_SCHEME + "/path/to/" + identifier 
+ ".config";
+            String originalUrl = JCR_INSTALL_SCHEME + APPS_BASE_PATH + 
"/config/" + identifier + ".config";

Review Comment:
   is this change relevant for this PR? For general code improvements outside 
of the scope of this particular issue please raise a dedicated PR.



##########
src/test/java/org/apache/sling/installer/provider/jcr/impl/JcrHandleUpdateTest.java:
##########
@@ -192,31 +192,95 @@ public void 
testProcessConfigurationUpdatesWithDataPayload() throws Exception {
     }
 
     /**
-     * Tests URL transformation for different root path priorities.
-     * 
-     * Validates that configuration updates in different root paths
-     * (/apps, /libs) are handled consistently.
+     * Tests that configurations from a lower priority root path (/libs) are
+     * written back below the root path with the highest priority (/apps).
      */
     @Test
-    public void testHandleDifferentRootPathPriorities() throws Exception {

Review Comment:
   the diff here is a bit cumbersome to read, but I did not find this 
particular test ``testHandleDifferentRootPathPriorities()`` anymore. Why was it 
removed? I see that some aspects show up in other testcases, but I miss the 
handling of the ``/libs`` and ``/apps`` paths.



##########
src/test/java/org/apache/sling/installer/provider/jcr/impl/JcrHandleUpdateTest.java:
##########
@@ -229,7 +293,7 @@ public void testHandleDifferentRootPathPriorities() throws 
Exception {
     @Test
     public void testHandleComplexPathsWithMultipleDots() throws Exception {
         // Given: Complex path with multiple dot-separated segments
-        String complexPath = "/path/to/my.configName.file.config";
+        String complexPath = APPS_BASE_PATH + 
"/config/my.configName.file.config";

Review Comment:
   same as above



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to