cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r1004494 - in /cxf/trunk/rt/frontend/jaxrs/src/test: java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java resources/org/apache/cxf/jaxrs/provider/jsonCases.xml
Date Tue, 05 Oct 2010 00:57:48 GMT
Author: bimargulies
Date: Tue Oct  5 00:57:48 2010
New Revision: 1004494

URL: http://svn.apache.org/viewvc?rev=1004494&view=rev
Log:
Add a test case for Aegis JAX-RS with unqualified elements

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/resources/org/apache/cxf/jaxrs/provider/jsonCases.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java?rev=1004494&r1=1004493&r2=1004494&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
Tue Oct  5 00:57:48 2010
@@ -40,45 +40,47 @@ import org.junit.Before;
 import org.junit.Test;
 
 public class AegisElementProviderTest extends Assert {
-    
+
     private Properties properties;
     private String simpleBeanXml;
-    
+    private String noNamespaceXml;
+
     @Before
     public void before() throws InvalidPropertiesFormatException, IOException {
         properties = new Properties();
         properties.loadFromXML(getClass().getResourceAsStream("jsonCases.xml"));
         simpleBeanXml = properties.getProperty("simpleBeanXml");
+        noNamespaceXml = properties.getProperty("noNamespaceBeanXml");
     }
-    
+
     @After
     public void clearCache() {
         AbstractAegisProvider.clearContexts();
     }
-    
+
     @Test
     public void testIsWriteable() {
         MessageBodyWriter<Object> p = new AegisElementProvider<Object>();
         assertTrue(p.isWriteable(AegisTestBean.class, null, null, null));
     }
-    
+
     @Test
     public void testIsReadable() {
         MessageBodyReader<Object> p = new AegisElementProvider<Object>();
         assertTrue(p.isReadable(AegisTestBean.class, null, null, null));
     }
-    
-    
+
+
     @Test
     public void testReadFrom() throws Exception {
         MessageBodyReader<AegisTestBean> p = new AegisElementProvider<AegisTestBean>();
         byte[] simpleBytes = simpleBeanXml.getBytes("utf-8");
-        AegisTestBean bean = p.readFrom(AegisTestBean.class, null, null, 
+        AegisTestBean bean = p.readFrom(AegisTestBean.class, null, null,
                                           null, null, new ByteArrayInputStream(simpleBytes));
         assertEquals("hovercraft", bean.getStrValue());
         assertEquals(Boolean.TRUE, bean.getBoolValue());
     }
-    
+
     @Test
     public void testWriteTo() throws Exception {
         MessageBodyWriter<Object> p = new AegisElementProvider<Object>();
@@ -91,13 +93,25 @@ public class AegisElementProviderTest ex
         String xml = new String(bytes, "utf-8");
         assertEquals(simpleBeanXml, xml);
     }
-    
-    
+
+    @Test
+    public void testNoNamespaceWriteTo() throws Exception {
+        MessageBodyWriter<Object> p = new NoNamespaceAegisElementProvider();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        AegisTestBean bean = new AegisTestBean();
+        bean.setBoolValue(Boolean.TRUE);
+        bean.setStrValue("hovercraft");
+        p.writeTo(bean, null, null, null, null, null, os);
+        byte[] bytes = os.toByteArray();
+        String xml = new String(bytes, "utf-8");
+        assertEquals(noNamespaceXml, xml);
+    }
+
     @Test
     public void testReadWriteComplexMap() throws Exception {
-        Map<AegisTestBean, AegisSuperBean> testMap = 
+        Map<AegisTestBean, AegisSuperBean> testMap =
             new HashMap<AegisTestBean, AegisSuperBean>();
-        
+
         Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
         Method method = iwithMapClass.getMethod("mapFunction");
         Type mapType = method.getGenericReturnType();
@@ -105,24 +119,24 @@ public class AegisElementProviderTest ex
         AegisTestBean bean = new AegisTestBean();
         bean.setBoolValue(Boolean.TRUE);
         bean.setStrValue("hovercraft");
-        
+
         AegisSuperBean bean2 = new AegisSuperBean();
         bean2.setBoolValue(Boolean.TRUE);
         bean2.setStrValue("hovercraft2");
         testMap.put(bean, bean2);
-        
-        MessageBodyWriter<Map<AegisTestBean, AegisSuperBean>> writer 
+
+        MessageBodyWriter<Map<AegisTestBean, AegisSuperBean>> writer
             = new AegisElementProvider<Map<AegisTestBean, AegisSuperBean>>();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        
+
         writer.writeTo(testMap, testMap.getClass(), mapType, null, null, null, os);
         byte[] bytes = os.toByteArray();
         String xml = new String(bytes, "utf-8");
-        MessageBodyReader<Map<AegisTestBean, AegisSuperBean>> reader 
-            = new AegisElementProvider<Map<AegisTestBean, AegisSuperBean>>();
        
+        MessageBodyReader<Map<AegisTestBean, AegisSuperBean>> reader
+            = new AegisElementProvider<Map<AegisTestBean, AegisSuperBean>>();
         byte[] simpleBytes = xml.getBytes("utf-8");
-        
-        Map<AegisTestBean, AegisSuperBean> map2 = reader.readFrom(null, mapType, null,

+
+        Map<AegisTestBean, AegisSuperBean> map2 = reader.readFrom(null, mapType, null,
                                           null, null, new ByteArrayInputStream(simpleBytes));
         assertEquals(1, map2.size());
         Map.Entry<AegisTestBean, AegisSuperBean> entry = map2.entrySet().iterator().next();
@@ -132,14 +146,14 @@ public class AegisElementProviderTest ex
         AegisTestBean bean22 = entry.getValue();
         assertEquals("hovercraft2", bean22.getStrValue());
         assertEquals(Boolean.TRUE, bean22.getBoolValue());
-        
+
     }
-    
+
     public static class AegisSuperBean extends AegisTestBean {
     }
-    
+
     private static interface InterfaceWithMap {
         Map<AegisTestBean, AegisSuperBean> mapFunction();
     }
-    
+
 }

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java?rev=1004494&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java
Tue Oct  5 00:57:48 2010
@@ -0,0 +1,51 @@
+/**
+ * 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.cxf.jaxrs.provider;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.cxf.aegis.AegisContext;
+import org.apache.cxf.aegis.type.TypeCreationOptions;
+
+/**
+ * Class that sets options to disable xml namespaces.
+ */
+class NoNamespaceAegisElementProvider extends AegisElementProvider<Object> {
+    /*
+     * This can't use the cache in AbstractAegisProvider. It could have its own cache.
+     */
+
+    @Override
+    protected AegisContext getAegisContext(Class<?> plainClass, Type genericType) {
+        AegisContext context = new AegisContext();
+        context.setWriteXsiTypes(writeXsiType);
+        context.setReadXsiTypes(readXsiType);
+        TypeCreationOptions tco = new TypeCreationOptions();
+        tco.setQualifyElements(false);
+        Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
+        rootClasses.add(genericType);
+        context.setTypeCreationOptions(tco);
+        context.setRootClasses(rootClasses);
+        context.initialize();
+        return context;
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/resources/org/apache/cxf/jaxrs/provider/jsonCases.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/resources/org/apache/cxf/jaxrs/provider/jsonCases.xml?rev=1004494&r1=1004493&r2=1004494&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/resources/org/apache/cxf/jaxrs/provider/jsonCases.xml
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/resources/org/apache/cxf/jaxrs/provider/jsonCases.xml
Tue Oct  5 00:57:48 2010
@@ -2,5 +2,6 @@
 <properties>
 <entry key="testReadWriteComplexMap.expected">{"ns1.AegisTestBean2AegisSuperBeanMap":{"@xsi.type":"ns1:AegisTestBean2AegisSuperBeanMap","ns1.entry":{"ns1.key":{"@xsi.type":"ns2:AegisTestBean","ns2.boolValue":true,"ns2.strValue":"hovercraft"},"ns1.value":{"@xsi.type":"ns2:AegisSuperBean","ns2.boolValue":true,"ns2.strValue":"hovercraft2"}}}}</entry>
 <entry key="simpleBeanXml">&lt;?xml version='1.0' encoding='UTF-8'?&gt;<![CDATA[<ns1:AegisTestBean
xmlns:ns1="http://fortest.jaxrs.cxf.apache.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns1:AegisTestBean"><ns1:boolValue>true</ns1:boolValue><ns1:strValue>hovercraft</ns1:strValue></ns1:AegisTestBean>]]></entry>
+<entry key="noNamespaceBeanXml">&lt;?xml version='1.0' encoding='UTF-8'?&gt;<![CDATA[<ns1:AegisTestBean
xmlns:ns1="http://fortest.jaxrs.cxf.apache.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns1:AegisTestBean"><boolValue>true</boolValue><strValue>hovercraft</strValue></ns1:AegisTestBean>]]></entry>
 <entry key="testAegisWriteXml"><![CDATA[<ns1:Book xmlns:ns1="http://resources.jaxrs.cxf.apache.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:Book"><ns1:id>127</ns1:id><ns1:name>CXF</ns1:name><ns1:state></ns1:state></ns1:Book>]]></entry>
 </properties>
\ No newline at end of file



Mime
View raw message