1 package org.apache.maven.archiva.web.repository;
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 com.meterware.httpunit.PutMethodWebRequest;
23 import com.meterware.httpunit.WebRequest;
24 import com.meterware.httpunit.WebResponse;
25 import com.meterware.servletunit.ServletRunner;
26 import com.meterware.servletunit.ServletUnitClient;
27 import org.codehaus.plexus.PlexusConstants;
28 import org.codehaus.plexus.PlexusTestCase;
29 import org.codehaus.plexus.util.FileUtils;
30 import org.xml.sax.SAXException;
33 import java.io.IOException;
35 public class RepositoryServletTest
36 extends PlexusTestCase
38 private ServletUnitClient sc;
40 private String appserverBase;
42 protected void setUp()
47 appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
48 System.setProperty( "appserver.base", appserverBase );
49 System.setProperty( "derby.system.home", appserverBase );
51 ServletRunner sr = new ServletRunner();
52 sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
54 sc.getSession( true ).getServletContext().setAttribute( PlexusConstants.PLEXUS_KEY, getContainer() );
57 public void testPutWithMissingParentCollection()
58 throws IOException, SAXException
60 File repository = new File( appserverBase, "data/repositories/internal" );
61 FileUtils.deleteDirectory( repository );
63 WebRequest request = new PutMethodWebRequest( "http://localhost/repository/internal/path/to/artifact.jar",
64 getClass().getResourceAsStream( "/artifact.jar" ),
65 "application/octet-stream" );
66 WebResponse response = sc.getResponse( request );
67 assertNotNull( "No response received", response );
68 assertEquals( "file contents", "artifact.jar\n",
69 FileUtils.fileRead( new File( repository, "path/to/artifact.jar" ) ) );