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
23 import com.gargoylesoftware.htmlunit.WebRequest;
24 import com.gargoylesoftware.htmlunit.WebResponse;
25 import org.junit.Before;
26 import org.junit.Test;
28 import javax.servlet.http.HttpServletResponse;
32 * RepositoryServletBrowseTest
36 public class RepositoryServletBrowseTest
37 extends AbstractRepositoryServletTestCase
46 new File( repoRootInternal, "org/apache/archiva" ).mkdirs();
47 new File( repoRootInternal, "org/codehaus/mojo/" ).mkdirs();
48 new File( repoRootInternal, "net/sourceforge" ).mkdirs();
49 new File( repoRootInternal, "commons-lang" ).mkdirs();
53 public void testBrowse()
56 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" );
57 WebResponse response = getServletUnitClient().getResponse( request );
58 assertEquals( "Response", HttpServletResponse.SC_OK, response.getStatusCode() );
60 // dumpResponse( response );
62 String expectedLinks[] = new String[]{ ".indexer/", "commons-lang/", "net/", "org/" };
64 //assertLinks( expectedLinks, response.getLinks() );
68 public void testBrowseSubdirectory()
71 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/org" );
72 WebResponse response = getServletUnitClient().getResponse( request );
73 assertEquals( "Response", HttpServletResponse.SC_OK, response.getStatusCode() );
75 String expectedLinks[] = new String[]{ "../", "apache/", "codehaus/" };
77 //assertLinks( expectedLinks, response.getLinks() );
81 public void testGetDirectoryWhichHasMatchingFile() //MRM-893
84 new File( repoRootInternal, "org/apache/archiva/artifactId/1.0" ).mkdirs();
85 new File( repoRootInternal, "org/apache/archiva/artifactId/1.0/artifactId-1.0.jar" ).createNewFile();
88 new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId" );
89 WebResponse response = getServletUnitClient().getResponse( request );
90 assertEquals( "1st Response", HttpServletResponse.SC_OK, response.getStatusCode() );
92 request = new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId/" );
93 response = getServletUnitClient().getResponse( request );
94 assertEquals( "2nd Response", HttpServletResponse.SC_OK, response.getStatusCode() );
96 request = new GetMethodWebRequest(
97 "http://machine.com/repository/internal/org/apache/archiva/artifactId/1.0/artifactId-1.0.jar" );
98 response = getServletUnitClient().getResponse( request );
99 assertEquals( "3rd Response", HttpServletResponse.SC_OK, response.getStatusCode() );
101 request = new GetMethodWebRequest(
102 "http://machine.com/repository/internal/org/apache/archiva/artifactId/1.0/artifactId-1.0.jar/" );
103 response = getServletUnitClient().getResponse( request );
104 assertEquals( "4th Response", HttpServletResponse.SC_NOT_FOUND, response.getStatusCode() );
109 private void assertLinks( String expectedLinks[], WebLink actualLinks[] )
111 assertEquals( "Links.length", expectedLinks.length, actualLinks.length );
112 for ( int i = 0; i < actualLinks.length; i++ )
114 assertEquals( "Link[" + i + "]", expectedLinks[i], actualLinks[i].getURLString() );