Package org.apache.juddi.v3.tck

Source Code of org.apache.juddi.v3.tck.JUDDI_010_PublisherIntegrationTest

/*
* Copyright 2001-2009 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.juddi.v3.tck;

import java.rmi.RemoteException;
import java.util.List;

import javax.xml.ws.soap.SOAPFaultException;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.juddi.api_v3.DeletePublisher;
import org.apache.juddi.api_v3.GetAllPublisherDetail;
import org.apache.juddi.api_v3.GetPublisherDetail;
import org.apache.juddi.api_v3.Publisher;
import org.apache.juddi.api_v3.PublisherDetail;
import org.apache.juddi.api_v3.SavePublisher;
import org.apache.juddi.jaxb.EntityCreator;
import org.apache.juddi.v3.client.config.UDDIClient;
import org.apache.juddi.v3.client.transport.Transport;
import org.apache.juddi.v3_service.JUDDIApiPortType;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.uddi.api_v3.AuthToken;
import org.uddi.api_v3.GetAuthToken;
import org.uddi.v3_service.DispositionReportFaultMessage;
import org.uddi.v3_service.UDDISecurityPortType;

/**
* jUDDI specific tests
*
* @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
* @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
*/
public class JUDDI_010_PublisherIntegrationTest {

        private static Log logger = LogFactory.getLog(JUDDI_010_PublisherIntegrationTest.class);
        private static UDDIClient manager;
        private static UDDISecurityPortType security = null;
        private static JUDDIApiPortType publisher = null;
        private static String authInfo = null;

        @BeforeClass
        public static void startManager() throws ConfigurationException {
                Assume.assumeTrue(TckPublisher.isJUDDI());
                manager = new UDDIClient();
                manager.start();


                logger.debug("Getting auth tokens..");
                try {
                        Transport transport = manager.getTransport();

                        security = transport.getUDDISecurityService();
                        GetAuthToken getAuthToken = new GetAuthToken();
                        getAuthToken.setUserID(TckPublisher.getRootPublisherId());
                        getAuthToken.setCred(TckPublisher.getRootPassword());
                        authInfo = security.getAuthToken(getAuthToken).getAuthInfo();

                        publisher = transport.getJUDDIApiService();
                } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                        Assert.fail("Could not obtain authInfo token.");
                }
        }

        @AfterClass
        public static void stopManager() throws ConfigurationException {
                manager.stop();
        }

        @Test
        public void testAuthToken() {
                Assume.assumeTrue(TckPublisher.isUDDIAuthMode());
                try {
                        Transport transport = manager.getTransport();

                        UDDISecurityPortType securityService = transport.getUDDISecurityService();
                        GetAuthToken getAuthToken = new GetAuthToken();
                        getAuthToken.setUserID("root");
                        getAuthToken.setCred("");
                        AuthToken authToken = securityService.getAuthToken(getAuthToken);
                        logger.info("don't log auth tokens!!!");
                        Assert.assertNotNull(authToken);
                } catch (Exception e) {
                        logger.error(e);
                        Assert.fail();
                }
        }

        @Test
        public void testJoePublisher() {
                Assume.assumeTrue(TckPublisher.isJUDDI());
                //We can only test this if the publisher is not there already.
                //If it already there is probably has foreign key relationships.
                //This test should really only run on an empty database. Seed
                //data will be added if the root publisher is missing.
                if (!isExistPublisher(TckPublisher.getJoePublisherId())) {
                        saveJoePublisher();
                        deleteJoePublisher();
                }
        }

        @Test
        public void testSamSyndicator() {
                Assume.assumeTrue(TckPublisher.isJUDDI());
                //We can only test this if the publisher is not there already.
                if (!isExistPublisher(TckPublisher.getSamPublisherId())) {
                        saveSamSyndicator();
                        deleteSamSyndicator();
                }
        }

        @Test
        public void testGetAllPublishers() {
                Assume.assumeTrue(TckPublisher.isJUDDI());
                GetAllPublisherDetail gp = new GetAllPublisherDetail();
                gp.setAuthInfo(authInfo);
                try {
                        PublisherDetail publisherDetail = publisher.getAllPublisherDetail(gp);
                        Assert.assertTrue(publisherDetail.getPublisher().size() > 1);
                } catch (Exception e) {
                        logger.error(e);
                        Assert.fail();
                }
        }

        /**
         * Persists Joe Publisher to the database.
         *
         * @return - true if the published did not exist already, - false in all
         * other cases.
         */
        public boolean saveJoePublisher() {
                Assume.assumeTrue(TckPublisher.isJUDDI());
                if (!isExistPublisher(TckPublisher.getJoePublisherId())) {
                        savePublisher(TckPublisher.getJoePublisherId(), TckPublisher.JOE_PUBLISHER_XML);
                        return true;
                } else {
                        return false;
                }
        }

        /**
         * Removes Joe Publisher from the database, this will fail if there are
         * child objects attached; think Services etc.
         */
        public void deleteJoePublisher() {
                Assume.assumeTrue(TckPublisher.isJUDDI());
                deletePublisher(TckPublisher.getJoePublisherId());
        }

        /**
         * Persists Sam Syndicator to the database.
         *
         * @return publisherId
         */
        public String saveSamSyndicator() {
                Assume.assumeTrue(TckPublisher.isJUDDI());
                if (!isExistPublisher(TckPublisher.getSamPublisherId())) {
                        savePublisher(TckPublisher.getSamPublisherId(), TckPublisher.SAM_SYNDICATOR_XML);
                }
                return TckPublisher.getSamPublisherId();
        }

        /**
         * Removes Sam Syndicator from the database, this will fail if there are
         * child objects attached; think Services etc.
         */
        public void deleteSamSyndicator() {
                Assume.assumeTrue(TckPublisher.isJUDDI());
                deletePublisher(TckPublisher.getSamPublisherId());
        }

        private void savePublisher(String publisherId, String publisherXML) {
                try {
                        authInfo = TckSecurity.getAuthToken(security, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
                        logger.info("Saving new publisher: " + publisherXML);
                        SavePublisher sp = new SavePublisher();
                        sp.setAuthInfo(authInfo);
                        Publisher pubIn = (Publisher) EntityCreator.buildFromDoc(publisherXML, "org.apache.juddi.api_v3");
                        sp.getPublisher().add(pubIn);
                        publisher.savePublisher(sp);

                        // Now get the entity and check the values
                        GetPublisherDetail gp = new GetPublisherDetail();
                        gp.getPublisherId().add(publisherId);
                        gp.setAuthInfo(authInfo);
                        PublisherDetail pd = publisher.getPublisherDetail(gp);
                        List<Publisher> pubOutList = pd.getPublisher();
                        Publisher pubOut = pubOutList.get(0);

                        Assert.assertEquals(pubIn.getAuthorizedName(), pubOut.getAuthorizedName());
                        Assert.assertEquals(pubIn.getPublisherName(), pubOut.getPublisherName());
                        Assert.assertEquals(pubIn.getEmailAddress(), pubOut.getEmailAddress());
                        Assert.assertEquals(pubIn.isIsAdmin(), pubOut.isIsAdmin());
                        Assert.assertEquals(pubIn.isIsEnabled(), pubOut.isIsEnabled());
                        Assert.assertEquals(pubIn.getMaxBindingsPerService(), pubOut.getMaxBindingsPerService());
                        Assert.assertEquals(pubIn.getMaxBusinesses(), pubOut.getMaxBusinesses());
                        Assert.assertEquals(pubIn.getMaxServicePerBusiness(), pubOut.getMaxServicePerBusiness());
                        Assert.assertEquals(pubIn.getMaxTModels(), pubOut.getMaxTModels());

                        logger.debug("Querying for publisher: " + publisherXML);
                        //Querying for this publisher to make sure it's really gone
                        //We're expecting a invalid Key exception at this point.
                        PublisherDetail pdBeforeDelete = null;
                        try {
                                pdBeforeDelete = publisher.getPublisherDetail(gp);
                                Assert.assertNotNull(pdBeforeDelete);
                        } catch (Exception e) {
                                logger.error(e);
                                Assert.fail("We expected to find publisher " + publisherXML);
                        }

                } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                        Assert.fail("No exception should be thrown");
                }
        }

        private void deletePublisher(String publisherId) {
                try {
                        authInfo = TckSecurity.getAuthToken(security, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
                        logger.debug("Delete publisher: " + publisherId);
                        //Now deleting this publisher
                        DeletePublisher dp = new DeletePublisher();
                        dp.setAuthInfo(authInfo);
                        dp.getPublisherId().add(publisherId);
                        publisher.deletePublisher(dp);

                        logger.info("Querying for publisher: " + publisherId + " after deletion.");
                        //Querying for this publisher to make sure it's really gone
                        //We're expecting a invalid Key exception at this point.
                        GetPublisherDetail gp = new GetPublisherDetail();
                        gp.getPublisherId().add(publisherId);
                        gp.setAuthInfo(authInfo);
                        PublisherDetail pdAfterDelete = null;
                        try {
                                pdAfterDelete = publisher.getPublisherDetail(gp);
                                Assert.fail("We did not expect to find this publisher anymore.");
                                //don't think we really want a SOAPFaulException be thrown here.
                        } catch (SOAPFaultException e) {
                                Assert.assertNull(pdAfterDelete);
                        }

                } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                        Assert.fail("No exception should be thrown");
                }
        }

        private boolean isExistPublisher(String publisherId) {
                GetPublisherDetail gp = new GetPublisherDetail();
                gp.setAuthInfo(authInfo);
                gp.getPublisherId().add(publisherId);
                try {
                        publisher.getPublisherDetail(gp);
                        return true;
                } catch (Exception e) {
                        return false;
                }
        }

        protected String authInfoJoe() throws RemoteException, DispositionReportFaultMessage {
                return TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
        }

        protected String authInfoSam() throws RemoteException, DispositionReportFaultMessage {
                return TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(), TckPublisher.getSamPassword());
        }

}
TOP

Related Classes of org.apache.juddi.v3.tck.JUDDI_010_PublisherIntegrationTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.