You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2020/01/09 11:52:56 UTC

[syncope] branch 2_1_X updated: Small cleanup

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

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


The following commit(s) were added to refs/heads/2_1_X by this push:
     new 0ed97c4  Small cleanup
0ed97c4 is described below

commit 0ed97c4e5ebd366e5e6a64ca19b4fa7bbd3208f4
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Thu Jan 9 12:37:52 2020 +0100

    Small cleanup
---
 .../init/ClassPathScanImplementationLookup.java    | 14 +++------
 .../client/console/panels/ConsoleLogPanel.java     | 19 ++++++-------
 .../client/console/rest/AnyTypeRestClient.java     |  2 +-
 .../client/console/rest/LoggerRestClient.java      |  4 +--
 .../client/console/rest/ResourceRestClient.java    |  4 +--
 .../java/pushpull/LDAPPasswordPullActionsTest.java | 33 +++++++++-------------
 6 files changed, 30 insertions(+), 46 deletions(-)

diff --git a/client/console/src/main/java/org/apache/syncope/client/console/init/ClassPathScanImplementationLookup.java b/client/console/src/main/java/org/apache/syncope/client/console/init/ClassPathScanImplementationLookup.java
index ee8e72e..bc8d879 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/init/ClassPathScanImplementationLookup.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/init/ClassPathScanImplementationLookup.java
@@ -23,13 +23,13 @@ import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.syncope.client.console.pages.BaseExtPage;
 import org.apache.syncope.client.console.annotations.BinaryPreview;
 import org.apache.syncope.client.console.annotations.ExtPage;
@@ -210,19 +210,13 @@ public class ClassPathScanImplementationLookup {
         pages = Collections.unmodifiableList(pages);
         previewers = Collections.unmodifiableList(previewers);
 
-        extPages.sort((o1, o2) -> ObjectUtils.compare(
-                o1.getAnnotation(ExtPage.class).priority(),
-                o2.getAnnotation(ExtPage.class).priority()));
+        extPages.sort(Comparator.comparing(o -> o.getAnnotation(ExtPage.class).priority()));
         extPages = Collections.unmodifiableList(extPages);
 
-        extWidgets.sort((o1, o2) -> ObjectUtils.compare(
-                o1.getAnnotation(ExtWidget.class).priority(),
-                o2.getAnnotation(ExtWidget.class).priority()));
+        extWidgets.sort(Comparator.comparing(o -> o.getAnnotation(ExtWidget.class).priority()));
         extWidgets = Collections.unmodifiableList(extWidgets);
 
-        extAlertWidgets.sort((o1, o2) -> ObjectUtils.compare(
-                o1.getAnnotation(ExtWidget.class).priority(),
-                o2.getAnnotation(ExtWidget.class).priority()));
+        extAlertWidgets.sort(Comparator.comparing(o -> o.getAnnotation(ExtWidget.class).priority()));
         extAlertWidgets = Collections.unmodifiableList(extAlertWidgets);
 
         ssoLoginFormPanels = Collections.unmodifiableList(ssoLoginFormPanels);
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/ConsoleLogPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/ConsoleLogPanel.java
index f1e9dc2..b0f7f68 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/ConsoleLogPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/ConsoleLogPanel.java
@@ -20,9 +20,8 @@ package org.apache.syncope.client.console.panels;
 
 import java.io.Serializable;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.LoggerConfig;
@@ -35,22 +34,20 @@ public class ConsoleLogPanel extends AbstractLogsPanel<LoggerTO> {
 
     private static final long serialVersionUID = -9165749229623482717L;
 
-    private static final ConsoleLoggerController CONSOLE_LOGGER_CONTROLLER = new ConsoleLoggerController();
-
     public ConsoleLogPanel(final String id, final PageReference pageReference) {
-        super(id, pageReference, CONSOLE_LOGGER_CONTROLLER.getLoggers());
+        super(id, pageReference, ConsoleLoggerController.getLoggers());
     }
 
     @Override
     protected void update(final LoggerTO loggerTO) {
-        CONSOLE_LOGGER_CONTROLLER.setLogLevel(loggerTO.getKey(), loggerTO.getLevel());
+        ConsoleLoggerController.setLogLevel(loggerTO.getKey(), loggerTO.getLevel());
     }
 
     private static class ConsoleLoggerController implements Serializable {
 
         private static final long serialVersionUID = -1550459341476431714L;
 
-        public List<LoggerTO> getLoggers() {
+        public static List<LoggerTO> getLoggers() {
             LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
 
             List<LoggerTO> result = new ArrayList<>();
@@ -64,14 +61,14 @@ public class ConsoleLogPanel extends AbstractLogsPanel<LoggerTO> {
                     result.add(loggerTO);
                 }
             });
-            Collections.sort(result, (o1, o2) -> ObjectUtils.compare(o1.getKey(), o2.getKey()));
+            result.sort(Comparator.comparing(LoggerTO::getKey));
 
             return result;
         }
 
-        public void setLogLevel(final String name, final LoggerLevel level) {
-            final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
-            final LoggerConfig logConf = SyncopeConstants.ROOT_LOGGER.equals(name)
+        public static void setLogLevel(final String name, final LoggerLevel level) {
+            LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
+            LoggerConfig logConf = SyncopeConstants.ROOT_LOGGER.equals(name)
                     ? ctx.getConfiguration().getLoggerConfig(LogManager.ROOT_LOGGER_NAME)
                     : ctx.getConfiguration().getLoggerConfig(name);
             logConf.setLevel(level.getLevel());
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/rest/AnyTypeRestClient.java b/client/console/src/main/java/org/apache/syncope/client/console/rest/AnyTypeRestClient.java
index b1e55a6..f4e0ed6 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/rest/AnyTypeRestClient.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/rest/AnyTypeRestClient.java
@@ -54,7 +54,7 @@ public class AnyTypeRestClient extends BaseRestClient {
 
         try {
             types = getService(AnyTypeService.class).list();
-            Collections.sort(types, new AnyTypeComparator());
+            types.sort(COMPARATOR);
         } catch (SyncopeClientException e) {
             LOG.error("While reading all any types", e);
         }
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java b/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
index 212cede..445f7b3 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
@@ -20,13 +20,13 @@ package org.apache.syncope.client.console.rest;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.syncope.common.lib.log.EventCategory;
 import org.apache.syncope.common.lib.log.LogAppender;
 import org.apache.syncope.common.lib.log.LogStatement;
@@ -59,7 +59,7 @@ public class LoggerRestClient extends BaseRestClient {
 
     public List<LoggerTO> listLogs() {
         List<LoggerTO> logs = getService(LoggerService.class).list(LoggerType.LOG);
-        Collections.sort(logs, (o1, o2) -> ObjectUtils.compare(o1.getKey(), o2.getKey()));
+        logs.sort(Comparator.comparing(LoggerTO::getKey));
 
         return logs;
     }
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/rest/ResourceRestClient.java b/client/console/src/main/java/org/apache/syncope/client/console/rest/ResourceRestClient.java
index eefd6ad..a90911f 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/rest/ResourceRestClient.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/rest/ResourceRestClient.java
@@ -20,9 +20,9 @@ package org.apache.syncope.client.console.rest;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.to.ConnObjectTO;
 import org.apache.syncope.common.lib.to.PagedConnObjectTOResult;
@@ -88,7 +88,7 @@ public class ResourceRestClient extends BaseRestClient {
         List<ResourceTO> resources = Collections.emptyList();
         try {
             resources = getService(ResourceService.class).list();
-            Collections.sort(resources, (o1, o2) -> ObjectUtils.compare(o1.getKey(), o2.getKey()));
+            resources.sort(Comparator.comparing(ResourceTO::getKey));
         } catch (Exception e) {
             LOG.error("Could not fetch the Resource list", e);
         }
diff --git a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/LDAPPasswordPullActionsTest.java b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/LDAPPasswordPullActionsTest.java
index 31f2d0e..5754603 100644
--- a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/LDAPPasswordPullActionsTest.java
+++ b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/LDAPPasswordPullActionsTest.java
@@ -25,10 +25,8 @@ import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.when;
 import static org.mockito.Mockito.verify;
 
-import org.apache.syncope.common.lib.patch.AnyPatch;
 import org.apache.syncope.common.lib.patch.PasswordPatch;
 import org.apache.syncope.common.lib.patch.UserPatch;
-import org.apache.syncope.common.lib.to.EntityTO;
 import org.apache.syncope.common.lib.to.ProvisioningReport;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.lib.types.CipherAlgorithm;
@@ -53,9 +51,6 @@ public class LDAPPasswordPullActionsTest extends AbstractTest {
     private ProvisioningProfile<?, ?> profile;
 
     @Mock
-    private AnyPatch anyPatch;
-
-    @Mock
     private UserDAO userDAO;
 
     @Mock
@@ -64,7 +59,9 @@ public class LDAPPasswordPullActionsTest extends AbstractTest {
     @InjectMocks
     private LDAPPasswordPullActions ldapPasswordPullActions;
 
-    private EntityTO entity;
+    private UserTO userTO;
+
+    private UserPatch userPatch;
 
     private String encodedPassword;
 
@@ -72,7 +69,7 @@ public class LDAPPasswordPullActionsTest extends AbstractTest {
 
     @BeforeEach
     public void initTest() {
-        entity = new UserTO();
+        userTO = new UserTO();
         encodedPassword = "s3cureP4ssw0rd";
         cipher = CipherAlgorithm.SHA512;
 
@@ -84,9 +81,9 @@ public class LDAPPasswordPullActionsTest extends AbstractTest {
     public void beforeProvision() throws JobExecutionException {
         String digest = "SHA256";
         String password = "t3stPassw0rd";
-        ReflectionTestUtils.setField(entity, "password", String.format("{%s}%s", digest, password));
+        userTO.setPassword(String.format("{%s}%s", digest, password));
 
-        ldapPasswordPullActions.beforeProvision(profile, syncDelta, entity);
+        ldapPasswordPullActions.beforeProvision(profile, syncDelta, userTO);
 
         assertEquals(CipherAlgorithm.valueOf(digest), ReflectionTestUtils.getField(ldapPasswordPullActions, "cipher"));
         assertEquals(password, ReflectionTestUtils.getField(ldapPasswordPullActions, "encodedPassword"));
@@ -94,23 +91,19 @@ public class LDAPPasswordPullActionsTest extends AbstractTest {
 
     @Test
     public void beforeUpdate() throws JobExecutionException {
-        anyPatch = new UserPatch();
-        PasswordPatch passwordPatch = new PasswordPatch();
-        String digest = "MD5";
-        String password = "an0therTestP4ss";
-        ReflectionTestUtils.setField(passwordPatch, "value", String.format("{%s}%s", digest, password));
-        ReflectionTestUtils.setField(anyPatch, "password", passwordPatch);
+        userPatch = new UserPatch();
+        userPatch.setPassword(new PasswordPatch.Builder().value("{MD5}an0therTestP4ss").build());
 
-        ldapPasswordPullActions.beforeUpdate(profile, syncDelta, entity, anyPatch);
+        ldapPasswordPullActions.beforeUpdate(profile, syncDelta, userTO, userPatch);
 
         assertNull(ReflectionTestUtils.getField(ldapPasswordPullActions, "encodedPassword"));
     }
 
     @Test
     public void afterWithNullUser() throws JobExecutionException {
-        when(userDAO.find(entity.getKey())).thenReturn(null);
+        when(userDAO.find(userTO.getKey())).thenReturn(null);
 
-        ldapPasswordPullActions.after(profile, syncDelta, entity, result);
+        ldapPasswordPullActions.after(profile, syncDelta, userTO, result);
 
         assertNull(ReflectionTestUtils.getField(ldapPasswordPullActions, "encodedPassword"));
         assertNull(ReflectionTestUtils.getField(ldapPasswordPullActions, "cipher"));
@@ -118,9 +111,9 @@ public class LDAPPasswordPullActionsTest extends AbstractTest {
 
     @Test
     public void after(@Mock User user) throws JobExecutionException {
-        when(userDAO.find(entity.getKey())).thenReturn(user);
+        when(userDAO.find(userTO.getKey())).thenReturn(user);
 
-        ldapPasswordPullActions.after(profile, syncDelta, entity, result);
+        ldapPasswordPullActions.after(profile, syncDelta, userTO, result);
 
         verify(user).setEncodedPassword(anyString(), any(CipherAlgorithm.class));
         assertNull(ReflectionTestUtils.getField(ldapPasswordPullActions, "encodedPassword"));