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/08/25 22:43:34 UTC

svn commit: r688870 - in /cxf/trunk/rt/javascript/src: main/java/org/apache/cxf/javascript/ParticleInfo.java test/java/org/apache/cxf/javascript/GenericAegisTest.java

Author: bimargulies
Date: Mon Aug 25 13:43:34 2008
New Revision: 688870

URL: http://svn.apache.org/viewvc?rev=688870&view=rev
Log:
Fix the superficial symptom of CXF-1738, since it might come up in a real case.

Added:
    cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GenericAegisTest.java
      - copied, changed from r688495, cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java
Modified:
    cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java

Modified: cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java?rev=688870&r1=688869&r2=688870&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java (original)
+++ cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java Mon Aug 25 13:43:34 2008
@@ -213,6 +213,9 @@
                             .toString(), element.getQName(), element);
                 }
             }
+        } else if (elementInfo.type.getQName() != null
+            && XmlSchemaConstants.ANY_TYPE_QNAME.equals(elementInfo.type.getQName())) {
+            elementInfo.anyType = true;
         }
     }
 

Copied: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GenericAegisTest.java (from r688495, cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GenericAegisTest.java?p2=cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GenericAegisTest.java&p1=cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java&r1=688495&r2=688870&rev=688870&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java (original)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GenericAegisTest.java Mon Aug 25 13:43:34 2008
@@ -19,128 +19,60 @@
 
 package org.apache.cxf.javascript;
 
+
 import java.util.Collection;
-import java.util.logging.Logger;
 
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.interceptor.LoggingInInterceptor;
-import org.apache.cxf.javascript.JavascriptTestUtilities.JSRunnable;
-import org.apache.cxf.javascript.JavascriptTestUtilities.Notifier;
-import org.apache.cxf.javascript.fortest.AegisServiceImpl;
-import org.junit.Before;
+import org.apache.cxf.endpoint.EndpointImpl;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.javascript.fortest.GenericGenericClass;
+import org.apache.cxf.javascript.service.ServiceJavascriptBuilder;
+import org.apache.cxf.javascript.types.SchemaJavascriptBuilder;
+import org.apache.cxf.service.model.SchemaInfo;
+import org.apache.cxf.service.model.ServiceInfo;
 import org.junit.Test;
-import org.mozilla.javascript.Context;
-import org.springframework.context.support.GenericApplicationContext;
+import static org.junit.Assert.assertNotNull;
 
-/*
- * We end up here with a part with isElement == true, a non-array element, 
- * but a complex type for an array of the element.
+/**
+ * Here we try to set up with Aegis, the Simple front end, and a generic class
+ * as the SEB. The simple front end, due to type erasure, turns all the <T> items
+ * into xsd:anyType. That exposed a bad assumption in the Javascript code generator,
+ * and this test regresses it by not exploding on contact. However, this will
+ * be obsolete if the Simple front end is made to cope correctly with Generic 
+ * SEBs.
  */
-public class AegisTest extends JavascriptRhinoTest {
-
-    private static final Logger LOG = LogUtils.getL7dLogger(AegisTest.class);
-
-    AegisServiceImpl implementor;
-
-    public AegisTest() throws Exception {
-        super();
-    }
+public class GenericAegisTest  {
 
-    @Override
-    protected void additionalSpringConfiguration(GenericApplicationContext context) throws Exception {
-    }
-    
-    @Override
-    protected String[] getConfigLocations() {
-        return new String[] {"classpath:AegisBeans.xml"};
-    }
-    
-    @Before
-    public void before() throws Exception {
-        setupRhino("aegis-service", 
-                   "/org/apache/cxf/javascript/AegisTests.js",
-                   true);
-        implementor = (AegisServiceImpl)rawImplementor;
-        implementor.reset();
-        serverFactoryBean.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor());
-    }
-    
-    private Void acceptAny(Context context) {
-        LOG.info("About to call acceptAny with Raw XML" + getAddress());
-        implementor.prepareToWaitForOneWay();
-        testUtilities.rhinoCall("testAnyNToServerRaw",  
-                                testUtilities.javaToJS(getAddress()));
-        implementor.waitForOneWay();
-        assertEquals("before items", implementor.getAcceptedString());
-        Collection<org.jdom.Element> something = implementor.getAcceptedCollection();
-        assertNotNull(something);
-        return null;
-    }
-    
+    // the claim is that code generation makes this go boom.
     @Test
-    public void callAcceptAny() {
-        testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
-            public Void run(Context context) {
-                return acceptAny(context);
-            }
-        });
-    }
-    
-    private Void acceptAnyTyped(Context context) {
-        LOG.info("About to call acceptAny with Raw XML and xsi:type" + getAddress());
-        implementor.prepareToWaitForOneWay();
-        testUtilities.rhinoCall("testAnyNToServerRawTyped",  
-                                testUtilities.javaToJS(getAddress()));
-        implementor.waitForOneWay();
-        Collection<Object> something = implementor.getAcceptedObjects();
-        assertNotNull(something);
-        return null;
-    }
-    
-    @Test
-    public void callAcceptAnyTyped() {
-        testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
-            public Void run(Context context) {
-                return acceptAnyTyped(context);
-            }
-        });
-    }
-    
-    private Void returnBeanWithAnyTypeArray(Context context) {
-        Notifier notifier = 
-            testUtilities.rhinoCallConvert("testReturningBeanWithAnyTypeArray", Notifier.class, 
-                                           testUtilities.javaToJS(getAddress()));
-        
-        boolean notified = notifier.waitForJavascript(1000 * 10);
-        assertTrue(notified);
-        Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
-        assertNull(errorStatus);
-        String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
-        assertNull(errorText);
-
-        //This method returns a 'BeanWithAnyTypeArray'. 
-        //start by looking at the string.
-        String beanString = (String)testUtilities.rhinoEvaluate("globalResponseObject._return._string");
-        assertEquals("lima", beanString);
-        Object o1 = testUtilities.rhinoEvaluate("globalResponseObject._return._objects._anyType[0]");
-        assertNotNull(o1);
-        String marker = 
-            testUtilities.rhinoEvaluateConvert("globalResponseObject._return._objects._anyType[0].typeMarker",
-                                               String.class);
-        assertEquals("aegis_fortest_javascript_cxf_apache_org_Mammal", marker);
-        Object intValue = 
-            testUtilities.rhinoEvaluate("globalResponseObject._return._objects._anyType[1]");
-        assertEquals(new Float(42), new Float(intValue.toString()));
-        return null;
-    }
-    
-    @Test
-    public void callReturnBeanWithAnyTypeArray() {
-        testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
-            public Void run(Context context) {
-                return returnBeanWithAnyTypeArray(context);
-            }
-        });
-    }
+    public void testGenerateJavascript() throws Exception {
+     // Create our service implementation
+        GenericGenericClass<String> impl = new GenericGenericClass<String>();
+
+        // Create our Server
+        ServerFactoryBean svrFactory = new ServerFactoryBean();
+        // we sure can't get a .class for the interface, can we?
+        svrFactory.setServiceClass(impl.getClass());
+        svrFactory.setAddress("http://localhost:9000/aegisgeneric");
+        svrFactory.setServiceBean(impl);
+        Server server = svrFactory.create();
+        ServiceInfo serviceInfo = ((EndpointImpl)server.getEndpoint()).getEndpointInfo().getService();
+        Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
+        BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo);
+        NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
+            .getXmlSchemaCollection());
+        for (SchemaInfo schema : schemata) {
+            SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
+                .getXmlSchemaCollection(), prefixManager, nameManager);
+            String allThatJavascript = builder.generateCodeForSchema(schema);
+            assertNotNull(allThatJavascript);
+        }
+
+        ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null,
+                                                                               prefixManager, nameManager);
+        serviceBuilder.walk();
+        String serviceJavascript = serviceBuilder.getCode();
+        assertNotNull(serviceJavascript);
 
+    }
 }