[jboss-cvs] jbosstest/src/main/org/jboss/test/jaxr/scout ...

Anil Saldhana anil.saldhana at jboss.com
Thu Jul 20 13:34:46 EDT 2006


  User: asaldhana
  Date: 06/07/20 13:34:46

  Modified:    src/main/org/jboss/test/jaxr/scout  JaxrBaseTestCase.java
  Log:
  JBAS-2621: Scout testcases
  
  Revision  Changes    Path
  1.3       +239 -93   jbosstest/src/main/org/jboss/test/jaxr/scout/JaxrBaseTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JaxrBaseTestCase.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/jaxr/scout/JaxrBaseTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- JaxrBaseTestCase.java	29 Oct 2005 23:41:53 -0000	1.2
  +++ JaxrBaseTestCase.java	20 Jul 2006 17:34:46 -0000	1.3
  @@ -1,57 +1,51 @@
   /*
  -  * 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.
  -  */
  +* 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.jaxr.scout;
   
   import junit.framework.TestCase;
  +import org.jboss.mx.util.ObjectNameFactory;
  +import org.jboss.test.JBossRMIAdaptorHelper;
   
  +import javax.management.ObjectName;
  +import javax.naming.Context;
  +import javax.naming.InitialContext;
  +import javax.naming.NamingException;
  +import javax.xml.registry.BulkResponse;
  +import javax.xml.registry.BusinessLifeCycleManager;
  +import javax.xml.registry.BusinessQueryManager;
   import javax.xml.registry.Connection;
   import javax.xml.registry.ConnectionFactory;
  +import javax.xml.registry.FindQualifier;
   import javax.xml.registry.JAXRException;
  -import javax.xml.registry.BusinessLifeCycleManager;
   import javax.xml.registry.RegistryService;
  -import javax.xml.registry.BusinessQueryManager;
  -import javax.xml.registry.FindQualifier;
  -import javax.xml.registry.BulkResponse;
  -import javax.xml.registry.infomodel.InternationalString;
  -import javax.xml.registry.infomodel.Organization;
  -import javax.xml.registry.infomodel.Service;
  -import javax.xml.registry.infomodel.ServiceBinding;
  -import javax.xml.registry.infomodel.User;
  -import javax.xml.registry.infomodel.PersonName;
  -import javax.xml.registry.infomodel.TelephoneNumber;
  -import javax.xml.registry.infomodel.EmailAddress;
  -import javax.xml.registry.infomodel.RegistryObject;
  -import javax.xml.registry.infomodel.PostalAddress;
  -import javax.xml.registry.infomodel.ClassificationScheme;
  -import javax.xml.registry.infomodel.Key;
  -import javax.xml.registry.infomodel.Classification;
  -import javax.xml.registry.infomodel.ExternalIdentifier;
  -import java.util.Properties;
  -import java.util.Set;
  -import java.util.HashSet;
  -import java.util.Collection;
  +import javax.xml.registry.infomodel.*;
  +import java.net.PasswordAuthentication;
   import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.HashSet;
   import java.util.Iterator;
  -import java.net.PasswordAuthentication;
  +import java.util.Locale;
  +import java.util.Properties;
  +import java.util.Set;
   
   /**
    * Acts as the base class for Jaxr Test Cases
  @@ -68,48 +62,87 @@
       protected RegistryService rs = null;
       protected BusinessQueryManager bqm = null;
       protected Connection connection = null;
  +    protected BulkResponse br = null;
  +    protected JBossRMIAdaptorHelper server = null;
  +
  +    protected ConnectionFactory factory = null;
  +
  +    protected static final ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss:service=juddi");
   
  +    //Debug ID
  +    protected static String debugProp = System.getProperty("jaxr.debug", "true");
  +
  +    /**
  +     * Setup of the JUnit test
  +     * We create the juddi tables on startup
  +     *
  +     * @throws Exception
  +     */
       protected void setUp() throws Exception
       {
  -        String queryurl = System.getProperty("jaxr.query.url");
  -        String puburl   = System.getProperty("jaxr.publish.url");
  +        //Change the createonstart setting for juddi service and restart it
  +        server = new JBossRMIAdaptorHelper(this.getClientContext());
  +        server.invokeOperation(OBJECT_NAME, "setCreateOnStart",
  +                new Object[]{Boolean.TRUE},
  +                new String[]{Boolean.TYPE.getName()});
  +        server.invokeOperation(OBJECT_NAME, "stop",
  +                null, null);
  +        server.invokeOperation(OBJECT_NAME, "start",
  +                null, null);
  +
  +        //Ensure that the Jaxr Connection Factory class is setup
  +        String factoryString = "javax.xml.registry.ConnectionFactoryClass";
  +        String factoryClass = System.getProperty(factoryString);
  +        if(factoryClass == null || factoryClass.length() == 0)
  +           System.setProperty(factoryString,"org.apache.ws.scout.registry.ConnectionFactoryImpl");
  +
  +        String queryurl = System.getProperty("jaxr.query.url", 
  +              "http://localhost:8080/juddi/inquiry");
  +        String puburl = System.getProperty("jaxr.publish.url", 
  +              "http://localhost:8080/juddi/publish");
  +
           Properties props = new Properties();
           props.setProperty("javax.xml.registry.queryManagerURL",
                   queryurl);
   
           props.setProperty("javax.xml.registry.lifeCycleManagerURL",
                   puburl);
  -        /*props.setProperty("javax.xml.registry.queryManagerURL",
  -                "http://localhost:7080/juddi/inquiry");
   
  -        props.setProperty("javax.xml.registry.lifeCycleManagerURL",
  -                "http://localhost:7080/juddi/publish");
  -        props.setProperty("javax.xml.registry.factoryClass",
  -                "org.apache.ws.scout.registry.ConnectionFactoryImpl");
  -        System.setProperty("javax.xml.registry.ConnectionFactoryClass",
  -                "org.apache.ws.scout.registry.ConnectionFactoryImpl");*/
  -        System.setProperty("juddi.proxy.transportClass","org.jboss.jaxr.juddi.axis.JBossJuddiAxisTransport");
  +        String transportClass = System.getProperty("juddi.proxy.transportClass",
  +                "org.jboss.jaxr.juddi.transport.SaajTransport");
  +        System.setProperty("juddi.proxy.transportClass", transportClass);
           try
           {
               // Create the connection, passing it the configuration properties
  -            ConnectionFactory factory = ConnectionFactory.newInstance();
  +            factory = ConnectionFactory.newInstance();
               factory.setProperties(props);
               connection = factory.createConnection();
           } catch (JAXRException e)
           {
  -            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
  +            fail("Setup failed"+e);
           }
  -
       }
   
  -    public void testJaxrEssentials()
  +    /**
  +     * Teardown of the junit test
  +     * We discard all the tables created by the juddi service
  +     *
  +     * @throws Exception
  +     */
  +    protected void tearDown() throws Exception
       {
  -        assertNotNull(connection);
  +        if (connection != null) connection.close();
  +        //stop the juddi service so that all the tables are dropped
  +        server.invokeOperation(OBJECT_NAME, "setCreateOnStart",
  +                new Object[]{Boolean.FALSE},
  +                new String[]{Boolean.TYPE.getName()});
  +        server.invokeOperation(OBJECT_NAME, "stop",
  +                null, null);
       }
   
  -    protected void tearDown() throws Exception
  +    public void testJaxrEssentials()
       {
  -        if(connection != null ) connection.close();
  +        assertNotNull(connection);
       }
   
       /**
  @@ -132,29 +165,44 @@
           }
       }
   
  +    protected void getJAXREssentials() throws JAXRException
  +    {
  +
  +        rs = connection.getRegistryService();
  +        blm = rs.getBusinessLifeCycleManager();
  +        bqm = rs.getBusinessQueryManager();
  +    }
  +
       public InternationalString getIString(String str)
               throws JAXRException
       {
           return blm.createInternationalString(str);
       }
   
  +    
  +    /**
  +     * Locale aware Search a business in the registry
  +     * 
  +     * @param bizname
  +     * @throws JAXRException
  +     */
       public void searchBusiness(String bizname) throws JAXRException
       {
           try
           {
               // Get registry service and business query manager
  -            rs = connection.getRegistryService();
  -            bqm = rs.getBusinessQueryManager();
  -            System.out.println("We have the Business Query Manager");
  +            this.getJAXREssentials();
   
               // Define find qualifiers and name patterns
               Collection findQualifiers = new ArrayList();
               findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
               Collection namePatterns = new ArrayList();
  -            namePatterns.add("%" + bizname + "%");
  +            String pattern = "%" + bizname + "%";
  +            LocalizedString ls = blm.createLocalizedString(Locale.getDefault(),
  +                  pattern);
  +            namePatterns.add(ls);
   
               // Find based upon qualifier type and values
  -            System.out.println("\n-- searching the registry --\n");
               BulkResponse response =
                       bqm.findOrganizations(findQualifiers,
                               namePatterns,
  @@ -167,25 +215,26 @@
               Collection orgs = response.getCollection();
               if (orgs == null)
               {
  -                System.out.println("\n-- Matched 0 orgs");
  +                if ("true".equalsIgnoreCase(debugProp))
  +                    System.out.println(" -- Matched 0 orgs");
   
               } else
               {
  -                System.out.println("\n-- Matched " + orgs.size() + " organizations --\n");
  +                if ("true".equalsIgnoreCase(debugProp))
  +                    System.out.println(" -- Matched " + orgs.size() + " organizations -- ");
   
                   // then step through them
                   for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();)
                   {
                       Organization org = (Organization) orgIter.next();
  +                    if ("true".equalsIgnoreCase(debugProp))
  +                    {
                       System.out.println("Org name: " + getName(org));
                       System.out.println("Org description: " + getDescription(org));
                       System.out.println("Org key id: " + getKey(org));
  -
  -                    printUser(org);
  -
  -                    printServices(org);
  -                    // Print spacer between organizations
  -                    System.out.println(" --- ");
  +                    } 
  +                    checkUser(org); 
  +                    checkServices(org);
                   }
               }//end else
           } catch (JAXRException e)
  @@ -208,17 +257,18 @@
       protected BusinessQueryManager getBusinessQueryManager() throws JAXRException
       {
           assertNotNull(connection);
  -        if(rs == null) rs=this.getRegistryService();
  +        if (rs == null) rs = this.getRegistryService();
           return rs.getBusinessQueryManager();
       }
  +
       protected BusinessLifeCycleManager getBusinessLifeCycleManager() throws JAXRException
       {
           assertNotNull(connection);
  -        if(rs == null) rs=this.getRegistryService();
  +        if (rs == null) rs = this.getRegistryService();
           return rs.getBusinessLifeCycleManager();
       }
   
  -    private static void printServices(Organization org)
  +    private static void checkServices(Organization org)
               throws JAXRException
       {
           // Display service and binding information
  @@ -226,19 +276,30 @@
           for (Iterator svcIter = services.iterator(); svcIter.hasNext();)
           {
               Service svc = (Service) svcIter.next();
  +            if ("true".equalsIgnoreCase(debugProp))
  +            {
               System.out.println(" Service name: " + getName(svc));
               System.out.println(" Service description: " + getDescription(svc));
  +            }
  +            assertEquals("JBOSS JAXR Service",getName(svc));
  +            assertEquals("Services of XML Registry",getDescription(svc));
  +            
               Collection serviceBindings = svc.getServiceBindings();
               for (Iterator sbIter = serviceBindings.iterator(); sbIter.hasNext();)
               {
                   ServiceBinding sb = (ServiceBinding) sbIter.next();
  +                if ("true".equalsIgnoreCase(debugProp))
  +                {
                   System.out.println("  Binding Description: " + getDescription(sb));
                   System.out.println("  Access URI: " + sb.getAccessURI());
               }
  +                assertEquals("http://testjboss.org", sb.getAccessURI());
  +                assertEquals("Test Service Binding", getDescription(sb));
  +            }
           }
       }
   
  -    private static void printUser(Organization org)
  +    private static void checkUser(Organization org)
       throws JAXRException
       {
           // Display primary contact information
  @@ -247,6 +308,7 @@
           {
               PersonName pcName = pc.getPersonName();
               System.out.println(" Contact name: " + pcName.getFullName());
  +            assertEquals("Anil S",pcName.getFullName());
               Collection phNums = pc.getTelephoneNumbers(pc.getType());
               for (Iterator phIter = phNums.iterator(); phIter.hasNext();)
               {
  @@ -290,6 +352,7 @@
   
       /**
        * Creates a Jaxr Organization with 1 or more services
  +     *
        * @return
        * @throws JAXRException
        */
  @@ -300,6 +363,18 @@
           org.setDescription(getIString("JBoss Inc"));
           Service service = blm.createService(getIString("JBOSS JAXR Service"));
           service.setDescription(getIString("Services of XML Registry"));
  +        //Create serviceBinding
  +        ServiceBinding serviceBinding = blm.createServiceBinding();
  +        serviceBinding.setDescription(blm.
  +               createInternationalString("Test Service Binding"));
  + 
  +        //Turn validation of URI off
  +        serviceBinding.setValidateURI(false);
  +        serviceBinding.setAccessURI("http://testjboss.org");
  + 
  +        // Add the serviceBinding to the service
  +        service.addServiceBinding(serviceBinding); 
  +        
           User user = blm.createUser();
           org.setPrimaryContact(user);
           PersonName personName = blm.createPersonName("Anil S");
  @@ -341,21 +416,24 @@
           return org;
       }
   
  +
       /**
        * Delete an Organization with a given key
  +     *
        * @param orgkey
        * @throws Exception
        */
  -    protected void deleteOrganization( Key orgkey)
  -    throws Exception {
  +    protected void deleteOrganization(Key orgkey)
  +            throws Exception
  +    {
           assertNotNull("Org Key is null?", orgkey);
  -        if( blm == null ) blm = this.getBusinessLifeCycleManager();
  +        if (blm == null) blm = this.getBusinessLifeCycleManager();
           Collection keys = new ArrayList();
           keys.add(orgkey);
   
           BulkResponse response = blm.deleteOrganizations(keys);
           Collection exceptions = response.getExceptions();
  -        assertNull("Deleting Org with Key="+orgkey,exceptions);
  +        assertNull("Deleting Org with Key=" + orgkey, exceptions);
       }
   
       private ClassificationScheme getClassificationScheme(String str1, String str2)
  @@ -365,4 +443,72 @@
                   getIString(str2));
           return cs;
       }
  +
  +    protected Connection loginSecondUser()
  +    {
  +        Connection con = null;
  +        try
  +        {
  +            if (factory == null)
  +                throw new IllegalStateException("ConnectionFactory is null");
  +            con = factory.createConnection();
  +        } catch (JAXRException e)
  +        {
  +            e.printStackTrace();
  +        }
  +        PasswordAuthentication passwdAuth = new PasswordAuthentication("jbosscts",
  +                passwd.toCharArray());
  +        Set creds = new HashSet();
  +        creds.add(passwdAuth);
  +
  +        try
  +        {
  +            con.setCredentials(creds);
  +        } catch (JAXRException e)
  +        {
  +            e.printStackTrace();
  +            fail(e.getMessage());
  +        }
  +        return con;
  +    }
  +
  +    protected Concept getAssociationConcept(String associationType)
  +    {
  +        try
  +        {
  +            BusinessQueryManager bqm = rs.getBusinessQueryManager();
  +            ClassificationScheme associationTypes =
  +                    bqm.findClassificationSchemeByName(null, "AssociationType");
  +            Collection types = associationTypes.getChildrenConcepts();
  +            Iterator iter = types.iterator();
  +            Concept concept = null;
  +            while (iter.hasNext())
  +            {
  +                concept = (Concept) iter.next();
  +                if (concept.getName().getValue().equals(associationType))
  +                {
  +                    return concept;
  +                }
  +            }
  +        } catch (Exception e)
  +        {
  +            e.printStackTrace();
  +            return null;
  +        }
  +        return null;
  +
  +    }// end of method
  +
  +    protected InitialContext getClientContext() throws NamingException
  +    {
  +        String hostname = System.getProperty("host.name", "localhost");
  +        if (hostname == null)
  +            throw new IllegalStateException("host.name system property not present");
  +        Properties env = new Properties();
  +        env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  +        env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
  +        env.setProperty(Context.PROVIDER_URL, "jnp://" + hostname + ":1099");
  +        return new InitialContext(env);
  +    }
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list