View Javadoc
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   */
43  public abstract class IntegrityCommandTest
44      extends ScmTestCase
45  {
46      // A simple date format to generate unique names for the test run
47      public static final SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
48  
49      public static final String fileName = "NewFile_" + sdf.format( new Date() ) + ".txt";
50  
51      // A locally pre-configured repository for use with executing Integrity SCM Commands
52      protected String testScmURL = "scm:integrity|dsouza/password@xpvm:7001|#/Code_Gen";
53  
54      protected ScmManager scmManager;
55  
56      protected ScmLogger logger;
57  
58      protected IntegrityScmProviderRepository iRepo;
59  
60      protected ScmFileSet fileSet;
61  
62      protected CommandParameters parameters;
63  
64      /**
65       * Sets up all commands for unit test execution
66       */
67      protected void setUp()
68          throws Exception
69      {
70          super.setUp();
71          // Set the Change Package ID to :bypass as we wont have a valid Change Pacakge ID for automated tests
72          System.setProperty( "maven.scm.integrity.cpid", ":bypass" );
73          // Initialize our scmManager
74          scmManager = getScmManager();
75          // Initialize our logger
76          LoggerManager loggerManager = (LoggerManager) getContainer().lookup( LoggerManager.ROLE );
77          logger = new PlexusLogger( loggerManager.getLoggerForComponent( ScmManager.ROLE ) );
78          // Construct the SCM Repository and initialize our command execution variables
79          ScmRepository repo = scmManager.makeScmRepository( testScmURL );
80          iRepo = (IntegrityScmProviderRepository) repo.getProviderRepository();
81          fileSet = new ScmFileSet( getTestFile( "target/test-execution" ) );
82          parameters = new CommandParameters();
83          // Set the tag name for our tag and branch commands
84          parameters.setString( CommandParameter.TAG_NAME,
85                                "Maven-${new java.text.SimpleDateFormat(\"yyyyMMddHHmmssSSS\").format(new Date())}" );
86          // Connect to the MKS Integrity Server
87          IntegrityLoginCommand login = new IntegrityLoginCommand();
88          login.setLogger( logger );
89          assertResultIsSuccess( login.execute( iRepo, fileSet, parameters ) );
90          // Then make sure we've got a sandbox to work with
91          IntegrityCheckOutCommand checkout = new IntegrityCheckOutCommand();
92          checkout.setLogger( logger );
93          assertResultIsSuccess( checkout.execute( iRepo, fileSet, parameters ) );
94      }
95  }
96