[jboss-svn-commits] JBoss Common SVN: r2161 - in jbossxb/trunk/src/test: java/org/jboss/test/xml resources/org/jboss/test/xml

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Nov 16 10:38:05 EST 2006


Author: adrian at jboss.org
Date: 2006-11-16 10:38:02 -0500 (Thu, 16 Nov 2006)
New Revision: 2161

Added:
   jbossxb/trunk/src/test/java/org/jboss/test/xml/DuplicateInterceptorUnitTestCase.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/DuplicateInterceptor.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/DuplicateInterceptor.xsd
Log:
Another test

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/DuplicateInterceptorUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/DuplicateInterceptorUnitTestCase.java	2006-11-16 00:36:47 UTC (rev 2160)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/DuplicateInterceptorUnitTestCase.java	2006-11-16 15:38:02 UTC (rev 2161)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xml;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestSuite;
+
+import org.jboss.xb.binding.metadata.ClassMetaData;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementInterceptor;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
+
+/**
+ * DuplicateInterceptorUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DuplicateInterceptorUnitTestCase extends AbstractJBossXBTest
+{  
+   private static final String NS = "http://www.jboss.org/test/xml/duplicateInterceptor";
+   
+   public static final TestSuite suite()
+   {
+      return new TestSuite(DuplicateInterceptorUnitTestCase.class);
+   }
+   
+   public DuplicateInterceptorUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testDuplicateInterceptor() throws Exception
+   {
+      SchemaBinding schema = bind("DuplicateInterceptor.xsd");
+      schema.setIgnoreUnresolvedFieldOrClass(false);
+
+      ClassMetaData classMetaData = new ClassMetaData();
+      classMetaData.setImpl(Parent1.class.getName());
+      TypeBinding parent1Type = schema.getType(new QName(NS, "parent1Type"));
+      assertNotNull(parent1Type);
+      parent1Type.setClassMetaData(classMetaData);
+
+      parent1Type.pushInterceptor(new QName(NS, "child"), new DefaultElementInterceptor()
+      {
+         public void add(Object parent, Object child, QName qName)
+         {
+            Parent1 parent1 = (Parent1) parent;
+            Child c = (Child) child;
+            c.string = c.string + "Parent1";
+            parent1.child = c;
+         }
+      });
+      
+      classMetaData = new ClassMetaData();
+      classMetaData.setImpl(Parent2.class.getName());
+      TypeBinding parent2Type = schema.getType(new QName(NS, "parent2Type"));
+      assertNotNull(parent2Type);
+      parent2Type.setClassMetaData(classMetaData);
+
+      parent2Type.pushInterceptor(new QName(NS, "child"), new DefaultElementInterceptor()
+      {
+         public void add(Object parent, Object child, QName qName)
+         {
+            fail("Should not invoke interceptor added to parent2Type when processing parent1!"); 
+         }
+      });
+
+      classMetaData = new ClassMetaData();
+      classMetaData.setImpl(Child.class.getName());
+      TypeBinding childType = schema.getType(new QName(NS, "childType"));
+      assertNotNull(childType);
+      childType.setClassMetaData(classMetaData);
+
+      Parent1 parent1 = (Parent1) unmarshal("DuplicateInterceptor.xml", schema, Parent1.class);
+      assertNotNull(parent1.child);
+      assertEquals("HelloParent1", parent1.child.string);
+   }
+   
+   public static class Parent1
+   {
+      public Child child;
+   }
+   
+   public static class Parent2
+   {
+      public Child child;
+   }
+   
+   public static class Child
+   {
+      public String string;
+   }
+}

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/DuplicateInterceptor.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/DuplicateInterceptor.xml	2006-11-16 00:36:47 UTC (rev 2160)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/DuplicateInterceptor.xml	2006-11-16 15:38:02 UTC (rev 2161)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<parent1 xmlns='http://www.jboss.org/test/xml/duplicateInterceptor'>
+   <child><string>Hello</string></child>
+</parent1>

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/DuplicateInterceptor.xsd
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/DuplicateInterceptor.xsd	2006-11-16 00:36:47 UTC (rev 2160)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/DuplicateInterceptor.xsd	2006-11-16 15:38:02 UTC (rev 2161)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+            targetNamespace="http://www.jboss.org/test/xml/duplicateInterceptor"
+            xmlns="http://www.jboss.org/test/xml/duplicateInterceptor"
+            elementFormDefault="qualified"
+            attributeFormDefault="unqualified"
+            version="1.0">
+
+   <xsd:element name="parent1" type="parent1Type"/>
+
+   <xsd:complexType name="parent1Type">
+      <xsd:sequence>
+         <xsd:element ref="child"/>
+      </xsd:sequence>
+   </xsd:complexType>
+
+   <xsd:element name="parent2" type="parent2Type"/>
+
+   <xsd:complexType name="parent2Type">
+      <xsd:sequence>
+         <xsd:element ref="child"/>
+      </xsd:sequence>
+   </xsd:complexType>
+
+   <xsd:element name="child" type="childType"/>
+
+   <xsd:complexType name="childType">
+      <xsd:sequence>
+         <xsd:element name="string" type="xsd:string"/>
+      </xsd:sequence>
+   </xsd:complexType>
+   
+</xsd:schema>




More information about the jboss-svn-commits mailing list