summaryrefslogtreecommitdiffstats
path: root/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-10-31 16:20:08 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-10-31 16:20:08 +0000
commit3bc574a9a7afef72e31647186d5050edd1e1c80d (patch)
tree90e5ab2b67cb8c211029084750e64baafd5dc2dc /branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca
parent39114ad6c744de09a65c5a48065b9658c3a93040 (diff)
Clean dependencies
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@709460 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/BeanXMLStreamReaderImpl.java324
-rw-r--r--branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2XMLStreamReader.java84
-rw-r--r--branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.java55
-rw-r--r--branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java (renamed from branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java.fixme)46
-rw-r--r--branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java49
5 files changed, 14 insertions, 544 deletions
diff --git a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/BeanXMLStreamReaderImpl.java b/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/BeanXMLStreamReaderImpl.java
deleted file mode 100644
index 602bc66569..0000000000
--- a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/BeanXMLStreamReaderImpl.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * 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.tuscany.sca.databinding.jaxb;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.xml.namespace.QName;
-
-import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
-import org.apache.tuscany.sca.databinding.xml.SimpleXmlNodeImpl;
-import org.apache.tuscany.sca.databinding.xml.XmlNode;
-import org.apache.tuscany.sca.databinding.xml.XmlTreeStreamReaderImpl;
-import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
-import org.jvnet.jaxb.reflection.model.annotation.RuntimeInlineAnnotationReader;
-import org.jvnet.jaxb.reflection.model.core.Ref;
-import org.jvnet.jaxb.reflection.model.impl.RuntimeModelBuilder;
-import org.jvnet.jaxb.reflection.model.runtime.RuntimeClassInfo;
-import org.jvnet.jaxb.reflection.model.runtime.RuntimePropertyInfo;
-import org.jvnet.jaxb.reflection.model.runtime.RuntimeTypeInfoSet;
-import org.jvnet.jaxb.reflection.runtime.IllegalAnnotationsException;
-import org.jvnet.jaxb.reflection.runtime.JAXBContextImpl;
-
-
-
-/**
- * @version $Rev$ $Date$
- */
-public class BeanXMLStreamReaderImpl extends XmlTreeStreamReaderImpl {
- private static final Comparator<Accessor> COMPARATOR = new Comparator<Accessor>() {
- public int compare(Accessor o1, Accessor o2) {
- return o1.getName().compareTo(o2.getName());
- }
- };
-
- private static final String XSI_PREFIX = "xsi";
- private static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
-
- private static XmlNode getXSIType(QName realType) {
- QName xsiType = new QName(XSI_NS, "type", XSI_PREFIX);
- String prefix = realType.getPrefix();
- String typeName = realType.getLocalPart();
- if (prefix != null && !prefix.equals("")) {
- typeName = prefix + ":" + realType.getLocalPart();
- }
- return new SimpleXmlNodeImpl(xsiType, XmlNode.Type.ATTRIBUTE);
- }
-
- /**
- * Represent a Map.Entry XML node
- * @version $Rev$ $Date$
- */
- public static class MapEntryXmlNodeImpl extends SimpleXmlNodeImpl implements XmlNode {
- private Map.Entry entry;
-
- public MapEntryXmlNodeImpl(Entry entry) {
- super(new QName("", "entry"), entry);
- this.entry = entry;
- }
-
- @Override
- public Iterator<XmlNode> children() {
- List<XmlNode> nodes = new ArrayList<XmlNode>();
- XmlNode key = new BeanXmlNodeImpl(new QName("", "key"), entry.getKey());
- XmlNode value = new BeanXmlNodeImpl(new QName("", "value"), entry.getValue());
- nodes.add(key);
- nodes.add(value);
- return nodes.iterator();
- }
- }
-
- public static class BeanXmlNodeImpl extends SimpleXmlNodeImpl implements XmlNode {
- private static final Object[] NULL = null;
- private static final SimpleTypeMapperImpl MAPPER = new SimpleTypeMapperImpl();
-
- public BeanXmlNodeImpl(Object bean) {
- super(getName(bean == null ? null : bean.getClass()), bean);
- }
-
- public BeanXmlNodeImpl(QName name, Object bean) {
- super(name, bean);
- }
-
- private static boolean isSimpleType(Class<?> javaType) {
- return SimpleTypeMapperImpl.getXMLType(javaType) != null;
- }
-
- private static String getStringValue(Object o) {
- if (o == null) {
- return null;
- }
- TypeInfo info = SimpleTypeMapperImpl.getXMLType(o.getClass());
- if (info != null) {
- return MAPPER.toXMLLiteral(info.getQName(), o, null);
- } else {
- return String.valueOf(o);
- }
- }
-
- @Override
- public Iterator<XmlNode> children() {
- if (name == null) {
- return null;
- }
- if (value == null) {
- return super.children();
- }
- if (isSimpleType(value.getClass())) {
- XmlNode textNode = new BeanXmlNodeImpl(null, value);
- return Arrays.asList(textNode).iterator();
- }
- if (Map.class.isAssignableFrom(value.getClass())) {
- List<XmlNode> entries = new ArrayList<XmlNode>();
- Map map = (Map)value;
- if (map != null) {
- for (Object e : map.entrySet()) {
- Map.Entry entry = (Map.Entry)e;
- entries.add(new MapEntryXmlNodeImpl(entry));
- }
- }
- return entries.iterator();
- }
- try {
- Map<String, Accessor> accessorMap = getAccessors(value);
- List<Accessor> accessorList = new ArrayList<Accessor>(accessorMap.values());
- Collections.sort(accessorList, COMPARATOR);
-
- List<XmlNode> props = new ArrayList<XmlNode>();
- for (Accessor accessor : accessorList) {
- Class<?> pType = accessor.getType();
-
- QName pName = new QName(name.getNamespaceURI(), accessor.getName());
- Object pValue = accessor.getValue();
- if (pType.isArray()) {
- if (pValue != null) {
- int i1 = Array.getLength(pValue);
- for (int j = 0; j < i1; j++) {
- Object o = Array.get(pValue, j);
- props.add(new BeanXmlNodeImpl(pName, o));
- }
- } else {
- // TODO: How to handle null?
- }
- } else if (Collection.class.isAssignableFrom(pType)) {
- Collection objList = (Collection)pValue;
- if (objList != null && objList.size() > 0) {
- for (Iterator j = objList.iterator(); j.hasNext();) {
- Object o = j.next();
- props.add(new BeanXmlNodeImpl(pName, o));
- }
-
- } else {
- // How to handle null
- }
- } else {
- props.add(new BeanXmlNodeImpl(pName, pValue));
- }
- }
- return props.iterator();
- } catch (Exception e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- @Override
- public QName getName() {
- return name;
- }
-
- @Override
- public String getValue() {
- return getStringValue(value);
- }
-
- private static String getPackageName(Class<?> cls) {
- String name = cls.getName();
- int index = name.lastIndexOf('.');
- return index == -1 ? "" : name.substring(0, index);
- }
-
- public static QName getName(Class<?> cls) {
- if (cls == null) {
- return null;
- }
-
- String packageName = getPackageName(cls);
-
- if ("".equals(packageName)) {
- return new QName("", cls.getSimpleName());
- }
- StringBuffer ns = new StringBuffer("http://");
- String[] names = packageName.split("\\.");
- for (int i = names.length - 1; i >= 0; i--) {
- ns.append(names[i]);
- if (i != 0) {
- ns.append('.');
- }
- }
- ns.append('/');
- return new QName(ns.toString(), cls.getSimpleName());
- }
- }
-
- public BeanXMLStreamReaderImpl(QName name, Object bean) {
- super(getXmlNode(name, bean));
- }
-
- private static BeanXmlNodeImpl getXmlNode(QName name, Object bean) {
- BeanXmlNodeImpl root = null;
- if (name != null) {
- root = new BeanXmlNodeImpl(name, bean);
- } else {
- root = new BeanXmlNodeImpl(bean);
- }
- return root;
- }
-
- public static interface Accessor {
- String getName();
-
- Class<?> getType();
-
- Object getValue() throws Exception;
-
- void setValue(Object value) throws Exception;
- }
-
- private static RuntimeTypeInfoSet create(Class... classes) throws Exception {
- IllegalAnnotationsException.Builder errorListener = new IllegalAnnotationsException.Builder();
- RuntimeInlineAnnotationReader reader = new RuntimeInlineAnnotationReader();
- JAXBContextImpl context =
- new JAXBContextImpl(classes, null, Collections.<Class, Class> emptyMap(), null, false, reader, false, false);
- RuntimeModelBuilder builder =
- new RuntimeModelBuilder(context, reader, Collections.<Class, Class> emptyMap(), null);
- builder.setErrorHandler(errorListener);
- for (Class c : classes)
- builder.getTypeInfo(new Ref<Type, Class>(c));
-
- RuntimeTypeInfoSet r = builder.link();
- errorListener.check();
- return r;
- }
-
- private static class JAXBAccessor implements Accessor {
- private Object target;
- private RuntimePropertyInfo prop;
-
- public JAXBAccessor(Object target, RuntimePropertyInfo field) {
- super();
- this.target = target;
- this.prop = field;
- }
-
- public String getName() {
- return prop.getName();
- }
-
- public Object getValue() throws Exception {
- return prop.getAccessor().get(target);
- }
-
- public void setValue(Object value) throws Exception {
- prop.getAccessor().set(target, value);
- }
-
- public Class<?> getType() {
- Type type = prop.getRawType();
- if (type instanceof Class) {
- return (Class<?>)type;
- } else if (type instanceof ParameterizedType) {
- ParameterizedType pType = (ParameterizedType)type;
- type = pType.getRawType();
- if (type instanceof Class) {
- return (Class<?>)type;
- }
- }
- return Object.class;
- }
-
- }
-
- private static Map<String, Accessor> getAccessors(Object target) throws Exception {
- if (target == null) {
- return Collections.emptyMap();
- }
- Map<String, Accessor> map = new HashMap<String, Accessor>();
- Class<?> type = target.getClass();
- RuntimeTypeInfoSet set = create(type);
- RuntimeClassInfo clsInfo = (RuntimeClassInfo)set.getTypeInfo(type);
- for (RuntimePropertyInfo f : clsInfo.getProperties()) {
- map.put(f.getName(), new JAXBAccessor(target, f));
- }
- return map;
- }
-
-}
diff --git a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2XMLStreamReader.java b/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2XMLStreamReader.java
deleted file mode 100644
index e2151e23a1..0000000000
--- a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2XMLStreamReader.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.tuscany.sca.databinding.jaxb;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.tuscany.sca.databinding.PullTransformer;
-import org.apache.tuscany.sca.databinding.TransformationContext;
-import org.apache.tuscany.sca.databinding.TransformationException;
-import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
-
-/**
- *
- * @version $Rev$ $Date$
- */
-public class JAXB2XMLStreamReader extends BaseTransformer<Object, XMLStreamReader> implements
- PullTransformer<Object, XMLStreamReader> {
-
- public JAXB2XMLStreamReader() {
- super();
- }
-
- public XMLStreamReader transform(Object source, TransformationContext context) {
- if (source == null) {
- return null;
- }
- try {
- QName name = null;
- Object bean = null;
- if (source instanceof JAXBElement) {
- bean = ((JAXBElement)source).getValue();
- name = ((JAXBElement)source).getName();
- } else {
- JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, true);
- Object element = JAXBContextHelper.createJAXBElement(jaxbContext, context.getSourceDataType(), source);
- name = jaxbContext.createJAXBIntrospector().getElementName(element);
- bean = source;
- }
- BeanXMLStreamReaderImpl reader = new BeanXMLStreamReaderImpl(name, bean);
- return reader;
- } catch (Exception e) {
- throw new TransformationException(e);
- }
- }
-
- @Override
- protected Class<Object> getSourceType() {
- return Object.class;
- }
-
- @Override
- protected Class<XMLStreamReader> getTargetType() {
- return XMLStreamReader.class;
- }
-
- @Override
- public int getWeight() {
- return 10;
- }
-
- @Override
- public String getTargetDataBinding() {
- return JAXBDataBinding.NAME;
- }
-}
diff --git a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.java b/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.java
index cbc32d4353..74f124f892 100644
--- a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.java
+++ b/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.java
@@ -19,32 +19,13 @@
package org.apache.tuscany.sca.databinding.jaxb;
-import java.lang.reflect.Type;
-import java.util.Collections;
-
import javax.xml.bind.JAXBContext;
-import javax.xml.namespace.QName;
-import junit.framework.Assert;
import junit.framework.TestCase;
-import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper;
import org.apache.tuscany.sca.databinding.xml.Node2String;
-import org.jvnet.jaxb.reflection.model.annotation.RuntimeInlineAnnotationReader;
-import org.jvnet.jaxb.reflection.model.core.Ref;
-import org.jvnet.jaxb.reflection.model.impl.RuntimeModelBuilder;
-import org.jvnet.jaxb.reflection.model.runtime.RuntimeClassInfo;
-import org.jvnet.jaxb.reflection.model.runtime.RuntimePropertyInfo;
-import org.jvnet.jaxb.reflection.model.runtime.RuntimeTypeInfoSet;
-import org.jvnet.jaxb.reflection.runtime.IllegalAnnotationsException;
-import org.jvnet.jaxb.reflection.runtime.JAXBContextImpl;
import org.w3c.dom.Node;
-import com.example.ipo.jaxb.ObjectFactory;
-import com.example.ipo.jaxb.PurchaseOrderType;
-import com.example.ipo.jaxb.USAddress;
-import com.example.ipo.jaxb.USState;
-
/**
* @version $Rev$ $Date$
*/
@@ -55,40 +36,4 @@ public class JAXBReflectionTestCase extends TestCase {
Node schema = JAXBContextHelper.generateSchema(context);
System.out.println(new Node2String().transform(schema, null));
}
-
- /**
- * This is a workaround for the NPE bug in jaxb-reflection
- * @param classes
- * @return
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- private static RuntimeTypeInfoSet create(Class... classes) throws Exception {
- IllegalAnnotationsException.Builder errorListener = new IllegalAnnotationsException.Builder();
- RuntimeInlineAnnotationReader reader = new RuntimeInlineAnnotationReader();
- JAXBContextImpl context =
- new JAXBContextImpl(classes, null, Collections.<Class, Class> emptyMap(), null, false, reader, false, false);
- RuntimeModelBuilder builder =
- new RuntimeModelBuilder(context, reader, Collections.<Class, Class> emptyMap(), null);
- builder.setErrorHandler(errorListener);
- for (Class c : classes)
- builder.getTypeInfo(new Ref<Type, Class>(c));
-
- RuntimeTypeInfoSet r = builder.link();
- errorListener.check();
- return r;
- }
-
- public void testReflection() throws Exception {
- org.jvnet.jaxb.reflection.model.runtime.RuntimeTypeInfoSet model = create(PurchaseOrderType.class);
- RuntimeClassInfo type = (RuntimeClassInfo)model.getTypeInfo(PurchaseOrderType.class);
- Assert.assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), type.getTypeName());
- type = (RuntimeClassInfo)model.getTypeInfo(USAddress.class);
- Assert.assertEquals(new QName("http://www.example.com/IPO", "USAddress"), type.getTypeName());
- RuntimePropertyInfo prop = type.getProperty("state");
- Assert.assertNotNull(prop);
- USAddress address = new ObjectFactory().createUSAddress();
- prop.getAccessor().set(address, USState.CA);
- Assert.assertEquals(USState.CA, address.getState());
- }
}
diff --git a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java.fixme b/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java
index 53779a1af6..8780b788af 100644
--- a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java.fixme
+++ b/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java
@@ -18,10 +18,6 @@
*/
package org.apache.tuscany.sca.databinding.jaxb;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-
import java.io.StringReader;
import javax.xml.namespace.QName;
@@ -30,9 +26,7 @@ import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.tuscany.sca.databinding.TransformationContext;
-import org.apache.tuscany.sca.databinding.jaxb.JAXB2Node;
-import org.apache.tuscany.sca.databinding.jaxb.Node2JAXB;
-import org.apache.tuscany.sca.databinding.jaxb.Reader2JAXB;
+import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl;
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
import org.apache.tuscany.sca.interfacedef.util.XMLType;
@@ -86,21 +80,15 @@ public class JAXBTestCase extends TestCase {
DataType targetDataType = new DataTypeImpl<Class>(PurchaseOrderType.class, null);
- TransformationContext tContext = createMock(TransformationContext.class);
- expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes();
- expect(tContext.getTargetOperation()).andReturn(null).anyTimes();
- replay(tContext);
+ TransformationContext tContext = new TransformationContextImpl();
+ tContext.setTargetDataType(targetDataType);
Object object1 = t0.transform(new StringReader(IPO_XML), tContext);
DataType sourceDataType = new DataTypeImpl<Class>(PurchaseOrderType.class, null);
- TransformationContext tContext1 = createMock(TransformationContext.class);
- expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes();
- expect(tContext1.getTargetDataType()).andReturn(null).anyTimes();
- expect(tContext1.getSourceOperation()).andReturn(null).anyTimes();
- expect(tContext1.getTargetOperation()).andReturn(null).anyTimes();
- replay(tContext1);
+ TransformationContext tContext1 = new TransformationContextImpl();
+ tContext1.setSourceDataType(sourceDataType);
JAXB2Node t1 = new JAXB2Node();
Node node = t1.transform(object1, tContext1);
@@ -120,22 +108,15 @@ public class JAXBTestCase extends TestCase {
DataType targetDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, new XMLType(root, null));
// targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath);
- TransformationContext tContext = createMock(TransformationContext.class);
- expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes();
- expect(tContext.getTargetOperation()).andReturn(null).anyTimes();
- replay(tContext);
-
+ TransformationContext tContext = new TransformationContextImpl();
+ tContext.setTargetDataType(targetDataType);
Object object1 = t0.transform(new StringReader(IPO_XML), tContext);
DataType sourceDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, new XMLType(root, null));
// sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath);
- TransformationContext tContext1 = createMock(TransformationContext.class);
- expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes();
- expect(tContext1.getTargetDataType()).andReturn(null).anyTimes();
- expect(tContext1.getSourceOperation()).andReturn(null).anyTimes();
- expect(tContext1.getTargetOperation()).andReturn(null).anyTimes();
- replay(tContext1);
+ TransformationContext tContext1 = new TransformationContextImpl();
+ tContext1.setSourceDataType(sourceDataType);
JAXB2Node t1 = new JAXB2Node();
Node node = t1.transform(object1, tContext1);
@@ -152,12 +133,9 @@ public class JAXBTestCase extends TestCase {
DataType sourceDataType = new DataTypeImpl<Class>(PurchaseOrderType.class, null);
- TransformationContext tContext1 = createMock(TransformationContext.class);
- expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes();
- expect(tContext1.getTargetDataType()).andReturn(null).anyTimes();
- expect(tContext1.getSourceOperation()).andReturn(null).anyTimes();
- expect(tContext1.getTargetOperation()).andReturn(null).anyTimes();
- replay(tContext1);
+ TransformationContext tContext1 = new TransformationContextImpl();
+ tContext1.setSourceDataType(sourceDataType);
+
JAXB2Node t1 = new JAXB2Node();
PurchaseOrderType po = new ObjectFactory().createPurchaseOrderType();
diff --git a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java b/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java
index 0a3d64a705..2603412a9d 100644
--- a/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java
+++ b/branches/sca-equinox/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java
@@ -20,30 +20,14 @@ package org.apache.tuscany.sca.databinding.jaxb;
import java.io.StringReader;
import java.io.StringWriter;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Collections;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
-import org.apache.tuscany.sca.databinding.TransformationContext;
-import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl;
-import org.apache.tuscany.sca.databinding.jaxb.JAXB2XMLStreamReader;
-
-import com.sun.xml.bind.v2.model.annotation.RuntimeInlineAnnotationReader;
-import com.sun.xml.bind.v2.model.core.Ref;
-import com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder;
-import com.sun.xml.bind.v2.model.runtime.RuntimeClassInfo;
-import com.sun.xml.bind.v2.model.runtime.RuntimePropertyInfo;
-import com.sun.xml.bind.v2.model.runtime.RuntimeTypeInfoSet;
-import com.sun.xml.bind.v2.runtime.IllegalAnnotationsException;
-import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
/**
*
@@ -101,6 +85,7 @@ public class POJOTestCase extends TestCase {
assertFalse(newBean instanceof MySubBean);
}
+ /*
public void testXMLStreamReader() throws Exception {
JAXBContext context = JAXBContext.newInstance(MyBean.class, MyInterfaceImpl.class);
@@ -130,6 +115,7 @@ public class POJOTestCase extends TestCase {
// FIXME :To be implemented
// assertEquals(bean, newBean);
}
+ */
public void testString() throws Exception {
JAXBContext context = JAXBContext.newInstance(String.class);
@@ -216,35 +202,4 @@ public class POJOTestCase extends TestCase {
assertTrue(e2.getValue() instanceof Exception);
}
*/
-
- private static RuntimeTypeInfoSet create(Class... classes) throws Exception {
- IllegalAnnotationsException.Builder errorListener = new IllegalAnnotationsException.Builder();
- RuntimeInlineAnnotationReader reader = new RuntimeInlineAnnotationReader();
- JAXBContextImpl context =
- new JAXBContextImpl(classes, null, Collections.<Class, Class> emptyMap(), null, false, reader, false, false);
- RuntimeModelBuilder builder =
- new RuntimeModelBuilder(context, reader, Collections.<Class, Class> emptyMap(), null);
- builder.setErrorHandler(errorListener);
- for (Class c : classes)
- builder.getTypeInfo(new Ref<Type, Class>(c));
-
- RuntimeTypeInfoSet r = builder.link();
- errorListener.check();
- return r;
- }
-
- public void testReflection() throws Exception {
- MyBean bean = new MyBean();
- RuntimeTypeInfoSet model = create(MyBean.class);
- RuntimeClassInfo clsInfo = (RuntimeClassInfo)model.getTypeInfo(MyBean.class);
- for (RuntimePropertyInfo p : clsInfo.getProperties()) {
- // System.out.print(p.getName());
- // System.out.println(" " + p.isCollection());
- if (p.getName().equals("notes")) {
- Collection c = (Collection)p.getAccessor().get(bean);
- c.add("123");
- }
- }
-
- }
}