001package org.apache.maven.scm.provider.starteam; 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.ScmException; 023import org.apache.maven.scm.ScmTestCase; 024import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository; 025 026import java.io.File; 027 028/** 029 * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a> 030 */ 031public class StarteamScmProviderTest 032 extends ScmTestCase 033{ 034 035 public void testGoodGetRelativeFile() 036 throws Exception 037 { 038 File basedir = new File( getBasedir() ); 039 040 File testDir = new File( basedir.getPath() + "/target/../target/testdir" ); 041 042 testDir.mkdirs(); 043 044 File testFile = new File( testDir, "testfile.txt" ); 045 046 testFile.createNewFile(); 047 048 String relativePath = StarteamScmProvider.getRelativePath( basedir, testFile ); 049 relativePath = relativePath.replace( '\\', '/' ) ; 050 assertEquals( "not expected relativePath, found " + relativePath + " for file " + testFile.getPath() 051 + " and baseDir " + basedir.getPath(), 052 "target/testdir/testfile.txt", relativePath ); 053 054 } 055 056 public void testBadGetRelativeFile() 057 throws Exception 058 { 059 File basedir = new File( getBasedir() ); 060 061 File testDir1 = new File( basedir.getPath() + "/target/testdir1" ); 062 testDir1.mkdirs(); 063 064 File testDir2 = new File( basedir.getPath() + "/target/testdir2" ); 065 testDir2.mkdirs(); 066 067 File testFile = new File( testDir1, "testfile.txt" ); 068 069 testFile.createNewFile(); 070 071 try 072 { 073 StarteamScmProvider.getRelativePath( testDir2, testFile ); 074 fail( "Bad relative path found!" ); 075 } 076 catch ( ScmException e ) 077 { 078 079 } 080 081 } 082 083 /** 084 * To specify multiple views url, we must use '|'( pipe ) as separator, 085 * must separate host and port using | 086 * 087 * @throws Exception 088 */ 089 public void testMultipleViewsUrl() 090 throws Exception 091 { 092 String scmSpecificUrl = "user:password@host|1234|/project/rootview:subview/folder"; 093 //String scmSpecificUrl = "user:password@host|1234/project/rootview:subview/folder"; //should work as well 094 StarteamScmProvider provider = new StarteamScmProvider(); 095 StarteamScmProviderRepository starteamProvider = 096 (StarteamScmProviderRepository) provider.makeProviderScmRepository( scmSpecificUrl, '|' ); 097 assertEquals( "user", starteamProvider.getUser() ); 098 assertEquals( "password", starteamProvider.getPassword() ); 099 assertEquals( 1234, starteamProvider.getPort() ); 100 assertEquals( "host", starteamProvider.getHost() ); 101 assertEquals( "/project/rootview:subview/folder", starteamProvider.getPath() ); 102 assertEquals( "user:password@host:1234/project/rootview:subview/folder", starteamProvider.getFullUrl() ); 103 } 104 105}