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 */
043public abstract class IntegrityCommandTest
044    extends ScmTestCase
045{
046    // A simple date format to generate unique names for the test run
047    public static final SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
048
049    public static final String fileName = "NewFile_" + sdf.format( new Date() ) + ".txt";
050
051    // A locally pre-configured repository for use with executing Integrity SCM Commands
052    protected String testScmURL = "scm:integrity|dsouza/password@xpvm:7001|#/Code_Gen";
053
054    protected ScmManager scmManager;
055
056    protected ScmLogger logger;
057
058    protected IntegrityScmProviderRepository iRepo;
059
060    protected ScmFileSet fileSet;
061
062    protected CommandParameters parameters;
063
064    /**
065     * Sets up all commands for unit test execution
066     */
067    protected void setUp()
068        throws Exception
069    {
070        super.setUp();
071        // Set the Change Package ID to :bypass as we wont have a valid Change Pacakge ID for automated tests
072        System.setProperty( "maven.scm.integrity.cpid", ":bypass" );
073        // Initialize our scmManager
074        scmManager = getScmManager();
075        // Initialize our logger
076        LoggerManager loggerManager = (LoggerManager) getContainer().lookup( LoggerManager.ROLE );
077        logger = new PlexusLogger( loggerManager.getLoggerForComponent( ScmManager.ROLE ) );
078        // Construct the SCM Repository and initialize our command execution variables
079        ScmRepository repo = scmManager.makeScmRepository( testScmURL );
080        iRepo = (IntegrityScmProviderRepository) repo.getProviderRepository();
081        fileSet = new ScmFileSet( getTestFile( "target/test-execution" ) );
082        parameters = new CommandParameters();
083        // Set the tag name for our tag and branch commands
084        parameters.setString( CommandParameter.TAG_NAME,
085                              "Maven-${new java.text.SimpleDateFormat(\"yyyyMMddHHmmssSSS\").format(new Date())}" );
086        // Connect to the MKS Integrity Server
087        IntegrityLoginCommand login = new IntegrityLoginCommand();
088        login.setLogger( logger );
089        assertResultIsSuccess( login.execute( iRepo, fileSet, parameters ) );
090        // Then make sure we've got a sandbox to work with
091        IntegrityCheckOutCommand checkout = new IntegrityCheckOutCommand();
092        checkout.setLogger( logger );
093        assertResultIsSuccess( checkout.execute( iRepo, fileSet, parameters ) );
094    }
095}
096