View Javadoc

1   package org.apache.continuum.webdav;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  public class ContinuumBuildAgentDavResourceLocatorTest
25      extends TestCase
26  {
27      private ContinuumBuildAgentDavLocatorFactory factory;
28  
29      private ContinuumBuildAgentDavResourceLocator locator;
30  
31      @Override
32      protected void setUp()
33          throws Exception
34      {
35          super.setUp();
36          factory = new ContinuumBuildAgentDavLocatorFactory();
37      }
38  
39      public void testAvoidDoubleSlashInHref()
40          throws Exception
41      {
42          String prefix = "http://myhost/";
43          String href = "/workingcopy/1/";
44          locator = getLocator( prefix, href );
45  
46          assertEquals( 1, locator.getProjectId() );
47          assertEquals( "", locator.getWorkspaceName() );
48          assertEquals( "", locator.getWorkspacePath() );
49          assertEquals( "http://myhost/", locator.getPrefix() );
50          assertEquals( "http://myhost/workingcopy/1/", locator.getHref( false ) );
51          assertEquals( "http://myhost/workingcopy/1/", locator.getHref( true ) );
52          assertEquals( "/workingcopy/1", locator.getResourcePath() );
53          assertEquals( "/workingcopy/1", locator.getRepositoryPath() );
54      }
55  
56      public void testLocatorWithPrefixHref()
57          throws Exception
58      {
59          String prefix = "http://myhost/";
60          String href = "/workingcopy/1";
61          locator = getLocator( prefix, href );
62  
63          assertEquals( 1, locator.getProjectId() );
64          assertEquals( "", locator.getWorkspaceName() );
65          assertEquals( "", locator.getWorkspacePath() );
66          assertEquals( "http://myhost/", locator.getPrefix() );
67          assertEquals( "http://myhost/workingcopy/1", locator.getHref( false ) );
68          assertEquals( "http://myhost/workingcopy/1/", locator.getHref( true ) );
69          assertEquals( "/workingcopy/1", locator.getResourcePath() );
70          assertEquals( "/workingcopy/1", locator.getRepositoryPath() );
71      }
72  
73      public void testLocatorWithHrefThatContainsPrefix()
74          throws Exception
75      {
76          String prefix = "http://myhost/";
77          String href = "http://myhost/workingcopy/1";
78          locator = getLocator( prefix, href );
79  
80          assertEquals( 1, locator.getProjectId() );
81          assertEquals( "", locator.getWorkspaceName() );
82          assertEquals( "", locator.getWorkspacePath() );
83          assertEquals( "http://myhost/", locator.getPrefix() );
84          assertEquals( "http://myhost/workingcopy/1", locator.getHref( false ) );
85          assertEquals( "http://myhost/workingcopy/1/", locator.getHref( true ) );
86          assertEquals( "/workingcopy/1", locator.getResourcePath() );
87          assertEquals( "/workingcopy/1", locator.getRepositoryPath() );
88      }
89  
90      public void testLocatorWithRootHref()
91          throws Exception
92      {
93          String prefix = "http://myhost/";
94          String href = "/";
95          locator = getLocator( prefix, href );
96  
97          assertEquals( 0, locator.getProjectId() );
98          assertEquals( "", locator.getWorkspaceName() );
99          assertEquals( "", locator.getWorkspacePath() );
100         assertEquals( "http://myhost/", locator.getPrefix() );
101         assertEquals( "http://myhost/", locator.getHref( false ) );
102         assertEquals( "http://myhost/", locator.getHref( true ) );
103         assertEquals( "/", locator.getResourcePath() );
104         assertEquals( "/", locator.getRepositoryPath() );
105     }
106 
107     private ContinuumBuildAgentDavResourceLocator getLocator( String prefix, String href )
108     {
109         return (ContinuumBuildAgentDavResourceLocator) factory.createResourceLocator( prefix, href );
110     }
111 }