View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.provider.svn;
20  
21  import org.apache.maven.scm.ScmTestCase;
22  import org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertTrue;
26  import static org.junit.Assert.fail;
27  
28  /**
29   * @author <a href="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a>
30   *
31   */
32  public class SvnCommandUtilsTest extends ScmTestCase {
33      // ----------------------------------------------------------------------
34      // appendPath
35      // ----------------------------------------------------------------------
36  
37      @Test
38      public void testFixUrlHttpUrlsAreIgnored() throws Exception {
39          String unchanged = "http://foo.com/svn/myproject/tags/foo";
40          assertEquals(unchanged, SvnCommandUtils.fixUrl(unchanged, null));
41          assertEquals(unchanged, SvnCommandUtils.fixUrl(unchanged, ""));
42          assertEquals(unchanged, SvnCommandUtils.fixUrl(unchanged, "user"));
43      }
44  
45      @Test
46      public void testFixUrlNPEifNullURL() throws Exception {
47          try {
48              SvnCommandUtils.fixUrl(null, "user");
49              fail("expected NPE");
50          } catch (NullPointerException e) {
51              assertTrue(true); // expected
52          }
53      }
54  
55      @Test
56      public void testFixUrlSvnSshUrlsUsernameIsAddedWhenUserSpecified() throws Exception {
57          assertEquals(
58                  "svn+ssh://foo.com/svn/myproject", SvnCommandUtils.fixUrl("svn+ssh://foo.com/svn/myproject", null));
59          assertEquals("svn+ssh://foo.com/svn/myproject", SvnCommandUtils.fixUrl("svn+ssh://foo.com/svn/myproject", ""));
60          assertEquals(
61                  "svn+ssh://user@foo.com/svn/myproject",
62                  SvnCommandUtils.fixUrl("svn+ssh://foo.com/svn/myproject", "user"));
63      }
64  
65      @Test
66      public void testFixUrlSvnSshUrlsUsernameIsOverridenWhenUserSpecified() throws Exception {
67          assertEquals(
68                  "svn+ssh://user1@foo.com/svn/myproject",
69                  SvnCommandUtils.fixUrl("svn+ssh://user1@foo.com/svn/myproject", null));
70          assertEquals(
71                  "svn+ssh://user1@foo.com/svn/myproject",
72                  SvnCommandUtils.fixUrl("svn+ssh://user1@foo.com/svn/myproject", ""));
73          assertEquals(
74                  "svn+ssh://user2@foo.com/svn/myproject",
75                  SvnCommandUtils.fixUrl("svn+ssh://user1@foo.com/svn/myproject", "user2"));
76      }
77  }