felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guilla...@apache.org
Subject svn commit: r1499988 - in /felix/trunk/ipojo/runtime/core/src: main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java test/java/org/apache/felix/ipojo/extender/internal/linker/ManagedTypeTestCase.java
Date Fri, 05 Jul 2013 12:44:35 GMT
Author: guillaume
Date: Fri Jul  5 12:44:35 2013
New Revision: 1499988

URL: http://svn.apache.org/r1499988
Log:
FELIX-4164 Instance / Component matching regression

* Tracks instances specifying the component's name OR the component's classname

Modified:
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/linker/ManagedTypeTestCase.java

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java?rev=1499988&r1=1499987&r2=1499988&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
Fri Jul  5 12:44:35 2013
@@ -124,25 +124,32 @@ public class ManagedType implements Fact
         String version = m_declaration.getComponentVersion();
         if (version != null) {
             // Track instance for:
-            // * this component AND
+            // * this component's name OR classname
+            //            AND
             // * this component's version OR no version
             filter = format(
-                    "(&(objectClass=%s)(%s=%s)(|(%s=%s)(!(%s=*))))",
+                    "(&(objectClass=%s)(|(%s=%s)(%s=%s))(|(%s=%s)(!(%s=*))))",
                     InstanceDeclaration.class.getName(),
                     InstanceDeclaration.COMPONENT_NAME_PROPERTY,
                     m_declaration.getComponentName(),
+                    InstanceDeclaration.COMPONENT_NAME_PROPERTY,
+                    getComponentClassname(),
                     InstanceDeclaration.COMPONENT_VERSION_PROPERTY,
                     version,
                     InstanceDeclaration.COMPONENT_VERSION_PROPERTY
             );
         } else {
             // Track instance for:
-            // * this component AND no version
+            // * this component's name OR classname
+            //       AND
+            // * no version
             filter = format(
-                    "(&(objectClass=%s)(%s=%s)(!(%s=*)))",
+                    "(&(objectClass=%s)(|(%s=%s)(%s=%s))(!(%s=*)))",
                     InstanceDeclaration.class.getName(),
                     InstanceDeclaration.COMPONENT_NAME_PROPERTY,
                     m_declaration.getComponentName(),
+                    InstanceDeclaration.COMPONENT_NAME_PROPERTY,
+                    getComponentClassname(),
                     InstanceDeclaration.COMPONENT_VERSION_PROPERTY
             );
         }
@@ -150,6 +157,13 @@ public class ManagedType implements Fact
     }
 
     /**
+     * Returns the {@literal classname} attribute value.
+     */
+    private String getComponentClassname() {
+        return m_declaration.getComponentMetadata().getAttribute("classname");
+    }
+
+    /**
      * Starting the management.
      * We open only the extension tracker.
      */

Modified: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/linker/ManagedTypeTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/linker/ManagedTypeTestCase.java?rev=1499988&r1=1499987&r2=1499988&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/linker/ManagedTypeTestCase.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/linker/ManagedTypeTestCase.java
Fri Jul  5 12:44:35 2013
@@ -20,12 +20,16 @@
 package org.apache.felix.ipojo.extender.internal.linker;
 
 import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.contains;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import org.apache.felix.ipojo.extender.ExtensionDeclaration;
+import org.apache.felix.ipojo.extender.InstanceDeclaration;
 import org.apache.felix.ipojo.extender.TypeDeclaration;
 import org.apache.felix.ipojo.extender.queue.QueueService;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.osgi.framework.BundleContext;
@@ -65,12 +69,31 @@ public class ManagedTypeTestCase extends
         );
 
         when(declaration.getExtension()).thenReturn("test");
+        when(declaration.getComponentMetadata()).thenReturn(element("test", "f.q.n.Type"));
+        when(declaration.getComponentName()).thenReturn("Type");
         when(filter.toString()).thenReturn(filterStr);
 
         ManagedType managedType = new ManagedType(bundleContext, queueService, declaration);
         managedType.start();
 
         verify(bundleContext).getAllServiceReferences(null, filterStr);
+
+        // Check that the filter contains a logical OR with component's name and classname
+        verify(bundleContext).createFilter(
+                contains(
+                        String.format("(|(%s=%s)(%s=%s))",
+                               InstanceDeclaration.COMPONENT_NAME_PROPERTY,
+                               "Type",
+                               InstanceDeclaration.COMPONENT_NAME_PROPERTY,
+                               "f.q.n.Type")
+                )
+        );
+    }
+
+    private Element element(String type, String classname) {
+        Element root = new Element(type, null);
+        root.addAttribute(new Attribute("classname", classname));
+        return root;
     }
 
 }



Mime
View raw message