PageRenderTime 647ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/StarteamScmProviderTest.java

https://github.com/intelchen/maven-scm
Java | 105 lines | 56 code | 21 blank | 28 comment | 0 complexity | db66b29e33025460aad941854cb5bb99 MD5 | raw file
  1. package org.apache.maven.scm.provider.starteam;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.maven.scm.ScmException;
  21. import org.apache.maven.scm.ScmTestCase;
  22. import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
  23. import java.io.File;
  24. /**
  25. * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a>
  26. */
  27. public class StarteamScmProviderTest
  28. extends ScmTestCase
  29. {
  30. public void testGoodGetRelativeFile()
  31. throws Exception
  32. {
  33. File basedir = new File( getBasedir() );
  34. File testDir = new File( basedir.getPath() + "/target/../target/testdir" );
  35. testDir.mkdirs();
  36. File testFile = new File( testDir, "testfile.txt" );
  37. testFile.createNewFile();
  38. String relativePath = StarteamScmProvider.getRelativePath( basedir, testFile );
  39. relativePath = relativePath.replace( '\\', '/' ) ;
  40. assertEquals( "not expected relativePath, found " + relativePath + " for file " + testFile.getPath()
  41. + " and baseDir " + basedir.getPath(),
  42. "target/testdir/testfile.txt", relativePath );
  43. }
  44. public void testBadGetRelativeFile()
  45. throws Exception
  46. {
  47. File basedir = new File( getBasedir() );
  48. File testDir1 = new File( basedir.getPath() + "/target/testdir1" );
  49. testDir1.mkdirs();
  50. File testDir2 = new File( basedir.getPath() + "/target/testdir2" );
  51. testDir2.mkdirs();
  52. File testFile = new File( testDir1, "testfile.txt" );
  53. testFile.createNewFile();
  54. try
  55. {
  56. StarteamScmProvider.getRelativePath( testDir2, testFile );
  57. fail( "Bad relative path found!" );
  58. }
  59. catch ( ScmException e )
  60. {
  61. }
  62. }
  63. /**
  64. * To specify multiple views url, we must use '|'( pipe ) as separator,
  65. * must separate host and port using |
  66. *
  67. * @throws Exception
  68. */
  69. public void testMultipleViewsUrl()
  70. throws Exception
  71. {
  72. String scmSpecificUrl = "user:password@host|1234|/project/rootview:subview/folder";
  73. //String scmSpecificUrl = "user:password@host|1234/project/rootview:subview/folder"; //should work as well
  74. StarteamScmProvider provider = new StarteamScmProvider();
  75. StarteamScmProviderRepository starteamProvider =
  76. (StarteamScmProviderRepository) provider.makeProviderScmRepository( scmSpecificUrl, '|' );
  77. assertEquals( "user", starteamProvider.getUser() );
  78. assertEquals( "password", starteamProvider.getPassword() );
  79. assertEquals( 1234, starteamProvider.getPort() );
  80. assertEquals( "host", starteamProvider.getHost() );
  81. assertEquals( "/project/rootview:subview/folder", starteamProvider.getPath() );
  82. assertEquals( "user:password@host:1234/project/rootview:subview/folder", starteamProvider.getFullUrl() );
  83. }
  84. }