(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 15 Nov 2009 10:38:08 +0000 (10:38 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 15 Nov 2009 10:38:08 +0000 (10:38 +0000)
trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java
trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java
trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java
trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java
trunk/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java
trunk/system/general/src/test/java/org/wamblee/system/adapters/ClassConfigurationTest.java
trunk/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java

index 9afece0081f8efe2170fc403f72f9000383e6934..2dcefee78715e77c4ceba8563b9050a0ca8041b2 100644 (file)
@@ -83,9 +83,9 @@ public class PersistentAuthorizationServiceTest extends
 
         ObjectConfiguration config = new ObjectConfiguration(
                 PersistentAuthorizationServiceTest.class);
-        config.getSetterConfig().clear().add("userAccessor").add(
-                "databaseTester").add("hibernateTemplate").add(
-                "authorizationService");
+        config.getSetterConfig().clear().add("setUserAccessor").add(
+                "setDatabaseTester").add("setHibernateTemplate").add(
+                "setAuthorizationService");
         _container.addComponent("testcase", this, config);
 
         _scope = _container.start();
index f1f5d18b0c7856f882124cfbb4d4918aa6e9f949..fa80b1a416b4664eb3f1fd48d3ee61c48368d9ee 100644 (file)
@@ -54,7 +54,7 @@ public class HibernateGroupSetTest extends InMemoryGroupSetTest {
         ObjectConfiguration config = new ObjectConfiguration(
                 HibernateGroupSetTest.class);
         config.getSetterConfig().clear().add(
-                "groupSet").add("databaseTester");
+                "setGroupSet").add("setDatabaseTester");
         _container.addComponent("testcase", this, config);
 
         _scope = _container.start();
index 5d604fc074f5e9f774450f8c5c563b29465bde6d..f707dba008ae8ead2c305b9c2cece9603e174675 100644 (file)
@@ -72,7 +72,7 @@ public class HibernateUserAdministrationTest extends UserAdministrationImplTest
         ObjectConfiguration config = new ObjectConfiguration(
                 HibernateUserAdministrationTest.class);
         config.getSetterConfig().clear().add(
-                "userCache").add("databaseTester").add("userAdmin");
+                "setUserCache").add("setDatabaseTester").add("setUserAdmin");
         _container.addComponent("testcase", this, config);
 
         _scope = _container.start();
index 6b7dc38a1f2581f7b0699f00234ffb445d8a3828..82588b3be03462877ade997427a5b18511d36496 100644 (file)
@@ -68,8 +68,8 @@ public class HibernateUserSetTest extends InMemoryUserSetTest {
        
         ObjectConfiguration config = new ObjectConfiguration(
                 HibernateUserSetTest.class);
-        config.getSetterConfig().clear().add("userset").add(
-                "groupset").add("databaseTester").add("userCache");
+        config.getSetterConfig().clear().add("setUserset").add(
+                "setGroupset").add("setDatabaseTester").add("setUserCache");
         _container.addComponent("testcase", this, config);
 
         _scope = _container.start();
index 649e008fae1f7f1ff0f17eff1b0c3923cd906db9..f81c4a4bc405837d893f5e021635a3b3bd1e0137 100644 (file)
@@ -100,21 +100,40 @@ public class SetterConfiguration {
         * Removes a setter from the set of methods.
         * 
         * @param aName
-        *            Name of the setter to remove (without the "set" prefix).
+        *            Name of the setter to remove.
         * @return Reference to the current object to allow call chaining.
         */
        public SetterConfiguration remove(String aName) {
-               final String name = createSetterName(aName);
-               Map<Method, ParameterValues> setters = new HashMap<Method, ParameterValues>();
                for (Method method : _setters.keySet()) {
-                       if (method.getName().equals(name)) {
+                       if (method.getName().equals(aName)) {
                                _setters.remove(method);
                                return this;
                        }
                }
                throw new IllegalArgumentException(
-                               "No setter configured by the name of '" + aName + "'");
+                               "No method configured by the name of '" + aName + "'");
        }
+       
+       /**
+        * Removes the method from the set of methods. 
+        * @param aMethod Method to remove. 
+        * @return
+        */
+       public SetterConfiguration remove(Method aMethod) { 
+           if ( !aMethod.getDeclaringClass().isAssignableFrom(_class) ) { 
+               throw new RuntimeException("Method " + aMethod + " not found in class " + _class + " or its superclasses");
+           }
+           for (Method method : _setters.keySet()) {
+            if (method.equals(aMethod)) {
+                _setters.remove(method);
+                return this;
+            }
+        }
+        throw new IllegalArgumentException(
+                "Method '" + aMethod + "' was not configured. ");
+       }
+       
+       
 
        /**
         * Creates the name of a setter based on the name of the setter without the
@@ -124,31 +143,30 @@ public class SetterConfiguration {
         *            Setter name.
         * @return Setter name.
         */
-       private String createSetterName(String aName) {
+       private String createxSetterName(String aName) {
                return "set" + aName.substring(0, 1).toUpperCase() + aName.substring(1);
        }
 
        /**
         * Adds a given setter name to the setters.
         * 
-        * @param aName
+        * @param aName Name of a setter method.
         * @return Reference to the current object to allow call chaining.
         */
-       public SetterConfiguration add(String aName) {
-               final String name = createSetterName(aName);
+       public SetterConfiguration add(final String aName) {
                int oldlen = _setters.size();
                List<Method> methods = new ArrayList<Method>();
                CollectionFilter.filter(getAllSetters(_class, _publicOnly), methods,
                                new Condition<Method>() {
                                        @Override
                                        public boolean matches(Method aObject) {
-                                               return aObject.getName().equals(name);
+                                               return aObject.getName().equals(aName);
                                        }
 
                                });
                if (methods.size() == 0 ) {
-                       throw new IllegalArgumentException("No setter found for '" + aName
-                                       + "' in " + _class.getName());
+                       throw new IllegalArgumentException("Method '" + aName
+                                       + "' not found in " + _class.getName());
                }
                // TODO is it possible to get more than one setter here in case the subclass overrides
                // the baseclass method? 
@@ -220,8 +238,9 @@ public class SetterConfiguration {
        }
 
        private static ParameterValues createParameterValues(Method method) {
+           // TODO generalize to multiple parameters. 
                return new ParameterValues(
-                               new String[] { getSetterName(method) }, new Class[] { method
+                               new String[] { method.getName() }, new Class[] { method
                                                .getParameterTypes()[0] });
        }
 
@@ -280,13 +299,12 @@ public class SetterConfiguration {
         * @return Parameter values.
         */
        public ParameterValues values(String aMethod) {
-               String name = createSetterName(aMethod);
                for (Method method : _setters.keySet()) {
-                       if (method.getName().equals(name)) {
+                       if (method.getName().equals(aMethod)) {
                                return _setters.get(method);
                        }
                }
-               throw new IllegalArgumentException("No setter method '" + name
+               throw new IllegalArgumentException("No setter method '" + aMethod
                                + "' found");
        }
 
@@ -299,7 +317,7 @@ public class SetterConfiguration {
         *            Method.
         * @return Setter name.
         */
-       private static String getSetterName(Method aMethod) {
+       private static String getxSetterName(Method aMethod) {
                String result = aMethod.getName().substring(3);
                return result.substring(0, 1).toLowerCase() + result.substring(1);
        }
index a5cd1a09c6d337ba83c5e494b06ff1a10288b5c4..8d5703dd603810c4a5f5dc2aefb0484cccf3bb67 100644 (file)
@@ -53,7 +53,7 @@ public class ClassConfigurationTest extends AdapterTestCase {
         ClassConfiguration classConfig = new ClassConfiguration(X7.class);
 
         classConfig.getConstructorConfig().select(Boolean.class);
-        classConfig.getObjectConfig().getSetterConfig().initAllSetters().values("port").setValue(0, 10);
+        classConfig.getObjectConfig().getSetterConfig().initAllSetters().values("setPort").setValue(0, 10);
         
         ProvidedInterface providedBoolean = new DefaultProvidedInterface("boolean",
                 Boolean.class);
index 1d7ec75e3648d35b15842da61f216e07e482a3f4..382beb36d4dbb01ca180d09a70e6b333f9a43164 100644 (file)
@@ -36,7 +36,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                config.initAllSetters();
                List<RequiredInterface> required = config.getRequiredInterfaces();
                assertEquals(1, required.size());
-               assertEquals("value", required.get(0).getName());
+               assertEquals("setValue", required.get(0).getName());
 
                ProvidedInterface provided = new DefaultProvidedInterface("janse",
                                String.class);
@@ -62,8 +62,8 @@ public class SetterConfigurationTest extends AdapterTestCase {
                        }
                });
                assertEquals(2, required.size());
-               assertEquals("value", required.get(0).getName());
-               assertEquals("xyz", required.get(1).getName());
+               assertEquals("setValue", required.get(0).getName());
+               assertEquals("setXyz", required.get(1).getName());
 
                ProvidedInterface providedString = new DefaultProvidedInterface(
                                "janse", String.class);
@@ -98,9 +98,9 @@ public class SetterConfigurationTest extends AdapterTestCase {
                        }
                });
                assertEquals(3, required.size());
-               assertEquals("flag", required.get(0).getName());
-               assertEquals("value", required.get(1).getName());
-               assertEquals("xyz", required.get(2).getName());
+               assertEquals("setFlag", required.get(0).getName());
+               assertEquals("setValue", required.get(1).getName());
+               assertEquals("setXyz", required.get(2).getName());
 
                ProvidedInterface providedBoolean = new DefaultProvidedInterface(
                                "janse", Boolean.class);
@@ -135,8 +135,8 @@ public class SetterConfigurationTest extends AdapterTestCase {
                List<RequiredInterface> required = config.getRequiredInterfaces();
                Collections.sort(required, new RequiredInterfaceComparator());
                assertEquals(2, required.size());
-               assertEquals("host", required.get(0).getName());
-               assertEquals("port", required.get(1).getName());
+               assertEquals("setHost", required.get(0).getName());
+               assertEquals("setPort", required.get(1).getName());
 
                ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                                String.class);
@@ -161,7 +161,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                final SetterConfiguration config = new SetterConfiguration(X5.class).initAllSetters();
                List<RequiredInterface> required = config.getRequiredInterfaces();
                assertEquals(1, required.size());
-               assertEquals("value", required.get(0).getName());
+               assertEquals("setValue", required.get(0).getName());
 
                ProvidedInterface provided = new DefaultProvidedInterface("janse",
                                String.class);
@@ -179,7 +179,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
 
        public void testSetExplicitValue() {
                SetterConfiguration config = new SetterConfiguration(X5.class).initAllSetters();
-               config.values("value").setValue(0, "bladibla");
+               config.values("setValue").setValue(0, "bladibla");
 
                List<RequiredInterface> required = config.getRequiredInterfaces();
                assertEquals(0, required.size());
@@ -209,11 +209,11 @@ public class SetterConfigurationTest extends AdapterTestCase {
 
        public void testAddByName() {
                SetterConfiguration config = new SetterConfiguration(X6.class);
-               config.clear().add("host");
+               config.clear().add("setHost");
                List<RequiredInterface> required = config.getRequiredInterfaces();
                Collections.sort(required, new RequiredInterfaceComparator());
                assertEquals(1, required.size());
-               assertEquals("host", required.get(0).getName());
+               assertEquals("setHost", required.get(0).getName());
 
                ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                                String.class);
@@ -235,7 +235,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                List<RequiredInterface> required = config.getRequiredInterfaces();
                Collections.sort(required, new RequiredInterfaceComparator());
                assertEquals(1, required.size());
-               assertEquals("host", required.get(0).getName());
+               assertEquals("setHost", required.get(0).getName());
 
                ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                                String.class);
@@ -263,7 +263,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                
                config.setNonPublic(true);
                config.clear();
-               config.add("xyz");
+               config.add("setXyz");
                assertEquals(1, config.getRequiredInterfaces().size());
        }
 
@@ -298,11 +298,11 @@ public class SetterConfigurationTest extends AdapterTestCase {
 
        public void testRemove() {
                SetterConfiguration config = new SetterConfiguration(X6.class).initAllSetters();
-               config.remove("port");
+               config.remove("setPort");
                List<RequiredInterface> required = config.getRequiredInterfaces();
                Collections.sort(required, new RequiredInterfaceComparator());
                assertEquals(1, required.size());
-               assertEquals("host", required.get(0).getName());
+               assertEquals("setHost", required.get(0).getName());
 
                ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                                String.class);