1 Reply Latest reply: Oct 6, 2011 4:06 AM by 892827 RSS

    xquery testing environment

    865572
      He guys!
      There is a question about creating the xquery testing environment.
      I have Altova XML Spy editor to write xquery. How to load OSM automation classes which xquery script will see in xml spy runtime?
      Typical xquery automator contains next external objects:
      automator, outboundMessage, context. How to declare this variables in xml spy for debuging goals?
        • 1. Re: xquery testing environment
          892827
          The problem was solved by using SaxonB implementation of Xquery processor.
          The sample application for testing xquery scripts for automation cartridges:

          package xq;

          import net.sf.saxon.query.*;
          import net.sf.saxon.Configuration;
          import java.io.*;
          import java.util.Properties;
          import java.util.logging.Logger;

          import javax.xml.transform.OutputKeys;
          import javax.xml.transform.stream.StreamResult;
          import javax.xml.transform.stream.StreamSource;

          import javax.jms.QueueConnection;
          import javax.jms.QueueConnectionFactory;
          import javax.jms.QueueSession;
          import javax.jms.TextMessage;

          import oracle.communications.ordermanagement.automation.plugin.XQuerySender;

          import com.mslv.oms.automation.*;
          import org.apache.commons.logging.*;
          public class XQueryAutomatorCustom {

               @SuppressWarnings("deprecation")
               public static void main(String[] args) {
                    String xQueryFileName="query.xq";
                    String inputXMLFileName="input.xml";
                    if (args.length==2)
                    {
                         xQueryFileName=args[0];
                         inputXMLFileName=args[1];
                    }
                    try {
                    java.util.Hashtable env = new java.util.Hashtable();
                    env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
                    env.put(javax.naming.Context.PROVIDER_URL, "t3://ip:port");
                    javax.naming.Context ctx = new javax.naming.InitialContext(env);
                    QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx.lookup("test/jms/ConnectionFactory");
                    QueueConnection qcon = qconFactory.createQueueConnection();
                    QueueSession qsession = qcon.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
                    TextMessage msg = qsession.createTextMessage();
                    
                    Configuration config = new Configuration();
                    StaticQueryContext staticContext = new StaticQueryContext(config);

                    XQueryExpression exp = staticContext.compileQuery(new FileInputStream(xQueryFileName), "UTF-8");
                    DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
                    
                    dynamicContext.setContextNode(config.buildDocument(new StreamSource(
                              new File(inputXMLFileName))));

                    dynamicContext.setParameter("outboundMessage", msg);
                    dynamicContext.setParameter("context", new TaskContextBean());
                    dynamicContext.setParameter("log", LogFactory.getLog(XQueryAutomatorCustom.class));
                    dynamicContext.setParameter("automator", new XQuerySender());
                    
                    Properties props = new Properties();
                    props.setProperty(OutputKeys.METHOD, "xml");
                    props.setProperty(OutputKeys.INDENT, "yes");
                    
                    exp.run(dynamicContext, new StreamResult(System.out), props);
                    
                    System.out.println("\n**************\nAssigned corrID: "+msg.getJMSCorrelationID());
                    } catch (Exception e) {e.printStackTrace(); System.exit(0);
                    
                    }
               }
          }


          build.xml file:

          <project name="xq_test">
               <path id="class.path">
                    <pathelement location="C:\saxon\saxonb\saxon9.jar" />
                    <pathelement location="D:/wlserver/server/lib/wljmsclient.jar"
                    />
                    <pathelement location="C:/OSM/SDK/Automation/automationdeploy_bin/automation_plugins.jar"
                    />
                    <pathelement location="C:/OSM/SDK/Automation/automationdeploy_bin/commons-logging-1.1.jar"
                    />
               </path>
               <target name="cli">
                    <java classname="net.sf.saxon.Query" classpathref="class.path">
                         <arg value="-t" />
                         <arg value="-s:GetOrder.xml" />
                         <arg value="-q:query1.xq" />
                         <classpath>
                              <pathelement location="C:\app\research\saxon\saxonb\saxon9.jar"
                              />
                         </classpath>
                    </java>
               </target>
               <target name="run">
                    <java classname="xq.XQueryAutomatorCustom"
                    classpathref="class.path"
                    classpath="bin"
                    >
                         <arg value="sw_create_sender.xq" />
                         <!--arg value="createwacallback_element.xml" /-->
                         <arg value="response.xml" />
                    </java>
               </target>
          </project>

          Edited by: 889824 on 06.10.2011 2:05