View Javadoc

1   package org.apache.maven.archiva.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  /**
25   */
26  public class ArchivaDavResourceLocatorTest extends TestCase
27  {
28      ArchivaDavLocatorFactory factory;
29  
30      @Override
31      protected void setUp()
32          throws Exception
33      {
34          super.setUp();
35          factory = new ArchivaDavLocatorFactory();
36      }
37      
38      public void testAvoidDoubleSlashInHref()
39          throws Exception
40      {
41          String prefix = "http://myproxy/";
42          String href = "/repository/internal/";
43          ArchivaDavResourceLocator locator = getLocator(prefix, href);
44  
45          assertEquals("internal", locator.getRepositoryId());
46          assertEquals("", locator.getWorkspaceName());
47          assertEquals("", locator.getWorkspacePath());
48          assertEquals("http://myproxy/", locator.getPrefix());
49          assertEquals("http://myproxy/repository/internal/", locator.getHref(false));
50          assertEquals("http://myproxy/repository/internal/", locator.getHref(true));
51          assertEquals("/repository/internal", locator.getResourcePath());
52          assertEquals("/repository/internal", locator.getRepositoryPath());        
53      }
54  
55      public void testLocatorWithPrefixHref()
56          throws Exception
57      {
58          String prefix = "http://myproxy/";
59          String href = "/repository/internal";
60          ArchivaDavResourceLocator locator = getLocator(prefix, href);
61  
62          assertEquals("internal", locator.getRepositoryId());
63          assertEquals("", locator.getWorkspaceName());
64          assertEquals("", locator.getWorkspacePath());
65          assertEquals("http://myproxy/", locator.getPrefix());
66          assertEquals("http://myproxy/repository/internal", locator.getHref(false));
67          assertEquals("http://myproxy/repository/internal/", locator.getHref(true));
68          assertEquals("/repository/internal", locator.getResourcePath());
69          assertEquals("/repository/internal", locator.getRepositoryPath());
70      }
71  
72      public void testLocatorWithHrefThatContainsPrefix()
73          throws Exception
74      {
75          String prefix = "http://myproxy/";
76          String href = "http://myproxy/repository/internal";
77          ArchivaDavResourceLocator locator = getLocator(prefix, href);
78  
79          assertEquals("internal", locator.getRepositoryId());
80          assertEquals("", locator.getWorkspaceName());
81          assertEquals("", locator.getWorkspacePath());
82          assertEquals("http://myproxy/", locator.getPrefix());
83          assertEquals("http://myproxy/repository/internal", locator.getHref(false));
84          assertEquals("http://myproxy/repository/internal/", locator.getHref(true));
85          assertEquals("/repository/internal", locator.getResourcePath());
86          assertEquals("/repository/internal", locator.getRepositoryPath());
87      }
88  
89      public void testLocatorWithRootHref()
90          throws Exception
91      {
92          String prefix = "http://myproxy/";
93          String href = "/";
94          ArchivaDavResourceLocator locator = getLocator(prefix, href);
95  
96          assertEquals("", locator.getRepositoryId());
97          assertEquals("", locator.getWorkspaceName());
98          assertEquals("", locator.getWorkspacePath());
99          assertEquals("http://myproxy/", locator.getPrefix());
100         assertEquals("http://myproxy/", locator.getHref(false));
101         assertEquals("http://myproxy/", locator.getHref(true));
102         assertEquals("/", locator.getResourcePath());
103         assertEquals("/", locator.getRepositoryPath());
104     }
105     
106     private ArchivaDavResourceLocator getLocator( String prefix, String href )
107     {
108         return (ArchivaDavResourceLocator)factory.createResourceLocator(prefix, href);
109     }
110 }