001    /*
002     * file CcDemoBase.java
003     *
004     * Licensed Materials - Property of IBM
005     * Restricted Materials of IBM - you are allowed to copy, modify and 
006     * redistribute this file as part of any program that interfaces with 
007     * IBM Rational CM API.
008     *
009     * com.ibm.rational.stp.client.samples.cc.CcDemoBase
010     *
011     * © Copyright IBM Corporation 2008.  All Rights Reserved.
012     * Note to U.S. Government Users Restricted Rights:  Use, duplication or 
013     * disclosure restricted by GSA ADP  Schedule Contract with IBM Corp.
014     */
015    
016    package com.ibm.rational.stp.client.samples.cc;
017    
018    import javax.wvcm.ProviderFactory;
019    import javax.wvcm.WvcmException;
020    import javax.wvcm.ProviderFactory.Callback;
021    import javax.wvcm.WvcmException.ReasonCode;
022    
023    import junit.framework.TestCase;
024    
025    import com.ibm.rational.wvcm.stp.StpProvider;
026    import com.ibm.rational.wvcm.stp.cc.CcProvider;
027    
028    /**
029     * TODO
030     */
031    public class CcDemoBase extends TestCase {
032    
033        public class DefaultCallback implements Callback {
034    
035            public Authentication getAuthentication(String realm, int retryCount)
036                throws WvcmException
037            {
038                trace("Getting credentials");
039                if (retryCount > 0) {
040                    throw new WvcmException("Invalid credentials", ReasonCode.UNAUTHORIZED);
041                }
042                return new Authentication() {
043                    public String loginName() {
044                        return props().getLoginNameAndDomain();
045                    }
046                    public String password() {
047                        return props().getPassword();
048                    }
049                };
050            }
051        }
052    
053        private CcDemoProps m_props;
054        private CcProvider m_provider;
055    
056        /* (non-Javadoc)
057         * @see junit.framework.TestCase#setUp()
058         */
059        protected void setUp() throws Exception {
060            super.setUp();
061    
062            // Read the current user's properties file.
063            m_props = new CcDemoProps();
064    
065            // Instantiate a ClearCase CM API provider
066            StpProvider provider = (StpProvider) ProviderFactory.createProvider(
067                    CcProvider.CC_ONLY_PROVIDER_CLASS,
068                    new DefaultCallback());
069            provider.setServerUrl(props().getCmServerUrl());
070            m_provider = provider.ccProvider();
071        }
072    
073        /* (non-Javadoc)
074         * @see junit.framework.TestCase#tearDown()
075         */
076        protected void tearDown() throws Exception {
077            super.tearDown();
078        }
079    
080        CcDemoProps props() {
081            return m_props;
082        }
083    
084        CcProvider getClearCaseProvider() {
085            return m_provider;
086        }
087    
088        void trace(String msg) {
089            System.out.println(msg);
090        }
091    }