Author: bdekruijff at gmail.com
Date: Mon Dec 20 15:49:44 2010
New Revision: 516

Log:
[sandbox] Additional testing

Modified:
   
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/internal/DistributionUtilities.java
   
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DistributionServiceImpl.java
   
sandbox/bdekruijff/fabric/src/test/java/org/amdatu/core/fabric/remote/service/DistributionUtilitiesTest.java

Modified: 
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/internal/DistributionUtilities.java
==============================================================================
--- 
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/internal/DistributionUtilities.java
   (original)
+++ 
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/internal/DistributionUtilities.java
   Mon Dec 20 15:49:44 2010
@@ -27,35 +27,38 @@
 public final class DistributionUtilities {
 
     public static boolean isConfigurationTypeSupported(Dictionary<String, 
Object> serviceRegistrationProperties) {
+        if (serviceRegistrationProperties == null) {
+            return false;
+        }
+        Object exportedConfigsValue =
+            
serviceRegistrationProperties.get(DistributionService.SERVICE_EXPORTED_CONFIGS_PROP);
+        if (exportedConfigsValue == null) {
+            return false;
+        }
+        if (!String[].class.isAssignableFrom(exportedConfigsValue.getClass())) 
{
+            return false;
+        }
         String[] expertedConfgis =
             (String[]) 
serviceRegistrationProperties.get(DistributionService.SERVICE_EXPORTED_CONFIGS_PROP);
-        if (stringArrayContainsValue(expertedConfgis, 
DistributionService.SERVICE_CONFIGURATION_TYPE)) {
-            return true;
+        if (!stringArrayContainsValue(expertedConfgis, 
DistributionService.SERVICE_CONFIGURATION_TYPE)) {
+            return false;
         }
-        return false;
+        return true;
     }
 
-    public static boolean isIntentsListSupported(Dictionary<String, Object> 
serviceRegistrationProperties) {
-        String[] serviceIntents =
-            (String[]) 
serviceRegistrationProperties.get(DistributionService.SERVICE_INTENTS_PROP);
-        if 
(!stringArrayContainsValues(DistributionService.DISTRIBUTION_INTENTS_SUPPORTED, 
serviceIntents)) {
-            return false;
-        }
-        String[] serviceExportedIntents =
-            (String[]) 
serviceRegistrationProperties.get(DistributionService.SERVICE_EXPORTED_INTENTS_PROP);
-        if 
(!stringArrayContainsValues(DistributionService.DISTRIBUTION_INTENTS_SUPPORTED, 
serviceExportedIntents)) {
+    public static boolean isExportedIntentsListSupported(Dictionary<String, 
Object> serviceRegistrationProperties) {
+        if (serviceRegistrationProperties == null) {
             return false;
         }
-        String[] serviceExportedIntentsExtra =
-            (String[]) 
serviceRegistrationProperties.get(DistributionService.SERVICE_INTENTS_PROP);
-        if 
(!stringArrayContainsValues(DistributionService.DISTRIBUTION_INTENTS_SUPPORTED, 
serviceExportedIntentsExtra)) {
+        String[] mergedIntents = 
mergeExportedIntents(serviceRegistrationProperties);
+        if 
(!stringArrayContainsValues(DistributionService.DISTRIBUTION_INTENTS_SUPPORTED, 
mergedIntents)) {
             return false;
         }
         return true;
     }
 
     public static boolean isExportedInterfacesSupported(Dictionary<String, 
Object> serviceRegistrationProperties,
-        ClassLoaderAdaptor classLoadingHelper) {
+        ClassLoaderAdaptor classLoaderAdaptor) {
         if (serviceRegistrationProperties == null) {
             return false;
         }
@@ -64,7 +67,7 @@
         if (serviceRegistrationProperty == null) {
             return false;
         }
-        if 
(!serviceRegistrationProperty.getClass().isAssignableFrom(String[].class)) {
+        if 
(!String[].class.isAssignableFrom(serviceRegistrationProperty.getClass())) {
             return false;
         }
         String[] exportedInterfaces = (String[]) serviceRegistrationProperty;
@@ -73,7 +76,7 @@
         }
         for (String exportedInterface : exportedInterfaces) {
             try {
-                Class<?> exportedInterfaceClass = 
classLoadingHelper.loadClass(exportedInterface);
+                Class<?> exportedInterfaceClass = 
classLoaderAdaptor.loadClass(exportedInterface);
                 if (exportedInterfaceClass == null) { // can it happen?
                     return false;
                 }
@@ -81,11 +84,12 @@
                     return false;
                 }
                 for (Method method : exportedInterfaceClass.getMethods()) {
-                    if 
(!Serializable.class.isAssignableFrom(method.getReturnType())) {
+                    if (!method.getReturnType().isPrimitive()
+                        && 
!Serializable.class.isAssignableFrom(method.getReturnType())) {
                         return false;
                     }
                     for (Class<?> parameterType : method.getParameterTypes()) {
-                        if 
(!Serializable.class.isAssignableFrom(parameterType)) {
+                        if (!parameterType.isPrimitive() && 
!Serializable.class.isAssignableFrom(parameterType)) {
                             return false;
                         }
                     }

Modified: 
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DistributionServiceImpl.java
==============================================================================
--- 
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DistributionServiceImpl.java
  (original)
+++ 
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DistributionServiceImpl.java
  Mon Dec 20 15:49:44 2010
@@ -289,7 +289,7 @@
             System.err.println("No supported configuration type");
             return false;
         }
-        if 
(!DistributionUtilities.isIntentsListSupported(serviceEndPoint.getProperties()))
 {
+        if 
(!DistributionUtilities.isExportedIntentsListSupported(serviceEndPoint.getProperties()))
 {
             System.err.println("Not all intents supported");
             return false;
         }

Modified: 
sandbox/bdekruijff/fabric/src/test/java/org/amdatu/core/fabric/remote/service/DistributionUtilitiesTest.java
==============================================================================
--- 
sandbox/bdekruijff/fabric/src/test/java/org/amdatu/core/fabric/remote/service/DistributionUtilitiesTest.java
        (original)
+++ 
sandbox/bdekruijff/fabric/src/test/java/org/amdatu/core/fabric/remote/service/DistributionUtilitiesTest.java
        Mon Dec 20 15:49:44 2010
@@ -21,9 +21,121 @@
     }
 
     @Test
+    public void testIsConfigurationTypeSupported() {
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+
+        Assert.assertFalse("No config specified... cannot be supported",
+            DistributionUtilities.isConfigurationTypeSupported(null));
+
+        Assert.assertFalse("No config specified... cannot be supported",
+            DistributionUtilities.isConfigurationTypeSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_CONFIGS_PROP, 
DistributionService.SERVICE_CONFIGURATION_TYPE);
+        Assert.assertFalse("Wrong config class... cannot be supported",
+            DistributionUtilities.isConfigurationTypeSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_CONFIGS_PROP,
+            new String[] { "hello" });
+        Assert.assertFalse("Unknown config specified... cannot be supported",
+            DistributionUtilities.isConfigurationTypeSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_CONFIGS_PROP,
+            new String[] { DistributionService.SERVICE_CONFIGURATION_TYPE });
+        Assert.assertTrue("Our config specified... should be supported",
+            DistributionUtilities.isConfigurationTypeSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_CONFIGS_PROP, new 
String[] { "hello",
+            DistributionService.SERVICE_CONFIGURATION_TYPE });
+        Assert.assertTrue("Our config specified... should be supported",
+            DistributionUtilities.isConfigurationTypeSupported(props));
+    }
+
+    @Test
+    public void testIsExportedIntentsListSupported() {
+
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+
+        Assert.assertFalse("No properties specified... cannot be supported",
+            DistributionUtilities.isExportedIntentsListSupported(null));
+
+        Assert.assertTrue("No intents specified... should be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_INTENTS_PROP, new String[] {});
+        Assert.assertTrue("No intents specified... should be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_INTENTS_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY });
+        Assert.assertTrue("Known intent specified... should be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_INTENTS_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY,
+                DistributionService.DISTRIBUTION_INTENT_INTEGRITY });
+        Assert.assertTrue("Known intents specified... should be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTENTS_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY });
+        Assert.assertTrue("Known intent specified... should be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTENTS_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY,
+                DistributionService.DISTRIBUTION_INTENT_INTEGRITY });
+        Assert.assertTrue("Known intents specified... should be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTENTS_EXTRA_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY });
+        Assert.assertTrue("Known intent specified... should be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTENTS_EXTRA_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY,
+                DistributionService.DISTRIBUTION_INTENT_INTEGRITY });
+        Assert.assertTrue("Known intents specified... should be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_INTENTS_PROP,
+            new String[] { "unknown_intent" });
+        Assert.assertFalse("Unknown intent specified... cannot be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_INTENTS_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY,
+                "unknown_intent" });
+        Assert.assertFalse("Unknown intent specified... cannot be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTENTS_PROP,
+            new String[] { "unknown_intent" });
+        Assert.assertFalse("Unknown intent specified... cannot be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTENTS_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY,
+                "unknown_intent" });
+        Assert.assertFalse("Unknown intent specified... cannot be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTENTS_EXTRA_PROP,
+            new String[] { "unknown_intent" });
+        Assert.assertFalse("Unknown intent specified... cannot be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTENTS_EXTRA_PROP,
+            new String[] { 
DistributionService.DISTRIBUTION_INTENT_CONFIDENTIALITY,
+                "unknown_intent" });
+        Assert.assertFalse("Unknown intent specified... cannot be supported",
+            DistributionUtilities.isExportedIntentsListSupported(props));
+    }
+
+    @Test
     public void testIsExportedInterfacesSupported() {
 
-        ClassLoaderAdaptor clh = new ClassLoaderAdaptor() {
+        ClassLoaderAdaptor cla = new ClassLoaderAdaptor() {
             public Class<?> loadClass(String className) throws 
ClassNotFoundException {
                 return this.getClass().getClassLoader().loadClass(className);
             }
@@ -31,45 +143,67 @@
 
         Dictionary<String, Object> props = new Hashtable<String, Object>();
 
-        // null dict
-        
Assert.assertFalse(DistributionUtilities.isExportedInterfacesSupported(null, 
clh));
+        Assert.assertFalse("No config specified... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(null, cla));
 
-        // null clh
-        
Assert.assertFalse(DistributionUtilities.isExportedInterfacesSupported(props, 
clh));
+        Assert.assertFalse("No classloader specified... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, null));
 
-        // empty dict
-        
Assert.assertFalse(DistributionUtilities.isExportedInterfacesSupported(props, 
clh));
+        Assert.assertFalse("No config specified... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
 
-        // String prop
         props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP, 
"hello");
-        
Assert.assertFalse(DistributionUtilities.isExportedInterfacesSupported(props, 
clh));
+        Assert.assertFalse("Wrong config class... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP, new 
String[] {});
+        Assert.assertFalse("No interface specified... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
 
-        // Non existing class
         props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP, new 
String[] { "foo.bar.Test" });
-        
Assert.assertFalse(DistributionUtilities.isExportedInterfacesSupported(props, 
clh));
+        Assert.assertFalse("Class not loadable... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
 
-        // Non interface class
         props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP, new 
String[] { String.class.getName() });
-        
Assert.assertFalse(DistributionUtilities.isExportedInterfacesSupported(props, 
clh));
-
-        // Remotable interface class
-        props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP,
-            new String[] { RemotableInterface1.class.getName() });
-        
Assert.assertTrue(DistributionUtilities.isExportedInterfacesSupported(props, 
clh));
+        Assert.assertFalse("Class not an interface... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
 
-        // Nonremotable interface class
         props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP,
             new String[] { NonRemotableInterface1.class.getName() });
-        
Assert.assertFalse(DistributionUtilities.isExportedInterfacesSupported(props, 
clh));
+        Assert.assertFalse("Interface not serializable... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
+
         props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP,
             new String[] { NonRemotableInterface2.class.getName() });
-        
Assert.assertFalse(DistributionUtilities.isExportedInterfacesSupported(props, 
clh));
+        Assert.assertFalse("Interface not serializable... cannot be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP,
+            new String[] { NonRemotableInterface2.class.getName(), 
RemotableInterface1.class.getName() });
+        Assert.assertFalse("Interfaces not serializable... cannot be 
supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP,
+            new String[] { RemotableInterface1.class.getName() });
+        Assert.assertTrue("Valid interface... should be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
+
+        props.put(DistributionService.SERVICE_EXPORTED_INTERFACES_PROP,
+            new String[] { RemotableInterface1.class.getName(), 
RemotableInterface2.class.getName() });
+        Assert.assertTrue("Valid interface... should be supported",
+            DistributionUtilities.isExportedInterfacesSupported(props, cla));
 
     }
 }
 
 interface RemotableInterface1 {
     String helloWorld(String arg1);
+
+    int helloWorld(String arg1, long l);
+}
+
+interface RemotableInterface2 {
+    void helloWorld(int arg1);
 }
 
 interface NonRemotableInterface1 {

Reply via email to