You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2008/09/26 14:01:20 UTC

svn commit: r699289 - in /cxf/trunk/rt/javascript/src/test: java/org/apache/cxf/javascript/fortest/ java/org/apache/cxf/javascript/types/ resources/

Author: bimargulies
Date: Fri Sep 26 05:01:20 2008
New Revision: 699289

URL: http://svn.apache.org/viewvc?rev=699289&view=rev
Log:
Some preliminary work on attributes.

Added:
    cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestBean.java   (with props)
    cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestService.java   (with props)
    cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestServiceImpl.java   (with props)
    cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/AttributeTest.java   (with props)
    cxf/trunk/rt/javascript/src/test/resources/attributeTestBeans.xml   (with props)
    cxf/trunk/rt/javascript/src/test/resources/attributeTests.js   (with props)

Added: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestBean.java?rev=699289&view=auto
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestBean.java (added)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestBean.java Fri Sep 26 05:01:20 2008
@@ -0,0 +1,45 @@
+/**
+ * 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.javascript.fortest;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * 
+ */
+@XmlRootElement(namespace = "uri:org.apache.cxf.javascript.testns")
+@XmlType(namespace = "uri:org.apache.cxf.javascript.testns")
+public class AttributeTestBean {
+    
+    //CHECKSTYLE:OFF
+    @XmlElement
+    public String element1;
+    @XmlAttribute
+    public String attribute1;
+    @XmlElement
+    public String element2;
+    @XmlAttribute
+    public String attribute2;
+    //CHECKSTYLE:ON
+
+}

Propchange: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestService.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestService.java?rev=699289&view=auto
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestService.java (added)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestService.java Fri Sep 26 05:01:20 2008
@@ -0,0 +1,31 @@
+/**
+ * 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.javascript.fortest;
+
+import javax.jws.WebService;
+
+/**
+ * 
+ */
+@WebService(name = "AttributeTestService", targetNamespace = "uri:cxf.apache.org.javascript.attribute")
+public interface AttributeTestService {
+    AttributeTestBean returnAtrributeBean();
+    void acceptAttributeTestBean(AttributeTestBean atb);
+}

Propchange: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestServiceImpl.java?rev=699289&view=auto
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestServiceImpl.java (added)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestServiceImpl.java Fri Sep 26 05:01:20 2008
@@ -0,0 +1,46 @@
+/**
+ * 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.javascript.fortest;
+
+/**
+ * 
+ */
+public class AttributeTestServiceImpl implements AttributeTestService {
+    private AttributeTestBean acceptedAttributeTestBean;
+    
+    public void acceptAttributeTestBean(AttributeTestBean atb) {
+        acceptedAttributeTestBean = atb;
+        
+    }
+
+    public AttributeTestBean returnAtrributeBean() {
+        AttributeTestBean atb = new AttributeTestBean();
+        atb.attribute1 = "A1";
+        atb.attribute2 = "A2";
+        atb.element1 = "E1";
+        atb.element2 = "E2";
+        return atb;
+    }
+
+    public AttributeTestBean getAcceptedAttributeTestBean() {
+        return acceptedAttributeTestBean;
+    }
+
+}

Propchange: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/AttributeTestServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/AttributeTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/AttributeTest.java?rev=699289&view=auto
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/AttributeTest.java (added)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/AttributeTest.java Fri Sep 26 05:01:20 2008
@@ -0,0 +1,197 @@
+/**
+ * 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.javascript.types;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.databinding.DataReader;
+import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.javascript.BasicNameManager;
+import org.apache.cxf.javascript.JavascriptTestUtilities;
+import org.apache.cxf.javascript.NameManager;
+import org.apache.cxf.javascript.NamespacePrefixAccumulator;
+import org.apache.cxf.javascript.fortest.AttributeTestBean;
+import org.apache.cxf.javascript.fortest.TestBean1;
+import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.service.model.SchemaInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.test.AbstractCXFSpringTest;
+
+import org.junit.Test;
+import org.springframework.context.support.GenericApplicationContext;
+
+public class AttributeTest extends AbstractCXFSpringTest {
+    private JavascriptTestUtilities testUtilities;
+    private XMLInputFactory xmlInputFactory;
+    private XMLOutputFactory xmlOutputFactory;
+    private Client client;
+    private List<ServiceInfo> serviceInfos;
+    private Collection<SchemaInfo> schemata;
+    private NameManager nameManager;
+    private JaxWsProxyFactoryBean clientProxyFactory;
+
+    public AttributeTest() throws Exception {
+        testUtilities = new JavascriptTestUtilities(getClass());
+        testUtilities.addDefaultNamespaces();
+        xmlInputFactory = XMLInputFactory.newInstance();
+        xmlOutputFactory = XMLOutputFactory.newInstance();
+    }
+
+    @Override
+    protected String[] getConfigLocations() {
+        return new String[] {"classpath:attributeTestBeans.xml"};
+    }
+
+    @Test
+    public void testDeserialization() throws Exception {
+        setupClientAndRhino("attribute-test-proxy-factory");
+        testUtilities.readResourceIntoRhino("/attributeTests.js");
+        DataBinding dataBinding = new JAXBDataBinding(AttributeTestBean.class);
+        assertNotNull(dataBinding);
+        AttributeTestBean bean = new AttributeTestBean();
+        bean.element1 = "e1";
+        bean.element2 = "e2";
+        bean.attribute1 = "a1";
+        bean.attribute2 = "a2";
+
+        String serialized = serializeObject(dataBinding, bean);
+        testUtilities.rhinoCallInContext("deserializeAttributeTestBean", serialized);
+    }
+
+    private String serializeObject(DataBinding dataBinding, 
+                                   AttributeTestBean bean) throws XMLStreamException {
+        DataWriter<XMLStreamWriter> writer = dataBinding.createWriter(XMLStreamWriter.class);
+        StringWriter stringWriter = new StringWriter();
+        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
+        writer.write(bean, xmlStreamWriter);
+        xmlStreamWriter.flush();
+        xmlStreamWriter.close();
+        return stringWriter.toString();
+    }
+
+    @Test
+    @org.junit.Ignore
+    public void testSerialization() throws Exception {
+        setupClientAndRhino("simple-dlwu-proxy-factory");
+
+        testUtilities.readResourceIntoRhino("/serializationTests.js");
+        DataBinding dataBinding = clientProxyFactory.getServiceFactory().getDataBinding();
+        assertNotNull(dataBinding);
+
+        Object serialized = testUtilities.rhinoCallInContext("serializeTestBean1_1");
+        assertTrue(serialized instanceof String);
+        String xml = (String)serialized;
+        DataReader<XMLStreamReader> reader = dataBinding.createReader(XMLStreamReader.class);
+        StringReader stringReader = new StringReader(xml);
+        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
+        QName testBeanQName = new QName("uri:org.apache.cxf.javascript.testns", "TestBean1");
+        Object bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
+        assertNotNull(bean);
+        assertTrue(bean instanceof TestBean1);
+        TestBean1 testBean = (TestBean1)bean;
+        assertEquals("bean1<stringItem", testBean.stringItem);
+        assertEquals(64, testBean.intItem);
+        assertEquals(64000000, testBean.longItem);
+        assertEquals(101, testBean.optionalIntItem);
+        assertNotNull(testBean.optionalIntArrayItem);
+        assertEquals(1, testBean.optionalIntArrayItem.length);
+        assertEquals(543, testBean.optionalIntArrayItem[0]);
+
+        serialized = testUtilities.rhinoCallInContext("serializeTestBean1_2");
+        assertTrue(serialized instanceof String);
+        xml = (String)serialized;
+        reader = dataBinding.createReader(XMLStreamReader.class);
+        stringReader = new StringReader(xml);
+        xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
+        bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
+        assertNotNull(bean);
+        assertTrue(bean instanceof TestBean1);
+        testBean = (TestBean1)bean;
+        assertEquals("bean1<stringItem", testBean.stringItem);
+        assertEquals(64, testBean.intItem);
+        assertEquals(64000000, testBean.longItem);
+        assertEquals(0, testBean.optionalIntItem);
+        assertNotNull(testBean.optionalIntArrayItem);
+        assertEquals(3, testBean.optionalIntArrayItem.length);
+        assertEquals(543, testBean.optionalIntArrayItem[0]);
+        assertEquals(0, testBean.optionalIntArrayItem[1]);
+        assertEquals(345, testBean.optionalIntArrayItem[2]);
+
+        serialized = testUtilities.rhinoCallInContext("serializeTestBean1_3");
+        assertTrue(serialized instanceof String);
+        xml = (String)serialized;
+        reader = dataBinding.createReader(XMLStreamReader.class);
+        stringReader = new StringReader(xml);
+        xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
+        bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
+        assertNotNull(bean);
+        assertTrue(bean instanceof TestBean1);
+        testBean = (TestBean1)bean;
+        assertEquals("bean1<stringItem", testBean.stringItem);
+        assertEquals(64, testBean.intItem);
+        assertEquals(43, testBean.longItem);
+        assertEquals(33, testBean.optionalIntItem);
+        assertNull(testBean.optionalIntArrayItem);
+    }
+
+    private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException {
+        testUtilities.setBus(getBean(Bus.class, "cxf"));
+
+        testUtilities.initializeRhino();
+        testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");
+
+        clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
+        client = clientProxyFactory.getClientFactoryBean().create();
+        serviceInfos = client.getEndpoint().getService().getServiceInfos();
+        // there can only be one.
+        assertEquals(1, serviceInfos.size());
+        ServiceInfo serviceInfo = serviceInfos.get(0);
+        schemata = serviceInfo.getSchemas();
+        nameManager = BasicNameManager.newNameManager(serviceInfo);
+        NamespacePrefixAccumulator prefixAccumulator = 
+            new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
+        for (SchemaInfo schema : schemata) {
+            SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
+                .getXmlSchemaCollection(), prefixAccumulator, nameManager);
+            String allThatJavascript = builder.generateCodeForSchema(schema);
+            assertNotNull(allThatJavascript);
+            testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
+        }
+    }
+
+    @Override
+    protected void additionalSpringConfiguration(GenericApplicationContext context) throws Exception {
+    }
+}

Propchange: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/AttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/AttributeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/javascript/src/test/resources/attributeTestBeans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/resources/attributeTestBeans.xml?rev=699289&view=auto
==============================================================================
--- cxf/trunk/rt/javascript/src/test/resources/attributeTestBeans.xml (added)
+++ cxf/trunk/rt/javascript/src/test/resources/attributeTestBeans.xml Fri Sep 26 05:01:20 2008
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:jaxws="http://cxf.apache.org/jaxws"
+	xmlns:http="http://cxf.apache.org/transports/http/configuration"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+						http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
+						http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">
+	<!-- CXF -->
+	<import resource="classpath:META-INF/cxf/cxf.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-local.xml" />
+
+   <bean id="attribute-test-proxy-factory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean" >
+    <property name="serviceClass" value="org.apache.cxf.javascript.fortest.AttributeTestService"/>
+    <property name="address" value="local://AttributeTestService"/>
+   </bean>
+	
+	<jaxws:server id="AttributeTestServerBean" 
+                   serviceClass="org.apache.cxf.javascript.fortest.AttributeTestServiceImpl" 
+	               address="local://AttributeTestService">
+	</jaxws:server>
+	
+
+</beans>

Propchange: cxf/trunk/rt/javascript/src/test/resources/attributeTestBeans.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/javascript/src/test/resources/attributeTestBeans.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/rt/javascript/src/test/resources/attributeTests.js
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/resources/attributeTests.js?rev=699289&view=auto
==============================================================================
--- cxf/trunk/rt/javascript/src/test/resources/attributeTests.js (added)
+++ cxf/trunk/rt/javascript/src/test/resources/attributeTests.js Fri Sep 26 05:01:20 2008
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+ 
+var jsutils = new CxfApacheOrgUtil();
+ 
+function assertionFailed(explanation)
+{
+ 	var assert = new Assert(explanation); // this will throw out in Java.
+}
+
+function parseXml(xmlString) 
+{
+	var parser = new DOMParser();
+	return parser.parseFromString(xmlString, "text/xml").documentElement;
+}
+
+function deserializeAttributeTestBean(xmlString)
+{
+	var dom = parseXml(xmlString);
+	var bean = org_apache_cxf_javascript_testns_attributeTestBean_deserialize(jsutils, dom);
+	if(bean.getElement1() != "e1")
+		assertionFailed("element1 " + bean.getElement1());
+}
+
+

Propchange: cxf/trunk/rt/javascript/src/test/resources/attributeTests.js
------------------------------------------------------------------------------
    svn:eol-style = native