[jboss-cvs] JBossAS SVN: r70510 - projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 6 14:58:36 EST 2008
Author: adrian at jboss.org
Date: 2008-03-06 14:58:36 -0500 (Thu, 06 Mar 2008)
New Revision: 70510
Modified:
projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringSchemaTest.java
projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringSchemaTestDelegate.java
Log:
Use a local copy of the jbossxb test until jbossxb provides one
Modified: projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringSchemaTest.java
===================================================================
--- projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringSchemaTest.java 2008-03-06 19:50:59 UTC (rev 70509)
+++ projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringSchemaTest.java 2008-03-06 19:58:36 UTC (rev 70510)
@@ -21,13 +21,15 @@
*/
package org.jboss.test.spring.test;
+import java.net.URL;
+
+import org.jboss.test.AbstractTestCaseWithSetup;
import org.jboss.test.AbstractTestDelegate;
-import org.jboss.test.ioc.test.AbstractIoCTest;
/**
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class TempSpringSchemaTest extends AbstractIoCTest
+public class TempSpringSchemaTest extends AbstractTestCaseWithSetup
{
public TempSpringSchemaTest(String name)
@@ -36,6 +38,51 @@
}
/**
+ * Unmarshal some xml
+ *
+ * @param <T> the expected type
+ * @param name the name
+ * @param expected the expected type
+ * @return the unmarshalled object
+ * @throws Exception for any error
+ */
+ protected <T> T unmarshal(String name, Class<T> expected) throws Exception
+ {
+ Object object = unmarshal(name);
+ if (object == null)
+ fail("No object from " + name);
+ assertTrue("Object '" + object + "' cannot be assigned to " + expected.getName(), expected.isAssignableFrom(object.getClass()));
+ return expected.cast(object);
+ }
+
+ /**
+ * Unmarshal some xml
+ *
+ * @param name the name
+ * @return the unmarshalled object
+ * @throws Exception for any error
+ */
+ protected Object unmarshal(String name) throws Exception
+ {
+ String url = findXML(name);
+ return getJBossXBDelegate().unmarshal(url);
+ }
+
+ /**
+ * Find the xml
+ *
+ * @param name the name
+ * @return the url of the xml
+ */
+ protected String findXML(String name)
+ {
+ URL url = getResource(name);
+ if (url == null)
+ fail(name + " not found");
+ return url.toString();
+ }
+
+ /**
* Setup the test delegate
*
* @param clazz the class
@@ -47,4 +94,34 @@
return new TempSpringSchemaTestDelegate(clazz);
}
+ protected TempSpringSchemaTestDelegate getJBossXBDelegate()
+ {
+ return (TempSpringSchemaTestDelegate) getDelegate();
+ }
+
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ configureLogging();
+ }
+
+ /**
+ * Get the package root name
+ *
+ * @return the root name
+ */
+ protected String getRootName()
+ {
+ String longName = getClass().getName();
+ int dot = longName.lastIndexOf('.');
+ if (dot != -1)
+ return longName.substring(dot + 1);
+ return longName;
+ }
+
+ protected void configureLogging()
+ {
+ //enableTrace("org.jboss.xb");
+ }
}
Modified: projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringSchemaTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringSchemaTestDelegate.java 2008-03-06 19:50:59 UTC (rev 70509)
+++ projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringSchemaTestDelegate.java 2008-03-06 19:58:36 UTC (rev 70510)
@@ -22,15 +22,24 @@
package org.jboss.test.spring.test;
import org.jboss.spring.deployment.xml.SpringSchemaInitializer;
-import org.jboss.test.ioc.test.IoCTestDelegate;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
/**
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class TempSpringSchemaTestDelegate extends IoCTestDelegate
+public class TempSpringSchemaTestDelegate extends AbstractTestDelegate
{
+ /** The unmarshaller factory */
+ protected UnmarshallerFactory unmarshallerFactory;
+ /** The resolver */
+ protected SchemaBindingResolver resolver;
+
public TempSpringSchemaTestDelegate(Class<?> clazz)
{
super(clazz);
@@ -39,10 +48,37 @@
public void setUp() throws Exception
{
super.setUp();
+ unmarshallerFactory = UnmarshallerFactory.newInstance();
+ resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
DefaultSchemaResolver defaultSchemaResolver = (DefaultSchemaResolver) resolver;
defaultSchemaResolver.addSchemaInitializer("urn:jboss:spring-beans:2.0", new SpringSchemaInitializer());
defaultSchemaResolver.addSchemaLocation("urn:jboss:spring-beans:2.0", "mc-spring-beans_2_0.xsd");
defaultSchemaResolver.addSchemaParseAnnotations("urn:jboss:spring-beans:2.0", Boolean.FALSE);
}
+
+ /**
+ * Unmarshal an object
+ *
+ * @param url the url
+ * @return the object
+ * @throws Exception for any error
+ */
+ public Object unmarshal(String url) throws Exception
+ {
+ long start = System.currentTimeMillis();
+ Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+ log.debug("Initialized parsing in " + (System.currentTimeMillis() - start) + "ms");
+ try
+ {
+ Object result = unmarshaller.unmarshal(url, resolver);
+ log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
+ return result;
+ }
+ catch (Exception e)
+ {
+ log.debug("Error during parsing: " + url, e);
+ throw e;
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list