1   package org.apache.maven.scm.provider.integrity.command;
2   
3   /**
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.CommandParameter;
23  import org.apache.maven.scm.CommandParameters;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.ScmTestCase;
26  import org.apache.maven.scm.log.ScmLogger;
27  import org.apache.maven.scm.manager.ScmManager;
28  import org.apache.maven.scm.manager.plexus.PlexusLogger;
29  import org.apache.maven.scm.provider.integrity.command.checkout.IntegrityCheckOutCommand;
30  import org.apache.maven.scm.provider.integrity.command.login.IntegrityLoginCommand;
31  import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
32  import org.apache.maven.scm.repository.ScmRepository;
33  import org.codehaus.plexus.logging.LoggerManager;
34  
35  import java.text.SimpleDateFormat;
36  import java.util.Date;
37  
38  /**
39   * Parent class IntegrityCommandTest for all Integrity Test Command executions
40   *
41   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
42   * @version $Id: IntegrityCommandTest.java 1.1 2011/08/29 00:29:46EDT Cletus D'Souza (dsouza) Exp  $
43   */
44  public abstract class IntegrityCommandTest
45      extends ScmTestCase
46  {
47      // A simple date format to generate unique names for the test run
48      public static final SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
49  
50      public static final String fileName = "NewFile_" + sdf.format( new Date() ) + ".txt";
51  
52      // A locally pre-configured repository for use with executing Integrity SCM Commands
53      protected String testScmURL = "scm:integrity|dsouza/password@xpvm:7001|#/Code_Gen";
54  
55      protected ScmManager scmManager;
56  
57      protected ScmLogger logger;
58  
59      protected IntegrityScmProviderRepository iRepo;
60  
61      protected ScmFileSet fileSet;
62  
63      protected CommandParameters parameters;
64  
65      /**
66       * Sets up all commands for unit test execution
67       */
68      protected void setUp()
69          throws Exception
70      {
71          super.setUp();
72          // Set the Change Package ID to :bypass as we wont have a valid Change Pacakge ID for automated tests
73          System.setProperty( "maven.scm.integrity.cpid", ":bypass" );
74          // Initialize our scmManager
75          scmManager = getScmManager();
76          // Initialize our logger
77          LoggerManager loggerManager = (LoggerManager) getContainer().lookup( LoggerManager.ROLE );
78          logger = new PlexusLogger( loggerManager.getLoggerForComponent( ScmManager.ROLE ) );
79          // Construct the SCM Repository and initialize our command execution variables
80          ScmRepository repo = scmManager.makeScmRepository( testScmURL );
81          iRepo = (IntegrityScmProviderRepository) repo.getProviderRepository();
82          fileSet = new ScmFileSet( getTestFile( "target/test-execution" ) );
83          parameters = new CommandParameters();
84          // Set the tag name for our tag and branch commands
85          parameters.setString( CommandParameter.TAG_NAME,
86                                "Maven-${new java.text.SimpleDateFormat(\"yyyyMMddHHmmssSSS\").format(new Date())}" );
87          // Connect to the MKS Integrity Server
88          IntegrityLoginCommand login = new IntegrityLoginCommand();
89          login.setLogger( logger );
90          assertResultIsSuccess( login.execute( iRepo, fileSet, parameters ) );
91          // Then make sure we've got a sandbox to work with
92          IntegrityCheckOutCommand checkout = new IntegrityCheckOutCommand();
93          checkout.setLogger( logger );
94          assertResultIsSuccess( checkout.execute( iRepo, fileSet, parameters ) );
95      }
96  }
97