You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gu...@apache.org on 2013/02/14 10:56:15 UTC

svn commit: r1446089 - in /felix/trunk/ipojo/manipulator/manipulator/src: main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ test/java/org/apache/felix/ipojo/manip...

Author: guillaume
Date: Thu Feb 14 09:56:15 2013
New Revision: 1446089

URL: http://svn.apache.org/r1446089
Log:
FELIX-3900 @HandlerDeclaration do not convert DOM Attributes to iPOJO Attributes correctly
FELIX-3901 Avoid converting Xml namespace declaration with @HandlerDeclaration

* Use Attr.getLocalName() instead of Attr.getName(): getName returns a concatenation of prefix + ':' + localName
* Ignore 'xmlns' prefixed attributes
* Added tests to avoid future regressions

Added:
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitorTestCase.java
Modified:
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java?rev=1446089&r1=1446088&r2=1446089&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java Thu Feb 14 09:56:15 2013
@@ -120,7 +120,9 @@ public class HandlerDeclarationVisitor e
             NamedNodeMap attributes = xmlElement.getAttributes();
             for (int i = 0; i < attributes.getLength(); i++) {
                 Attr attr = (Attr) attributes.item(i);
-                root.addAttribute(transformAttribute(attr));
+                if (!"xmlns".equals(attr.getPrefix())) {
+                    root.addAttribute(transformAttribute(attr));
+                }
             }
         }
 
@@ -144,7 +146,7 @@ public class HandlerDeclarationVisitor e
     }
 
     private static Attribute transformAttribute(Attr attr) {
-        return new Attribute(attr.getName(),
+        return new Attribute(attr.getLocalName(),
                 attr.getNamespaceURI(),
                 attr.getValue());
     }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java?rev=1446089&r1=1446088&r2=1446089&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java Thu Feb 14 09:56:15 2013
@@ -81,7 +81,7 @@ public class ComponentWorkbenchTestCase 
     }
 
 
-    private static ClassNode node() {
+    public static ClassNode node() {
         ClassNode node = new ClassNode();
         node.name = "my/Component";
         return node;

Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitorTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitorTestCase.java?rev=1446089&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitorTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitorTestCase.java Thu Feb 14 09:56:15 2013
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import junit.framework.TestCase;
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.metadata.Element;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import static org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbenchTestCase.node;
+import static org.mockito.Mockito.mock;
+
+/**
+ * User: guillaume
+ * Date: 14/02/13
+ * Time: 10:22
+ */
+public class HandlerDeclarationVisitorTestCase extends TestCase {
+
+    private Reporter reporter;
+    private ComponentWorkbench workbench;
+    private HandlerDeclarationVisitor visitor;
+
+    @Override
+    public void setUp() throws Exception {
+        reporter = mock(Reporter.class);
+        workbench = new ComponentWorkbench(null, node());
+        workbench.setRoot(new Element("container", null));
+        visitor = new HandlerDeclarationVisitor(workbench, builder(), reporter);
+    }
+
+    public void testElementConversionWithNoNamespace() throws Exception {
+        visitor.visit(null, "<testing/>");
+        visitor.visitEnd();
+
+        Element produced = workbench.build();
+        Element testing = produced.getElements("testing")[0];
+        assertEquals(0, testing.getElements().length);
+        assertEquals(0, testing.getAttributes().length);
+    }
+
+    public void testElementConversionWithNamespace() throws Exception {
+        visitor.visit(null, "<ns:testing xmlns:ns='org.apache.felix.ipojo.testing'/>");
+        visitor.visitEnd();
+
+        Element produced = workbench.build();
+        Element testing = produced.getElements("testing", "org.apache.felix.ipojo.testing")[0];
+        assertEquals(0, testing.getElements().length);
+        assertEquals(0, testing.getAttributes().length);
+        assertNotNull(produced.getElements("org.apache.felix.ipojo.testing:testing"));
+        assertNull(produced.getElements("testing"));
+    }
+
+    public void testAttributeConversionWithNamespace() throws Exception {
+        visitor.visit(null, "<ns:testing xmlns:ns='org.apache.felix.ipojo.testing' ns:name='Guillaume'/>");
+        visitor.visitEnd();
+
+        Element produced = workbench.build();
+        Element testing = produced.getElements("testing", "org.apache.felix.ipojo.testing")[0];
+        assertEquals(0, testing.getElements().length);
+        assertEquals(1, testing.getAttributes().length);
+        assertEquals("Guillaume", testing.getAttribute("name", "org.apache.felix.ipojo.testing"));
+        assertEquals("Guillaume", testing.getAttribute("org.apache.felix.ipojo.testing:name"));
+    }
+
+    public void testAttributeConversionWithNoNamespace() throws Exception {
+        visitor.visit(null, "<ns:testing xmlns:ns='org.apache.felix.ipojo.testing' name='Guillaume'/>");
+        visitor.visitEnd();
+
+        Element produced = workbench.build();
+        Element testing = produced.getElements("testing", "org.apache.felix.ipojo.testing")[0];
+        assertEquals(0, testing.getElements().length);
+        assertEquals(1, testing.getAttributes().length);
+        assertEquals("Guillaume", testing.getAttribute("name"));
+    }
+
+    private DocumentBuilder builder() throws ParserConfigurationException {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        return factory.newDocumentBuilder();
+    }
+}