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;
23 import org.apache.archiva.test.ArchivaBlockJUnit4ClassRunner;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
30 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
31 public class ArchivaDavResourceLocatorTest
34 ArchivaDavLocatorFactory factory;
42 factory = new ArchivaDavLocatorFactory();
46 public void testAvoidDoubleSlashInHref()
49 String prefix = "http://myproxy/";
50 String href = "/repository/internal/";
51 ArchivaDavResourceLocator locator = getLocator( prefix, href );
53 assertEquals( "internal", locator.getRepositoryId() );
54 assertEquals( "", locator.getWorkspaceName() );
55 assertEquals( "", locator.getWorkspacePath() );
56 assertEquals( "http://myproxy/", locator.getPrefix() );
57 assertEquals( "http://myproxy/repository/internal/", locator.getHref( false ) );
58 assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
59 assertEquals( "/repository/internal", locator.getResourcePath() );
60 assertEquals( "/repository/internal", locator.getRepositoryPath() );
64 public void testLocatorWithPrefixHref()
67 String prefix = "http://myproxy/";
68 String href = "/repository/internal";
69 ArchivaDavResourceLocator locator = getLocator( prefix, href );
71 assertEquals( "internal", locator.getRepositoryId() );
72 assertEquals( "", locator.getWorkspaceName() );
73 assertEquals( "", locator.getWorkspacePath() );
74 assertEquals( "http://myproxy/", locator.getPrefix() );
75 assertEquals( "http://myproxy/repository/internal", locator.getHref( false ) );
76 assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
77 assertEquals( "/repository/internal", locator.getResourcePath() );
78 assertEquals( "/repository/internal", locator.getRepositoryPath() );
82 public void testLocatorWithHrefThatContainsPrefix()
85 String prefix = "http://myproxy/";
86 String href = "http://myproxy/repository/internal";
87 ArchivaDavResourceLocator locator = getLocator( prefix, href );
89 assertEquals( "internal", locator.getRepositoryId() );
90 assertEquals( "", locator.getWorkspaceName() );
91 assertEquals( "", locator.getWorkspacePath() );
92 assertEquals( "http://myproxy/", locator.getPrefix() );
93 assertEquals( "http://myproxy/repository/internal", locator.getHref( false ) );
94 assertEquals( "http://myproxy/repository/internal/", locator.getHref( true ) );
95 assertEquals( "/repository/internal", locator.getResourcePath() );
96 assertEquals( "/repository/internal", locator.getRepositoryPath() );
100 public void testLocatorWithRootHref()
103 String prefix = "http://myproxy/";
105 ArchivaDavResourceLocator locator = getLocator( prefix, href );
107 assertEquals( "", locator.getRepositoryId() );
108 assertEquals( "", locator.getWorkspaceName() );
109 assertEquals( "", locator.getWorkspacePath() );
110 assertEquals( "http://myproxy/", locator.getPrefix() );
111 assertEquals( "http://myproxy/", locator.getHref( false ) );
112 assertEquals( "http://myproxy/", locator.getHref( true ) );
113 assertEquals( "/", locator.getResourcePath() );
114 assertEquals( "/", locator.getRepositoryPath() );
117 private ArchivaDavResourceLocator getLocator( String prefix, String href )
119 return (ArchivaDavResourceLocator) factory.createResourceLocator( prefix, href );