001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.svn; 020 021import org.apache.maven.scm.ScmTestCase; 022import org.junit.Test; 023 024import static org.junit.Assert.assertEquals; 025import static org.junit.Assert.assertTrue; 026import static org.junit.Assert.fail; 027 028/** 029 * @author <a href="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a> 030 * 031 */ 032public class SvnCommandUtilsTest extends ScmTestCase { 033 // ---------------------------------------------------------------------- 034 // appendPath 035 // ---------------------------------------------------------------------- 036 037 @Test 038 public void testFixUrlHttpUrlsAreIgnored() throws Exception { 039 String unchanged = "http://foo.com/svn/myproject/tags/foo"; 040 assertEquals(unchanged, SvnCommandUtils.fixUrl(unchanged, null)); 041 assertEquals(unchanged, SvnCommandUtils.fixUrl(unchanged, "")); 042 assertEquals(unchanged, SvnCommandUtils.fixUrl(unchanged, "user")); 043 } 044 045 @Test 046 public void testFixUrlNPEifNullURL() throws Exception { 047 try { 048 SvnCommandUtils.fixUrl(null, "user"); 049 fail("expected NPE"); 050 } catch (NullPointerException e) { 051 assertTrue(true); // expected 052 } 053 } 054 055 @Test 056 public void testFixUrlSvnSshUrlsUsernameIsAddedWhenUserSpecified() throws Exception { 057 assertEquals( 058 "svn+ssh://foo.com/svn/myproject", SvnCommandUtils.fixUrl("svn+ssh://foo.com/svn/myproject", null)); 059 assertEquals("svn+ssh://foo.com/svn/myproject", SvnCommandUtils.fixUrl("svn+ssh://foo.com/svn/myproject", "")); 060 assertEquals( 061 "svn+ssh://user@foo.com/svn/myproject", 062 SvnCommandUtils.fixUrl("svn+ssh://foo.com/svn/myproject", "user")); 063 } 064 065 @Test 066 public void testFixUrlSvnSshUrlsUsernameIsOverridenWhenUserSpecified() throws Exception { 067 assertEquals( 068 "svn+ssh://user1@foo.com/svn/myproject", 069 SvnCommandUtils.fixUrl("svn+ssh://user1@foo.com/svn/myproject", null)); 070 assertEquals( 071 "svn+ssh://user1@foo.com/svn/myproject", 072 SvnCommandUtils.fixUrl("svn+ssh://user1@foo.com/svn/myproject", "")); 073 assertEquals( 074 "svn+ssh://user2@foo.com/svn/myproject", 075 SvnCommandUtils.fixUrl("svn+ssh://user1@foo.com/svn/myproject", "user2")); 076 } 077}