1 package org.apache.maven.scm.provider.clearcase.command.checkout;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
35
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 }