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

import junit.framework.Test;
import org.jboss.test.jbossnet.JBossNetTestBase;

import javax.xml.namespace.QName;
import java.net.URL;

/**
 * tests connectivity to external, global web services.
 * @author cgjung
 * @author Thomas.Diesler@jboss.org
 * @since 10.2002
 */
public class ExternalUnitTestCase extends JBossNetTestBase
{
   private QName FEDERATED_SERVICE = new QName("http://" + getServerHost() + ":8080/jboss-net/services/FederatedService", "FederatedServiceLocalService");

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

   /** the session bean with which we interact */
   FederatedService federation;

   /** setup the bean */
   public void setUp() throws Exception
   {
      super.setUp();
      URL wsdlURL = new URL(SERVICES_LOCATION + "/FederatedService?wsdl");
      federation = (FederatedService)createService(wsdlURL, FEDERATED_SERVICE).getPort(FederatedService.class);
   }

   /** test a federated call */
   public void testFederated() throws Exception
   {
      String result = federation.findAndTranslate("JBoss is a killer server and Mr. Fleury is a damned genius");
      assertNotNull("Result is null", result);
      System.out.println("Result: " + result);
      String shittimes = "This service is currently disabled.";
      assertTrue(result, result.indexOf("JBoss") >= 0 || shittimes.equals(result));
   }

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

   /** this is to deploy the whole ear */
   public static Test suite() throws Exception
   {
      return getDeploySetup(ExternalUnitTestCase.class, "jbossnet-external.ear");
   }

   public static void main(String[] args)
   {
      junit.textui.TestRunner.run(ExternalUnitTestCase.class);
   }
}
