This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new 8a1e1f48cd [SYNCOPE-1984] Fix problems and add unit test (#1459)
8a1e1f48cd is described below

commit 8a1e1f48cdd6deed08de2926d21bac760aedcb74
Author: Matteo Tatoni <[email protected]>
AuthorDate: Thu Jul 16 13:44:55 2026 +0200

    [SYNCOPE-1984] Fix problems and add unit test (#1459)
---
 .../client/enduser/layout/UserFormLayouts.java     | 17 ++---
 .../client/enduser/layout/UserFormaLayoutTest.java | 78 ++++++++++++++++++++++
 2 files changed, 83 insertions(+), 12 deletions(-)

diff --git 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/layout/UserFormLayouts.java
 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/layout/UserFormLayouts.java
index 3a00e4ba07..69bb4649cb 100644
--- 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/layout/UserFormLayouts.java
+++ 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/layout/UserFormLayouts.java
@@ -43,21 +43,14 @@ public class UserFormLayouts implements Serializable {
     }
 
     public UserFormLayoutInfo getLayout(final String realm) {
-        if (!StringUtils.isBlank(realm)) {
-            UserFormLayoutInfo layout = layouts.get(realm);
+        for (String current = StringUtils.isBlank(realm) ? 
SyncopeConstants.ROOT_REALM : realm;
+                StringUtils.isNotBlank(current);
+                current = StringUtils.substringBeforeLast(current, "/")) {
+
+            UserFormLayoutInfo layout = layouts.get(current);
             if (layout != null) {
                 return layout;
             }
-
-            String current = StringUtils.substringBeforeLast(realm, "/");
-            while (!SyncopeConstants.ROOT_REALM.equals(current)) {
-                layout = layouts.get(current);
-                if (layout != null) {
-                    return layout;
-                }
-
-                current = StringUtils.substringBeforeLast(current, "/");
-            }
         }
         return layouts.get(SyncopeConstants.ROOT_REALM);
     }
diff --git 
a/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/layout/UserFormaLayoutTest.java
 
b/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/layout/UserFormaLayoutTest.java
new file mode 100644
index 0000000000..6f8bfbb612
--- /dev/null
+++ 
b/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/layout/UserFormaLayoutTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.syncope.client.enduser.layout;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+import java.util.Map;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.junit.jupiter.api.Test;
+
+class UserFormLayoutsTest {
+
+    @Test
+    void shouldReturnExactRealmLayout() {
+        UserFormLayoutInfo customLayout = new UserFormLayoutInfo();
+        UserFormLayouts userFormLayouts = new UserFormLayouts(Map.of("/even", 
customLayout));
+        assertSame(customLayout, userFormLayouts.getLayout("/even"));
+    }
+
+    @Test
+    void shouldReturnParentRealmLayout() {
+        UserFormLayoutInfo customLayout = new UserFormLayoutInfo();
+        UserFormLayouts userFormLayouts = new UserFormLayouts(Map.of("/even", 
customLayout));
+        assertSame(customLayout, userFormLayouts.getLayout("/even/two"));
+    }
+
+    @Test
+    void shouldReturnRootRealmLayoutWhenNoParentExists() {
+        UserFormLayouts userFormLayouts = new UserFormLayouts(Map.of());
+        UserFormLayoutInfo rootLayout = 
userFormLayouts.getLayouts().get(SyncopeConstants.ROOT_REALM);
+        assertNotNull(rootLayout);
+        assertSame(rootLayout, userFormLayouts.getLayout("/odd"));
+    }
+
+    @Test
+    void shouldReturnCustomRootRealmLayout() {
+        UserFormLayoutInfo customLayout = new UserFormLayoutInfo();
+        UserFormLayouts userFormLayouts = new 
UserFormLayouts(Map.of(SyncopeConstants.ROOT_REALM, customLayout));
+        assertSame(customLayout, userFormLayouts.getLayout("/odd"));
+    }
+
+    @Test
+    void shouldNotLoopWhenRealmDoesNotExist() {
+        UserFormLayouts userFormLayouts = new UserFormLayouts(Map.of());
+        assertNotNull(userFormLayouts.getLayout("/unknown"));
+    }
+
+    @Test
+    void shouldReturnCustomLayoutForRealm() {
+        UserFormLayoutInfo customLayout = new UserFormLayoutInfo();
+        UserFormLayouts userFormLayouts = new UserFormLayouts(Map.of("/even", 
customLayout));
+        assertSame(customLayout, userFormLayouts.getLayout("/even"));
+    }
+
+    @Test
+    void shouldKeepCustomRootRealmLayout() {
+        UserFormLayoutInfo customLayout = new UserFormLayoutInfo();
+        UserFormLayouts userFormLayouts = new 
UserFormLayouts(Map.of(SyncopeConstants.ROOT_REALM, customLayout));
+        assertSame(customLayout, userFormLayouts.getLayout("/"));
+    }
+}

Reply via email to