/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.test.jbossnet.message;

// $Id: MessageTestCase.java,v 1.1.4.3 2005/12/01 19:51:09 dimitris Exp $

import junit.framework.Test;
import org.jboss.axis.utils.DOM2Utils;
import org.jboss.test.JBossTestCase;
import org.jboss.test.jbossnet.JBossNetTestBase;
import org.w3c.dom.Document;

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import java.io.ByteArrayInputStream;
import java.net.URL;

/** 
 * Endpoint test for document centric message exchange .
 * It uses the the jva:MSG provider.
 *
 * @author Thomas.Diesler@jboss.org
 */
public class MessageTestCase extends JBossNetTestBase
{
   public static final String xmlstr = "<root><child>Hello</child><child>World</child></root>";

   public MessageTestCase(String name)
   {
      super(name);
   }

   /** Process an Document at the endpoint
    */
   public void testProcessMessage() throws Exception
   {
      DocumentBuilder builder = DOM2Utils.getDocumentBuilder();
      Document doc = builder.parse(new ByteArrayInputStream(xmlstr.getBytes()));

      String namespaceURI = "http://jboss.net/message";
      URL wsdlURL = new URL(SERVICES_LOCATION + "/MessageServer?wsdl");
      Service service = createService(wsdlURL, new QName(namespaceURI, "MessageServerService"));
      Call call = service.createCall(new QName(namespaceURI, "MessageServer"), "processMessage");

      Object retObj = call.invoke(new Object[]{doc});
      assertNotNull("Return obj is null", retObj);
   }

   /** Deploy the test ear */
   public static Test suite() throws Exception
   {
      return getDeploySetup(MessageTestCase.class, "jbossnet-message.wsr");
   }

}
