001package org.apache.maven.scm.provider.integrity.command;
002
003/**
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.scm.CommandParameter;
023import org.apache.maven.scm.CommandParameters;
024import org.apache.maven.scm.ScmFileSet;
025import org.apache.maven.scm.ScmTestCase;
026import org.apache.maven.scm.log.ScmLogger;
027import org.apache.maven.scm.manager.ScmManager;
028import org.apache.maven.scm.manager.plexus.PlexusLogger;
029import org.apache.maven.scm.provider.integrity.command.checkout.IntegrityCheckOutCommand;
030import org.apache.maven.scm.provider.integrity.command.login.IntegrityLoginCommand;
031import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
032import org.apache.maven.scm.repository.ScmRepository;
033import org.codehaus.plexus.logging.LoggerManager;
034
035import java.text.SimpleDateFormat;
036import java.util.Date;
037
038/**
039 * Parent class IntegrityCommandTest for all Integrity Test Command executions
040 *
041 * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
042 * @version $Id: IntegrityCommandTest.java 1.1 2011/08/29 00:29:46EDT Cletus D'Souza (dsouza) Exp  $
043 */
044public abstract class IntegrityCommandTest
045    extends ScmTestCase
046{
047    // A simple date format to generate unique names for the test run
048    public static final SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
049
050    public static final String fileName = "NewFile_" + sdf.format( new Date() ) + ".txt";
051
052    // A locally pre-configured repository for use with executing Integrity SCM Commands
053    protected String testScmURL = "scm:integrity|dsouza/password@xpvm:7001|#/Code_Gen";
054
055    protected ScmManager scmManager;
056
057    protected ScmLogger logger;
058
059    protected IntegrityScmProviderRepository iRepo;
060
061    protected ScmFileSet fileSet;
062
063    protected CommandParameters parameters;
064
065    /**
066     * Sets up all commands for unit test execution
067     */
068    protected void setUp()
069        throws Exception
070    {
071        super.setUp();
072        // Set the Change Package ID to :bypass as we wont have a valid Change Pacakge ID for automated tests
073        System.setProperty( "maven.scm.integrity.cpid", ":bypass" );
074        // Initialize our scmManager
075        scmManager = getScmManager();
076        // Initialize our logger
077        LoggerManager loggerManager = (LoggerManager) getContainer().lookup( LoggerManager.ROLE );
078        logger = new PlexusLogger( loggerManager.getLoggerForComponent( ScmManager.ROLE ) );
079        // Construct the SCM Repository and initialize our command execution variables
080        ScmRepository repo = scmManager.makeScmRepository( testScmURL );
081        iRepo = (IntegrityScmProviderRepository) repo.getProviderRepository();
082        fileSet = new ScmFileSet( getTestFile( "target/test-execution" ) );
083        parameters = new CommandParameters();
084        // Set the tag name for our tag and branch commands
085        parameters.setString( CommandParameter.TAG_NAME,
086                              "Maven-${new java.text.SimpleDateFormat(\"yyyyMMddHHmmssSSS\").format(new Date())}" );
087        // Connect to the MKS Integrity Server
088        IntegrityLoginCommand login = new IntegrityLoginCommand();
089        login.setLogger( logger );
090        assertResultIsSuccess( login.execute( iRepo, fileSet, parameters ) );
091        // Then make sure we've got a sandbox to work with
092        IntegrityCheckOutCommand checkout = new IntegrityCheckOutCommand();
093        checkout.setLogger( logger );
094        assertResultIsSuccess( checkout.execute( iRepo, fileSet, parameters ) );
095    }
096}
097