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

Anil Saldhana anil.saldhana at jboss.com
Thu Jul 20 13:19:16 EDT 2006


  User: asaldhana
  Date: 06/07/20 13:19:16

  Added:       src/main/org/jboss/test/jaxr/scout/publish  
                        JaxrDeleteAssociationTestCase.java
                        JaxrSaveServiceBindingTestCase.java
  Log:
  JBAS-2621: JAXR testcases
  
  Revision  Changes    Path
  1.2       +197 -0    jbosstest/src/main/org/jboss/test/jaxr/scout/publish/JaxrDeleteAssociationTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JaxrDeleteAssociationTestCase.java
  ===================================================================
  RCS file: JaxrDeleteAssociationTestCase.java
  diff -N JaxrDeleteAssociationTestCase.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ JaxrDeleteAssociationTestCase.java	20 Jul 2006 17:19:16 -0000	1.2
  @@ -0,0 +1,197 @@
  +/*
  +* 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.publish;
  +
  +import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
  +import org.jboss.test.jaxr.scout.util.ScoutUtil;
  +
  +import javax.xml.registry.BusinessLifeCycleManager;
  +import javax.xml.registry.BusinessQueryManager;
  +import javax.xml.registry.Connection;
  +import javax.xml.registry.JAXRException;
  +import javax.xml.registry.LifeCycleManager;
  +import javax.xml.registry.RegistryService;
  +import javax.xml.registry.infomodel.Association;
  +import javax.xml.registry.infomodel.Concept;
  +import javax.xml.registry.infomodel.Key;
  +import javax.xml.registry.infomodel.Organization;
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
  +
  +/**
  + * Tests Save and Delete of Associations
  + *
  + * @author <mailto:Anil.Saldhana at jboss.org>Anil Saldhana
  + * @since Mar 9, 2005
  + */
  +public class JaxrDeleteAssociationTestCase extends JaxrBaseTestCase
  +{
  +    /**
  +     * Usecase:
  +     * 1. Authenticate two users
  +     * 2. First user creates an org (Source org)
  +     * 3. Second user creates an org (Target org)
  +     * 4. First user creates an association using the target org
  +     * 5. Both the users confirm the association
  +     * 6. Second user saves the association
  +     * 7. First user deletes the association
  +     * 8. When the first user asks the registry for associations,
  +     * need to get back empty!
  +     *
  +     * @throws JAXRException
  +     */
  +    public void testDeleteAssociations() throws JAXRException
  +    {
  +        Key savekey = null;
  +        Key assockey = null;
  +        BusinessQueryManager bqm2 = null;
  +        BusinessLifeCycleManager blm2 = null;
  +        Collection sourceKeys = null;
  +        Collection targetKeys = null;
  +
  +
  +        try
  +        {
  +            login();
  +            getJAXREssentials();
  +            // second user.
  +            Connection con2 = loginSecondUser();
  +            RegistryService rs2 = con2.getRegistryService();
  +            blm2 = rs2.getBusinessLifeCycleManager();
  +            bqm2 = rs2.getBusinessQueryManager();
  +            String orgTarget = "Target Organization";
  +            String orgSource = "Source Organization";
  +
  +            Organization target = blm2.createOrganization(blm.createInternationalString(orgTarget));
  +            Organization source = blm.createOrganization(blm.createInternationalString(orgSource));
  +
  +            Collection orgs = new ArrayList();
  +            orgs.add(source);
  +            br = blm.saveOrganizations(orgs);
  +            if (br.getExceptions() != null)
  +            {
  +                fail(" Source::Save Organizations failed");
  +            }
  +            sourceKeys = br.getCollection();
  +            Iterator iter = sourceKeys.iterator();
  +            while (iter.hasNext())
  +            {
  +                savekey = (Key) iter.next();
  +            }
  +            String sourceid = savekey.getId();
  +            String objectType = LifeCycleManager.ORGANIZATION;
  +
  +            Organization pubSource = (Organization) bqm.getRegistryObject(sourceid, objectType);
  +            assertNotNull("Source Org", pubSource.getName().getValue());
  +
  +            orgs.clear();
  +            orgs.add(target);
  +            br = blm2.saveOrganizations(orgs);
  +            if (br.getExceptions() != null)
  +            {
  +                fail("Target:: Save Organizations failed");
  +            }
  +            targetKeys = br.getCollection();
  +            iter = targetKeys.iterator();
  +            while (iter.hasNext())
  +            {
  +                savekey = (Key) iter.next();
  +            }
  +            String targetid = savekey.getId();
  +            Organization targetOrg = (Organization) bqm2.getRegistryObject(targetid, objectType);
  +            assertNotNull("Target Org", targetOrg.getName().getValue());
  +
  +            Concept associationType = getAssociationConcept("Implements");
  +            assertNotNull("AssociationType", associationType);
  +
  +            Association a = blm.createAssociation(targetOrg, associationType);
  +            a.setSourceObject(pubSource);
  +
  +            blm.confirmAssociation(a);
  +            blm2.confirmAssociation(a);
  +
  +            // publish the Association
  +            Collection associations = new ArrayList();
  +            associations.add(a);
  +            br = blm2.saveAssociations(associations, false);
  +
  +            if (br.getExceptions() != null)
  +            {
  +                fail("Second User :save Association failed");
  +            }
  +
  +            br = bqm.findCallerAssociations(null,
  +                    new Boolean(true),
  +                    new Boolean(true),
  +                    null);
  +
  +            if (br.getExceptions() == null)
  +            {
  +                Collection results = br.getCollection();
  +                if (results.size() > 0)
  +                {
  +                    iter = results.iterator();
  +                    while (iter.hasNext())
  +                    {
  +                        Association a1 = (Association) iter.next();
  +                        assockey = a1.getKey();
  +                        ScoutUtil.validateAssociation(a1, orgSource);
  +                    }
  +                }
  +            }
  +            if (assockey != null)
  +            {
  +                Collection keys = new ArrayList();
  +                keys.add(assockey);
  +                blm.deleteAssociations(keys);
  +                br = bqm.findCallerAssociations(null, new Boolean(true), new Boolean(true), null);
  +                if (br.getExceptions() == null)
  +                {
  +                    Collection retAssocs = br.getCollection();
  +                    if (retAssocs.size() == 0)
  +                    {
  +                        //Pass
  +                    } else
  +                        fail("Associations should have been zero");
  +                }
  +            }
  +
  +        } catch (Exception e)
  +        {
  +            e.printStackTrace();
  +            System.out.println("Caught unexpected exception: " + e.getMessage());
  +            fail(" failed ");
  +        } finally
  +        {
  +            // Clean up
  +            try
  +            {
  +                blm2.deleteOrganizations(targetKeys);
  +                blm.deleteOrganizations(sourceKeys);
  +            } catch (JAXRException je)
  +            {
  +                System.out.println("Error: Clean Up Failed");
  +            }
  +        }
  +    }
  +}
  
  
  
  1.2       +233 -0    jbosstest/src/main/org/jboss/test/jaxr/scout/publish/JaxrSaveServiceBindingTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JaxrSaveServiceBindingTestCase.java
  ===================================================================
  RCS file: JaxrSaveServiceBindingTestCase.java
  diff -N JaxrSaveServiceBindingTestCase.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ JaxrSaveServiceBindingTestCase.java	20 Jul 2006 17:19:16 -0000	1.2
  @@ -0,0 +1,233 @@
  +/*
  +* 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.publish;
  +
  +import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
  +
  +import javax.xml.registry.BulkResponse;
  +import javax.xml.registry.JAXRException;
  +import javax.xml.registry.LifeCycleManager;
  +import javax.xml.registry.infomodel.Concept;
  +import javax.xml.registry.infomodel.Key;
  +import javax.xml.registry.infomodel.Organization;
  +import javax.xml.registry.infomodel.Service;
  +import javax.xml.registry.infomodel.ServiceBinding;
  +import javax.xml.registry.infomodel.SpecificationLink;
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
  +
  +
  +/**
  + * Tests Saving ServiceBindings
  + *
  + * @author <mailto:Anil.Saldhana at jboss.org>Anil Saldhana
  + * @since Mar 8, 2005
  + */
  +public class JaxrSaveServiceBindingTestCase extends JaxrBaseTestCase
  +{
  +    /**
  +     * @throws JAXRException
  +     */
  +    public void testSaveServiceBinding() throws JAXRException
  +    {
  +        String serviceName = "jbosstestService";
  +        String sbDescription = "jbosstest sb description";
  +
  +        String conceptName = "jbosstest concept";
  +        Collection sbKeys = null;
  +        Collection serviceKeys = null;
  +        Collection orgKeys = null;
  +        Collection conceptKeys = null;
  +        Key conceptKey = null;
  +        Key serviceKey = null;
  +        Key orgKey = null;
  +
  +        String accessURI = "http://myhost/jaxrTest.jsp";
  +        login();
  +
  +
  +        try
  +        {
  +            getJAXREssentials();
  +            String orgname = "Jaxr Org";
  +            Organization org = blm.createOrganization(getIString(orgname));
  +            Collection orgs = new ArrayList();
  +            orgs.add(org);
  +            BulkResponse br = blm.saveOrganizations(orgs);
  +            if (br.getExceptions() != null)
  +            {
  +                fail("Save Organizations failed ");
  +            }
  +            orgKeys = br.getCollection();
  +            Iterator iter = orgKeys.iterator();
  +            while (iter.hasNext())
  +            {
  +                orgKey = (Key) iter.next();
  +            }
  +
  +
  +            org = (Organization) bqm.getRegistryObject(orgKey.getId(), LifeCycleManager.ORGANIZATION);
  +
  +            Service service = blm.createService(serviceName);
  +            org.addService(service);
  +            Collection services = new ArrayList();
  +            services.add(service);
  +            br = blm.saveServices(services);
  +            if (br.getExceptions() != null)
  +            {
  +                fail("Save Services failed ");
  +            }
  +            serviceKeys = br.getCollection();
  +            iter = serviceKeys.iterator();
  +            while (iter.hasNext())
  +            {
  +                serviceKey = (Key) iter.next();
  +            }
  +
  +            service = (Service) bqm.getRegistryObject(serviceKey.getId(), LifeCycleManager.SERVICE);
  +
  +            //Save some concepts
  +            Concept testConcept = (Concept) blm.createObject(LifeCycleManager.CONCEPT);
  +            testConcept.setName(blm.createInternationalString(conceptName));
  +            Collection concepts = new ArrayList();
  +            concepts.add(testConcept);
  +            br = blm.saveConcepts(concepts);
  +            if (br.getExceptions() != null)
  +            {
  +                fail("Save Concepts failed ");
  +            }
  +            conceptKeys = br.getCollection();
  +            iter = conceptKeys.iterator();
  +            while (iter.hasNext())
  +            {
  +                conceptKey = (Key) iter.next();
  +            }
  +
  +            testConcept = (Concept) bqm.getRegistryObject(conceptKey.getId(), LifeCycleManager.CONCEPT);
  +            SpecificationLink sl = blm.createSpecificationLink();
  +            sl.setSpecificationObject(testConcept);
  +            ServiceBinding sb = blm.createServiceBinding();
  +            sb.setDescription(blm.createInternationalString(sbDescription));
  +            sb.setAccessURI(accessURI);
  +            sb.addSpecificationLink(sl);
  +            service.addServiceBinding(sb);
  +            Collection sbs = new ArrayList();
  +            sbs.add(sb);
  +            br = blm.saveServiceBindings(sbs);
  +            if (br.getExceptions() != null)
  +            {
  +                fail("Save ServiceBindings failed ");
  +            }
  +
  +
  +            Collection specifications = new ArrayList();
  +            specifications.add(testConcept);
  +
  +            br = bqm.findServiceBindings(serviceKey, null, null, specifications);
  +            sbs = br.getCollection();
  +            iter = sbs.iterator();
  +            while (iter.hasNext())
  +            {
  +                sb = (ServiceBinding) iter.next();
  +                Service storedService = sb.getService();
  +                if (!(storedService.getName().getValue().equals(serviceName)))
  +                {
  +                    fail("Error: service name");
  +                }
  +                Organization storedOrg = storedService.getProvidingOrganization();
  +                if (!(storedOrg.getName().getValue().equals(orgname)))
  +                {
  +                    fail("Error: unexpected organization name \n");
  +                }
  +                if (!(sb.getDescription().getValue().equals(sbDescription)))
  +                {
  +                    fail("Error: servicebinding description");
  +                }
  +                if (!(sb.getAccessURI().equals(accessURI)))
  +                {
  +                    fail("Error: unexpected accessURI name");
  +                }
  +            }
  +
  +            //Lets update the ServiceBinding
  +            sbs = new ArrayList();
  +            sb.setAccessURI("http://newURI");
  +            sbs.add(sb);
  +            br = blm.saveServiceBindings(sbs);
  +            br = bqm.findServiceBindings(serviceKey, null, null, specifications);
  +            sbs = br.getCollection();
  +            iter = sbs.iterator();
  +            while (iter.hasNext())
  +            {
  +                sb = (ServiceBinding) iter.next();
  +                Service storedService = sb.getService();
  +                if (!(storedService.getName().getValue().equals(serviceName)))
  +                {
  +                    fail("Error: service name");
  +                }
  +                Organization storedOrg = storedService.getProvidingOrganization();
  +                if (!(storedOrg.getName().getValue().equals(orgname)))
  +                {
  +                    fail("Error: unexpected organization name \n");
  +                }
  +                if (!(sb.getDescription().getValue().equals(sbDescription)))
  +                {
  +                    fail("Error: servicebinding description");
  +                }
  +                if (!(sb.getAccessURI().equals("http://newURI")))
  +                {
  +                    fail("Error: unexpected accessURI name");
  +                }
  +            }
  +        } catch (Exception e)
  +        {
  +            e.printStackTrace();
  +            fail("Test has failed due to an exception ");
  +        } finally
  +        {
  +            try
  +            {
  +                if (conceptKeys != null)
  +                {
  +                    blm.deleteConcepts(conceptKeys);
  +                }
  +                if (sbKeys != null)
  +                {
  +                    blm.deleteServiceBindings(sbKeys);
  +                }
  +                if (serviceKeys != null)
  +                {
  +                    blm.deleteServices(serviceKeys);
  +                }
  +                if (orgKeys != null)
  +                {
  +                    blm.deleteOrganizations(orgKeys);
  +                }
  +
  +            } catch (JAXRException je)
  +            {
  +                fail("Cleanup of JAXR objects failed");
  +            }
  +        }
  +    } //end method
  +}
  
  
  



More information about the jboss-cvs-commits mailing list