/*
 * 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.wsr;

import com.ibm.wsdl.factory.WSDLFactoryImpl;
import junit.framework.Test;
import org.jboss.test.jbossnet.JBossNetTestBase;
import org.xml.sax.InputSource;

import javax.wsdl.Definition;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import java.io.InputStream;
import java.net.URL;

/**
 * Tests remote accessibility of "ordinary" (wsr-) deployed Axis services
 * @since 11. Oktober 2001
 * @author <a href="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>
 * @version $Revision: 1.1.1.1.4.3 $
 */
public class WSRUnitTestCase extends JBossNetTestBase
{
   private QName ADDRESS_SERVICE = new QName("http://test.jboss.org/samples/AddressBook", "AddressBookService");

   // Constructors --------------------------------------------------
   public WSRUnitTestCase(String name)
   {
      super(name);
   }

   /** prepared data */
   Address address;
   AddressBook book;

   /** sets up the test */
   public void setUp() throws Exception
   {
      super.setUp();

      Phone phone = new Phone();
      phone.setExchange("(0)6897");
      phone.setNumber("6666");
      phone.setAreaCode(49);
      StateType state = StateType.fromString("TX");
      address = new Address();
      address.setStreetNum(42);
      address.setStreetName("Milky Way");
      address.setCity("Galactic City");
      address.setZip(2121);
      address.setState(state);
      address.setPhoneNumber(phone);

      URL wsdlURI = new URL(SERVICES_LOCATION + "/AddressBook?wsdl");
      Service service = createService(wsdlURI, ADDRESS_SERVICE, true);

      book = (AddressBook)service.getPort(AddressBook.class);
   }

   /** this is where the axis config is stored */
   protected String getAxisConfiguration()
   {
      return "jbossnet/wsr/client/client-config.wsdd";
   }

   /** routes an address to the server and tests the result */
   public void testAddress() throws Exception
   {
      book.addEntry("George", address);
      Address retAddress = book.getAddressFromName("George");
      assertEquals("Comparing addresses", address, retAddress);
   }

   /** suite method */
   public static Test suite() throws Exception
   {
      return getDeploySetup(WSRUnitTestCase.class, "jbossnet-wsr.wsr");
   }
}