From ac7ace224a93c7817c9249fa13980ce5f0630e5c Mon Sep 17 00:00:00 2001 From: TatoniMatteo Date: Thu, 16 Jul 2026 12:48:26 +0200 Subject: [PATCH 1/2] [SYNCOPE-1984] - Fix problems and add unit test --- .../enduser/layout/UserFormLayouts.java | 14 ++--- .../client/enduser/UserFormaLayoutTest.java | 62 +++++++++++++++++++ 2 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/UserFormaLayoutTest.java 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 3a00e4ba07e..9b4c3c600dd 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,19 +43,13 @@ public Map getLayouts() { } public UserFormLayoutInfo getLayout(final String realm) { - if (!StringUtils.isBlank(realm)) { - UserFormLayoutInfo layout = layouts.get(realm); - if (layout != null) { - return layout; - } - - String current = StringUtils.substringBeforeLast(realm, "/"); - while (!SyncopeConstants.ROOT_REALM.equals(current)) { - layout = layouts.get(current); + if (StringUtils.isNotBlank(realm)) { + String current = realm; + while (StringUtils.isNotBlank(current)) { + UserFormLayoutInfo layout = layouts.get(current); if (layout != null) { return layout; } - current = StringUtils.substringBeforeLast(current, "/"); } } diff --git a/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/UserFormaLayoutTest.java b/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/UserFormaLayoutTest.java new file mode 100644 index 00000000000..b6dcd9b45fd --- /dev/null +++ b/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/UserFormaLayoutTest.java @@ -0,0 +1,62 @@ +package org.apache.syncope.client.enduser; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +import java.util.Map; +import org.apache.syncope.client.enduser.layout.UserFormLayoutInfo; +import org.apache.syncope.client.enduser.layout.UserFormLayouts; +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("/")); + } +} From ff1fd13961588395dacd969959d8617b20fa146a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Thu, 16 Jul 2026 13:00:01 +0200 Subject: [PATCH 2/2] Missing license header + cleanup the loop --- .../enduser/layout/UserFormLayouts.java | 15 ++++++------- .../{ => layout}/UserFormaLayoutTest.java | 22 ++++++++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-) rename client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/{ => layout}/UserFormaLayoutTest.java (73%) 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 9b4c3c600dd..69bb4649cb6 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,14 +43,13 @@ public Map getLayouts() { } public UserFormLayoutInfo getLayout(final String realm) { - if (StringUtils.isNotBlank(realm)) { - String current = realm; - while (StringUtils.isNotBlank(current)) { - UserFormLayoutInfo layout = layouts.get(current); - if (layout != null) { - return layout; - } - current = StringUtils.substringBeforeLast(current, "/"); + 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; } } return layouts.get(SyncopeConstants.ROOT_REALM); diff --git a/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/UserFormaLayoutTest.java b/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/layout/UserFormaLayoutTest.java similarity index 73% rename from client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/UserFormaLayoutTest.java rename to client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/layout/UserFormaLayoutTest.java index b6dcd9b45fd..6f8bfbb6128 100644 --- a/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/UserFormaLayoutTest.java +++ b/client/idrepo/enduser/src/test/java/org/apache/syncope/client/enduser/layout/UserFormaLayoutTest.java @@ -1,11 +1,27 @@ -package org.apache.syncope.client.enduser; +/* + * 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.client.enduser.layout.UserFormLayoutInfo; -import org.apache.syncope.client.enduser.layout.UserFormLayouts; import org.apache.syncope.common.lib.SyncopeConstants; import org.junit.jupiter.api.Test;