001package org.apache.maven.scm.provider.clearcase.command.checkout; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.scm.ScmBranch; 023import org.apache.maven.scm.ScmTestCase; 024import org.apache.maven.scm.log.DefaultLog; 025import org.apache.maven.scm.provider.clearcase.repository.ClearCaseScmProviderRepository; 026import org.apache.maven.scm.providers.clearcase.settings.Settings; 027import org.codehaus.plexus.util.Os; 028import org.codehaus.plexus.util.cli.Commandline; 029 030import java.io.File; 031import java.io.IOException; 032 033/** 034 * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a> 035 * @author <a href="mailto:frederic.mura@laposte.net">Frederic Mura</a> 036 */ 037public class ClearCaseCheckOutCommandTest 038 extends ScmTestCase 039{ 040 private Settings settings = null; 041 042 private ClearCaseCheckOutCommand checkOutCommand = null; 043 044 public void setUp() 045 throws Exception 046 { 047 super.setUp(); 048 checkOutCommand = new ClearCaseCheckOutCommand(); 049 checkOutCommand.setLogger( new DefaultLog() ); 050 settings = new Settings(); 051 checkOutCommand.setSettings( settings ); 052 } 053 054 public void testCreateViewCommandLine() 055 throws IOException 056 { 057 String viewName = "testView"; 058 settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_DEFAULT ); 059 060 Commandline commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, null ); 061 assertCommandLine( "cleartool mkview -snapshot -tag testView -vws " + checkOutCommand.getViewStore() + 062 "testView.vws " + getWorkingDirectory().getCanonicalPath(), getWorkingDirectory().getParentFile(), 063 commandLine ); 064 065 settings.setUseVWSParameter( false ); 066 commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, null ); 067 assertCommandLine( "cleartool mkview -snapshot -tag testView " + getWorkingDirectory().getCanonicalPath(), 068 getWorkingDirectory().getParentFile(), commandLine ); 069 070 settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_LT ); 071 settings.setUseVWSParameter( true ); 072 commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, null ); 073 assertCommandLine( "cleartool mkview -snapshot -tag testView " + getWorkingDirectory().getCanonicalPath(), 074 getWorkingDirectory().getParentFile(), commandLine ); 075 076 settings.setUseVWSParameter( false ); 077 commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, null ); 078 assertCommandLine( "cleartool mkview -snapshot -tag testView " + getWorkingDirectory().getCanonicalPath(), 079 getWorkingDirectory().getParentFile(), commandLine ); 080 081 settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_UCM ); 082 String streamId = "streamIdentifier"; 083 commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, streamId ); 084 assertCommandLine( "cleartool mkview -snapshot -tag testView -stream " + streamId + " " + 085 getWorkingDirectory().getCanonicalPath(), getWorkingDirectory().getParentFile(), commandLine ); 086 087 settings.setUseVWSParameter( true ); 088 commandLine = checkOutCommand.createCreateViewCommandLine( getWorkingDirectory(), viewName, streamId ); 089 assertCommandLine( "cleartool mkview -snapshot -tag testView -stream " + streamId + " -vws " + 090 checkOutCommand.getViewStore() + "testView.vws " + getWorkingDirectory().getCanonicalPath(), 091 getWorkingDirectory().getParentFile(), commandLine ); 092 } 093 094 public void testUpdateConfigSpec() 095 throws Exception 096 { 097 settings.setClearcaseType( ClearCaseScmProviderRepository.CLEARCASE_DEFAULT ); 098 099 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}