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