View Javadoc
1   package org.apache.maven.scm.provider.clearcase.command.checkout;
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.ScmBranch;
23  import org.apache.maven.scm.ScmTestCase;
24  import org.apache.maven.scm.log.DefaultLog;
25  import org.apache.maven.scm.provider.clearcase.repository.ClearCaseScmProviderRepository;
26  import org.apache.maven.scm.providers.clearcase.settings.Settings;
27  import org.codehaus.plexus.util.Os;
28  import org.codehaus.plexus.util.cli.Commandline;
29  
30  import java.io.File;
31  import java.io.IOException;
32  
33  /**
34   * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
35   * @author <a href="mailto:frederic.mura@laposte.net">Frederic Mura</a>
36   */
37  public class ClearCaseCheckOutCommandTest
38      extends ScmTestCase
39  {
40      private Settings settings = null;
41  
42      private ClearCaseCheckOutCommand checkOutCommand = null;
43  
44      public void setUp()
45          throws Exception
46      {
47          super.setUp();
48          checkOutCommand = new ClearCaseCheckOutCommand();
49          checkOutCommand.setLogger( new DefaultLog() );
50          settings = new Settings();
51          checkOutCommand.setSettings( settings );
52      }
53  
54      public void testCreateViewCommandLine()
55          throws IOException
56      {
57          String viewName = "testView";
58          settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_DEFAULT );
59  
60          Commandline commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, null );
61          assertCommandLine( "cleartool mkview -snapshot -tag testView -vws " + checkOutCommand.getViewStore() +
62              "testView.vws " + getWorkingDirectory().getCanonicalPath(), getWorkingDirectory().getParentFile(),
63                                                                          commandLine );
64  
65          settings.setUseVWSParameter( false );
66          commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, null );
67          assertCommandLine( "cleartool mkview -snapshot -tag testView " + getWorkingDirectory().getCanonicalPath(),
68                             getWorkingDirectory().getParentFile(), commandLine );
69  
70          settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_LT );
71          settings.setUseVWSParameter( true );
72          commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, null );
73          assertCommandLine( "cleartool mkview -snapshot -tag testView " + getWorkingDirectory().getCanonicalPath(),
74                             getWorkingDirectory().getParentFile(), commandLine );
75  
76          settings.setUseVWSParameter( false );
77          commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, null );
78          assertCommandLine( "cleartool mkview -snapshot -tag testView " + getWorkingDirectory().getCanonicalPath(),
79                             getWorkingDirectory().getParentFile(), commandLine );
80  
81          settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_UCM );
82          String streamId = "streamIdentifier";
83          commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, streamId );
84          assertCommandLine( "cleartool mkview -snapshot -tag testView -stream " + streamId + " " +
85              getWorkingDirectory().getCanonicalPath(), getWorkingDirectory().getParentFile(), commandLine );
86  
87          settings.setUseVWSParameter( true );
88          commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, streamId );
89          assertCommandLine( "cleartool mkview -snapshot -tag testView -stream " + streamId + " -vws " +
90              checkOutCommand.getViewStore() + "testView.vws " + getWorkingDirectory().getCanonicalPath(),
91                             getWorkingDirectory().getParentFile(), commandLine );
92      }
93  
94      public void testUpdateConfigSpec()
95          throws Exception
96      {
97          settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_DEFAULT );
98  
99          File configSpecLocation;
100         if ( Os.isFamily( "windows" ) )
101         {
102             configSpecLocation = new File( "\\\\myserver\\configspecs\\testconfigspec.txt" );
103         }
104         else
105         {
106             configSpecLocation = new File( "/clearcase/configspecs/testconfigspec.txt" );
107         }
108 
109         Commandline commandLine =
110             checkOutCommand.createUpdateConfigSpecCommandLine( getWorkingDirectory(), configSpecLocation, "testView" );
111         assertCommandLine( "cleartool setcs -tag testView " + configSpecLocation, getWorkingDirectory(), commandLine );
112 
113         settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_LT );
114         commandLine =
115             checkOutCommand.createUpdateConfigSpecCommandLine( getWorkingDirectory(), configSpecLocation, "testView" );
116         assertCommandLine( "cleartool setcs -tag testView " + configSpecLocation, getWorkingDirectory(), commandLine );
117     }
118 
119     public void testCreateConfigSpec()
120     {
121         assertEquals( "element * CHECKEDOUT\n" + "element * /main/LATEST\n" + "load MYVOB/my/dir\n",
122                       checkOutCommand.createConfigSpec( "MYVOB/my/dir", null ) );
123         assertEquals( "element * CHECKEDOUT\n" + "element * MYTAG\n" + "element -directory * /main/LATEST\n" +
124             "load MYVOB/my/dir\n", checkOutCommand
125             .createConfigSpec( "MYVOB/my/dir", new ScmBranch( "MYTAG" ) ) );
126     }
127 
128     public void testGetStreamIdentifier()
129     {
130         String streamName = "stream35_v1.0";
131         String vobName = "pVob_35";
132         String streamIdentifier = checkOutCommand.getStreamIdentifier( streamName, vobName );
133         assertEquals( "stream:" + streamName + "@" + vobName, streamIdentifier );
134 
135         streamIdentifier = checkOutCommand.getStreamIdentifier( streamName, null );
136         assertNull( streamIdentifier );
137 
138         streamIdentifier = checkOutCommand.getStreamIdentifier( null, vobName );
139         assertNull( streamIdentifier );
140     }
141 }