1 package org.apache.archiva.webdav;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import junit.framework.TestCase;
26 public class ArchivaDavResourceLocatorTest
29 ArchivaDavLocatorFactory factory;
32 protected void setUp()
36 factory = new ArchivaDavLocatorFactory();
39 public void testAvoidDoubleSlashInHref()
42 String prefix = "http://myproxy/";
43 String href = "/repository/internal/";
44 ArchivaDavResourceLocator locator = getLocator( prefix, href );
46 assertEquals( "internal", locator.getRepositoryId() );
47 assertEquals( "", locator.getWorkspaceName() );
48 assertEquals( "", locator.getWorkspacePath() );
49 assertEquals( "http://myproxy/", locator.getPrefix() );
50 assertEquals( "http://myproxy/repository/internal/", locator.getHref( false ) );
51 assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
52 assertEquals( "/repository/internal", locator.getResourcePath() );
53 assertEquals( "/repository/internal", locator.getRepositoryPath() );
56 public void testLocatorWithPrefixHref()
59 String prefix = "http://myproxy/";
60 String href = "/repository/internal";
61 ArchivaDavResourceLocator locator = getLocator( prefix, href );
63 assertEquals( "internal", locator.getRepositoryId() );
64 assertEquals( "", locator.getWorkspaceName() );
65 assertEquals( "", locator.getWorkspacePath() );
66 assertEquals( "http://myproxy/", locator.getPrefix() );
67 assertEquals( "http://myproxy/repository/internal", locator.getHref( false ) );
68 assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
69 assertEquals( "/repository/internal", locator.getResourcePath() );
70 assertEquals( "/repository/internal", locator.getRepositoryPath() );
73 public void testLocatorWithHrefThatContainsPrefix()
76 String prefix = "http://myproxy/";
77 String href = "http://myproxy/repository/internal";
78 ArchivaDavResourceLocator locator = getLocator( prefix, href );
80 assertEquals( "internal", locator.getRepositoryId() );
81 assertEquals( "", locator.getWorkspaceName() );
82 assertEquals( "", locator.getWorkspacePath() );
83 assertEquals( "http://myproxy/", locator.getPrefix() );
84 assertEquals( "http://myproxy/repository/internal", locator.getHref( false ) );
85 assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
86 assertEquals( "/repository/internal", locator.getResourcePath() );
87 assertEquals( "/repository/internal", locator.getRepositoryPath() );
90 public void testLocatorWithRootHref()
93 String prefix = "http://myproxy/";
95 ArchivaDavResourceLocator locator = getLocator( prefix, href );
97 assertEquals( "", locator.getRepositoryId() );
98 assertEquals( "", locator.getWorkspaceName() );
99 assertEquals( "", locator.getWorkspacePath() );
100 assertEquals( "http://myproxy/", locator.getPrefix() );
101 assertEquals( "http://myproxy/", locator.getHref( false ) );
102 assertEquals( "http://myproxy/", locator.getHref( true ) );
103 assertEquals( "/", locator.getResourcePath() );
104 assertEquals( "/", locator.getRepositoryPath() );
107 private ArchivaDavResourceLocator getLocator( String prefix, String href )
109 return (ArchivaDavResourceLocator) factory.createResourceLocator( prefix, href );