jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1483240 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/security/authorization/permission/ main/java/org/apache/jackrabbit/oak/security/user/ main/java/org/apache/jackrabbit/oak/spi/security/ main/java/org/apac...
Date Thu, 16 May 2013 08:29:40 GMT
Author: angela
Date: Thu May 16 08:29:40 2013
New Revision: 1483240

URL: http://svn.apache.org/r1483240
Log:
OAK-50 : Implement User Management  (wip)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModule.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AbstractAuthorizableAction.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AccessControlAction.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/PasswordValidationAction.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/ConfigurationParametersTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java?rev=1483240&r1=1483239&r2=1483240&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java
Thu May 16 08:29:40 2013
@@ -50,8 +50,8 @@ public class PermissionValidatorProvider
         this.securityProvider = securityProvider;
 
         ConfigurationParameters params = securityProvider.getAccessControlConfiguration().getConfigurationParameters();
-        String compatValue = params.getConfigValue(AccessControlConstants.PARAM_PERMISSIONS_JR2,
null);
-        jr2Permissions = Permissions.getPermissions(params.getConfigValue(AccessControlConstants.PARAM_PERMISSIONS_JR2,
compatValue));
+        String compatValue = params.getNullableConfigValue(AccessControlConstants.PARAM_PERMISSIONS_JR2,
null);
+        jr2Permissions = Permissions.getPermissions(compatValue);
     }
 
     //--------------------------------------------------< ValidatorProvider >---

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java?rev=1483240&r1=1483239&r2=1483240&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
Thu May 16 08:29:40 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
@@ -46,6 +44,8 @@ import org.apache.jackrabbit.oak.util.No
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * Creates initial set of users to be present in a given workspace. This
  * implementation uses the {@code UserManager} such as defined by the
@@ -123,7 +123,7 @@ class UserInitializer implements Workspa
             ConfigurationParameters params = userConfiguration.getConfigurationParameters();
             String adminId = params.getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
             if (userManager.getAuthorizable(adminId) == null) {
-                userManager.createUser(adminId, params.getConfigValue(PARAM_ADMIN_PW, adminId));
+                userManager.createUser(adminId, params.getNullableConfigValue(PARAM_ADMIN_PW,
adminId));
             }
             String anonymousId = params.getConfigValue(PARAM_ANONYMOUS_ID, DEFAULT_ANONYMOUS_ID);
             if (userManager.getAuthorizable(anonymousId) == null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java?rev=1483240&r1=1483239&r2=1483240&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java
Thu May 16 08:29:40 2013
@@ -30,9 +30,6 @@ import org.slf4j.LoggerFactory;
  */
 public class ConfigurationParameters {
 
-    /**
-     * logger instance
-     */
     private static final Logger log = LoggerFactory.getLogger(ConfigurationParameters.class);
 
     public static final ConfigurationParameters EMPTY = new ConfigurationParameters();
@@ -81,7 +78,7 @@ public class ConfigurationParameters {
      * @return The original or converted configuration value or {@code null}.
      */
     @CheckForNull
-    public <T> T getConfigValue(@Nonnull String key, @Nullable T defaultValue) {
+    public <T> T getNullableConfigValue(@Nonnull String key, @Nullable T defaultValue)
{
         if (options != null && options.containsKey(key)) {
             return convert(options.get(key), defaultValue);
         } else {
@@ -89,9 +86,19 @@ public class ConfigurationParameters {
         }
     }
 
+    @Nonnull
+    public <T> T getConfigValue(@Nonnull String key, @Nonnull T defaultValue) {
+        if (options != null && options.containsKey(key)) {
+            T value = convert(options.get(key), defaultValue);
+            return (value == null) ? defaultValue : value;
+        } else {
+            return defaultValue;
+        }
+    }
+
     //--------------------------------------------------------< private >---
     @SuppressWarnings("unchecked")
-    @CheckForNull
+    @Nullable
     private static <T> T convert(@Nullable Object configProperty, @Nullable T defaultValue)
{
         if (configProperty == null) {
             return null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModule.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModule.java?rev=1483240&r1=1483239&r2=1483240&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModule.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalLoginModule.java
Thu May 16 08:29:40 2013
@@ -65,7 +65,7 @@ public abstract class ExternalLoginModul
      * @throws SyncException
      */
     protected SyncHandler getSyncHandler() throws SyncException {
-        Object syncHandler = options.getConfigValue(PARAM_SYNC_HANDLER, null);
+        Object syncHandler = options.getNullableConfigValue(PARAM_SYNC_HANDLER, null);
         if (syncHandler == null) {
             return new DefaultSyncHandler();
         } else if (syncHandler instanceof SyncHandler) {
@@ -117,7 +117,7 @@ public abstract class ExternalLoginModul
         try {
             SyncHandler handler = getSyncHandler();
             Root root = getRoot();
-            Object smValue = options.getConfigValue(PARAM_SYNC_MODE, null);
+            Object smValue = options.getNullableConfigValue(PARAM_SYNC_MODE, null);
             SyncMode syncMode;
             if (smValue == null) {
                 syncMode = DEFAULT_SYNC_MODE;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AbstractAuthorizableAction.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AbstractAuthorizableAction.java?rev=1483240&r1=1483239&r2=1483240&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AbstractAuthorizableAction.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AbstractAuthorizableAction.java
Thu May 16 08:29:40 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.spi.security.user.action;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -43,7 +45,7 @@ public abstract class AbstractAuthorizab
      * @see AuthorizableAction#onCreate(org.apache.jackrabbit.api.security.user.Group, org.apache.jackrabbit.oak.api.Root,
org.apache.jackrabbit.oak.namepath.NamePathMapper)
      */
     @Override
-    public void onCreate(Group group, Root root, NamePathMapper namePathMapper) throws RepositoryException
{
+    public void onCreate(@Nonnull Group group, @Nonnull Root root, @Nonnull NamePathMapper
namePathMapper) throws RepositoryException {
         // nothing to do
     }
 
@@ -53,7 +55,7 @@ public abstract class AbstractAuthorizab
      * @see AuthorizableAction#onCreate(org.apache.jackrabbit.api.security.user.User, String,
org.apache.jackrabbit.oak.api.Root, org.apache.jackrabbit.oak.namepath.NamePathMapper)
      */
     @Override
-    public void onCreate(User user, String password, Root root, NamePathMapper namePathMapper)
throws RepositoryException {
+    public void onCreate(@Nonnull User user, @Nullable String password, @Nonnull Root root,
@Nonnull NamePathMapper namePathMapper) throws RepositoryException {
         // nothing to do
     }
 
@@ -63,7 +65,7 @@ public abstract class AbstractAuthorizab
      * @see AuthorizableAction#onRemove(org.apache.jackrabbit.api.security.user.Authorizable,
org.apache.jackrabbit.oak.api.Root, org.apache.jackrabbit.oak.namepath.NamePathMapper)
      */
     @Override
-    public void onRemove(Authorizable authorizable, Root root, NamePathMapper namePathMapper)
throws RepositoryException {
+    public void onRemove(@Nonnull Authorizable authorizable, @Nonnull Root root, @Nonnull
NamePathMapper namePathMapper) throws RepositoryException {
         // nothing to do
     }
 
@@ -73,7 +75,7 @@ public abstract class AbstractAuthorizab
      * @see AuthorizableAction#onPasswordChange(org.apache.jackrabbit.api.security.user.User,
String, org.apache.jackrabbit.oak.api.Root, org.apache.jackrabbit.oak.namepath.NamePathMapper)
      */
     @Override
-    public void onPasswordChange(User user, String newPassword, Root root, NamePathMapper
namePathMapper) throws RepositoryException {
+    public void onPasswordChange(@Nonnull User user, @Nullable String newPassword, @Nonnull
Root root, @Nonnull NamePathMapper namePathMapper) throws RepositoryException {
         // nothing to do
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AccessControlAction.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AccessControlAction.java?rev=1483240&r1=1483239&r2=1483240&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AccessControlAction.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/AccessControlAction.java
Thu May 16 08:29:40 2013
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.oak.spi.se
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.security.AccessControlPolicy;
@@ -109,8 +111,8 @@ public class AccessControlAction extends
     @Override
     protected void init(SecurityProvider securityProvider, ConfigurationParameters config)
{
         setSecurityProvider(securityProvider);
-        setUserPrivilegeNames(config.getConfigValue(USER_PRIVILEGE_NAMES, (String) null));
-        setGroupPrivilegeNames(config.getConfigValue(GROUP_PRIVILEGE_NAMES, (String) null));
+        setUserPrivilegeNames(config.getNullableConfigValue(USER_PRIVILEGE_NAMES, (String)
null));
+        setGroupPrivilegeNames(config.getNullableConfigValue(GROUP_PRIVILEGE_NAMES, (String)
null));
     }
 
     //-------------------------------------------------< AuthorizableAction >---
@@ -125,7 +127,7 @@ public class AccessControlAction extends
     }
 
     //------------------------------------------------------< Configuration >---
-    public void setSecurityProvider(SecurityProvider securityProvider) {
+    public void setSecurityProvider(@Nonnull SecurityProvider securityProvider) {
         this.securityProvider = securityProvider;
     }
 
@@ -134,7 +136,7 @@ public class AccessControlAction extends
      *
      * @param privilegeNames A comma separated list of privilege names.
      */
-    public void setGroupPrivilegeNames(String privilegeNames) {
+    public void setGroupPrivilegeNames(@Nullable String privilegeNames) {
         if (privilegeNames != null && privilegeNames.length() > 0) {
             groupPrivilegeNames = split(privilegeNames);
         }
@@ -146,7 +148,7 @@ public class AccessControlAction extends
      *
      * @param privilegeNames  A comma separated list of privilege names.
      */
-    public void setUserPrivilegeNames(String privilegeNames) {
+    public void setUserPrivilegeNames(@Nullable String privilegeNames) {
         if (privilegeNames != null && privilegeNames.length() > 0) {
             userPrivilegeNames = split(privilegeNames);
         }
@@ -154,7 +156,8 @@ public class AccessControlAction extends
 
     //------------------------------------------------------------< private >---
 
-    private void setAC(Authorizable authorizable, Root root, NamePathMapper namePathMapper)
throws RepositoryException {
+    private void setAC(@Nonnull Authorizable authorizable, @Nonnull Root root,
+                       @Nonnull NamePathMapper namePathMapper) throws RepositoryException
{
         if (securityProvider == null) {
             throw new IllegalStateException("Not initialized");
         }
@@ -201,7 +204,7 @@ public class AccessControlAction extends
         }
     }
 
-    private boolean isSystemUser(Authorizable authorizable) throws RepositoryException {
+    private boolean isSystemUser(@Nonnull Authorizable authorizable) throws RepositoryException
{
         if (authorizable.isGroup()) {
             return false;
         }
@@ -219,7 +222,8 @@ public class AccessControlAction extends
      * @throws javax.jcr.RepositoryException If a privilege name cannot be
      * resolved to a valid privilege.
      */
-    private static Privilege[] getPrivileges(String[] privNames, AccessControlManager acMgr)
throws RepositoryException {
+    private static Privilege[] getPrivileges(@Nullable String[] privNames,
+                                             @Nonnull AccessControlManager acMgr) throws
RepositoryException {
         if (privNames == null || privNames.length == 0) {
             return new Privilege[0];
         }
@@ -237,7 +241,7 @@ public class AccessControlAction extends
      * list of privilege names.
      * @return An array of privilege names.
      */
-    private static String[] split(String configParam) {
+    private static String[] split(@Nonnull String configParam) {
         List<String> nameList = new ArrayList<String>();
         for (String pn : Text.explode(configParam, ',', false)) {
             String privName = pn.trim();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/PasswordValidationAction.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/PasswordValidationAction.java?rev=1483240&r1=1483239&r2=1483240&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/PasswordValidationAction.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/action/PasswordValidationAction.java
Thu May 16 08:29:40 2013
@@ -18,6 +18,8 @@ package org.apache.jackrabbit.oak.spi.se
 
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
 
@@ -58,7 +60,7 @@ public class PasswordValidationAction ex
     //-----------------------------------------< AbstractAuthorizableAction >---
     @Override
     protected void init(SecurityProvider securityProvider, ConfigurationParameters config)
{
-        String constraint = config.getConfigValue(CONSTRAINT, (String) null);
+        String constraint = config.getNullableConfigValue(CONSTRAINT, (String) null);
         if (constraint != null) {
             setConstraint(constraint);
         }
@@ -81,7 +83,7 @@ public class PasswordValidationAction ex
      *
      * @param constraint A regular expression that can be used to validate a new password.
      */
-    public void setConstraint(String constraint) {
+    public void setConstraint(@Nonnull String constraint) {
         try {
             pattern = Pattern.compile(constraint);
         } catch (PatternSyntaxException e) {
@@ -99,7 +101,7 @@ public class PasswordValidationAction ex
      * @throws RepositoryException If the specified password is too short or
      * doesn't match the specified password pattern.
      */
-    private void validatePassword(String password, boolean forceMatch) throws RepositoryException
{
+    private void validatePassword(@Nullable String password, boolean forceMatch) throws RepositoryException
{
         if (password != null && (forceMatch || PasswordUtility.isPlainTextPassword(password)))
{
             if (pattern != null && !pattern.matcher(password).matches()) {
                 throw new ConstraintViolationException("Password violates password constraint
(" + pattern.pattern() + ").");

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/ConfigurationParametersTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/ConfigurationParametersTest.java?rev=1483240&r1=1483239&r2=1483240&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/ConfigurationParametersTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/ConfigurationParametersTest.java
Thu May 16 08:29:40 2013
@@ -30,10 +30,8 @@ import static junit.framework.Assert.ass
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
 import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertArrayEquals;
 
-/**
- * ConfigurationParametersTest...
- */
 public class ConfigurationParametersTest {
 
     @Before
@@ -64,37 +62,63 @@ public class ConfigurationParametersTest
         map.put("o1", "v");
         ConfigurationParameters options = new ConfigurationParameters(map);
 
-        assertEquals("v", options.getConfigValue("o1", null));
         assertEquals("v", options.getConfigValue("o1", "v2"));
+        assertEquals("v2", options.getConfigValue("missing", "v2"));
+    }
+
+    @Test
+    public void testGetNullableConfigValue() {
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("o1", "v");
+        ConfigurationParameters options = new ConfigurationParameters(map);
+
+        assertEquals("v", options.getNullableConfigValue("o1", null));
+        assertEquals("v", options.getNullableConfigValue("o1", "v2"));
+        assertEquals("v2", options.getNullableConfigValue("missing", "v2"));
+        assertEquals(null, options.getNullableConfigValue("missing", null));
+
     }
 
     @Test
     public void testDefaultValue() {
-        TestObject testObject = new TestObject("t");
+        TestObject obj = new TestObject("t");
         Integer int1000 = new Integer(1000);
 
         ConfigurationParameters options = new ConfigurationParameters();
 
-        assertNull(options.getConfigValue("some", null));
-        assertEquals(testObject, options.getConfigValue("some", testObject));
-        assertEquals(int1000, options.getConfigValue("some", int1000));
+        assertEquals(obj, options.getConfigValue("missing", obj));
+        assertEquals(int1000, options.getConfigValue("missing", int1000));
+
+        assertNull(options.getNullableConfigValue("missing", null));
+        assertEquals(obj, options.getNullableConfigValue("missing", obj));
+        assertEquals(int1000, options.getNullableConfigValue("missing", int1000));
     }
 
     @Test
     public void testArrayDefaultValue() {
         TestObject[] testArray = new TestObject[] {new TestObject("t")};
 
-        ConfigurationParameters options = new ConfigurationParameters();
-        TestObject[] result = options.getConfigValue("test", new TestObject[0]);
+        TestObject[] result = ConfigurationParameters.EMPTY.getConfigValue("test", new TestObject[0]);
         assertNotNull(result);
         assertEquals(0, result.length);
+        assertArrayEquals(testArray, ConfigurationParameters.EMPTY.getConfigValue("test",
testArray));
 
-        result = options.getConfigValue("test", testArray);
-        assertEquals(result, testArray);
+        ConfigurationParameters options = new ConfigurationParameters(Collections.singletonMap("test",
testArray));
+        assertArrayEquals(testArray, options.getConfigValue("test", new TestObject[] {new
TestObject("s")}));
+    }
+
+    @Test
+    public void testArrayDefaultValue2() {
+        TestObject[] testArray = new TestObject[] {new TestObject("t")};
+
+        TestObject[] result = ConfigurationParameters.EMPTY.getNullableConfigValue("test",
new TestObject[0]);
+        assertNotNull(result);
+        assertEquals(0, result.length);
+        assertArrayEquals(testArray, ConfigurationParameters.EMPTY.getNullableConfigValue("test",
testArray));
 
-        options = new ConfigurationParameters(Collections.singletonMap("test", testArray));
-        result = options.getConfigValue("test", null);
-        assertEquals(result, testArray);
+        ConfigurationParameters options = new ConfigurationParameters(Collections.singletonMap("test",
testArray));
+        assertArrayEquals(testArray, (TestObject[]) options.getNullableConfigValue("test",
null));
+        assertArrayEquals(testArray, options.getNullableConfigValue("test", new TestObject[]
{new TestObject("s")}));
     }
 
     @Test
@@ -107,38 +131,74 @@ public class ConfigurationParametersTest
         m.put("String", "1000");
         m.put("Int2", new Integer(1000));
         m.put("Int3", 1000);
-
-
         ConfigurationParameters options = new ConfigurationParameters(m);
 
-        assertNotNull(options.getConfigValue("TEST", null));
-        assertEquals(testObject, options.getConfigValue("TEST", null));
         assertEquals(testObject, options.getConfigValue("TEST", testObject));
         assertEquals("t", options.getConfigValue("TEST", "defaultString"));
 
-        assertEquals("1000", options.getConfigValue("String", null));
         assertEquals(int1000, options.getConfigValue("String", new Integer(10)));
         assertEquals(new Long(1000), options.getConfigValue("String", new Long(10)));
         assertEquals("1000", options.getConfigValue("String", "10"));
 
-        assertEquals(int1000, options.getConfigValue("Int2", null));
         assertEquals(int1000, options.getConfigValue("Int2", new Integer(10)));
         assertEquals("1000", options.getConfigValue("Int2", "1000"));
 
-        assertEquals(1000, options.getConfigValue("Int3", null));
-        assertEquals(int1000, options.getConfigValue("Int3", null));
         assertEquals(int1000, options.getConfigValue("Int3", new Integer(10)));
         assertEquals("1000", options.getConfigValue("Int3", "1000"));
     }
 
     @Test
+    public void testConversion2() {
+        TestObject testObject = new TestObject("t");
+        Integer int1000 = new Integer(1000);
+
+        Map<String,Object> m = new HashMap<String, Object>();
+        m.put("TEST", testObject);
+        m.put("String", "1000");
+        m.put("Int2", new Integer(1000));
+        m.put("Int3", 1000);
+        ConfigurationParameters options = new ConfigurationParameters(m);
+
+        assertNotNull(options.getNullableConfigValue("TEST", null));
+        assertEquals(testObject, options.getNullableConfigValue("TEST", null));
+
+        assertEquals(testObject, options.getNullableConfigValue("TEST", testObject));
+        assertEquals("t", options.getNullableConfigValue("TEST", "defaultString"));
+
+        assertEquals("1000", options.getNullableConfigValue("String", null));
+        assertEquals(int1000, options.getNullableConfigValue("String", new Integer(10)));
+        assertEquals(new Long(1000), options.getNullableConfigValue("String", new Long(10)));
+        assertEquals("1000", options.getNullableConfigValue("String", "10"));
+
+        assertEquals(int1000, options.getNullableConfigValue("Int2", null));
+        assertEquals(int1000, options.getNullableConfigValue("Int2", new Integer(10)));
+        assertEquals("1000", options.getNullableConfigValue("Int2", "1000"));
+
+        assertEquals(1000, options.getNullableConfigValue("Int3", null));
+        assertEquals(int1000, options.getNullableConfigValue("Int3", new Integer(10)));
+        assertEquals("1000", options.getNullableConfigValue("Int3", "1000"));
+    }
+
+    @Test
     public void testNullValue() {
         ConfigurationParameters options = new ConfigurationParameters(Collections.singletonMap("test",
null));
 
         assertNull(options.getConfigValue("test", null));
-        assertNull(options.getConfigValue("test", "value"));
-        assertNull(options.getConfigValue("test", new TestObject("t")));
-        assertNull(options.getConfigValue("test", false));
+        assertEquals("value", options.getConfigValue("test", "value"));
+        TestObject to = new TestObject("t");
+        assertEquals(to, options.getConfigValue("test", to));
+        assertFalse(options.getConfigValue("test", false));
+    }
+
+    @Test
+    public void testNullValue2() {
+        ConfigurationParameters options = new ConfigurationParameters(Collections.singletonMap("test",
null));
+
+        assertNull(options.getNullableConfigValue("test", null));
+        assertNull(options.getNullableConfigValue("test", "value"));
+        assertNull(options.getNullableConfigValue("test", "value"));
+        assertNull(options.getNullableConfigValue("test", new TestObject("t")));
+        assertNull(options.getNullableConfigValue("test", false));
     }
 
     private class TestObject {
@@ -153,6 +213,10 @@ public class ConfigurationParametersTest
             return name;
         }
 
+        public int hashCode() {
+            return name.hashCode();
+        }
+
         public boolean equals(Object object) {
             if (object == this) {
                 return true;



Mime
View raw message