1 package org.apache.maven.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 org.apache.archiva.admin.repository.managed.ManagedRepository;
23 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.Configuration;
25 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.apache.maven.archiva.webdav.RepositoryServlet;
28 import com.meterware.httpunit.GetMethodWebRequest;
29 import com.meterware.httpunit.WebRequest;
30 import com.meterware.httpunit.WebResponse;
31 import org.junit.Test;
36 * RepositoryServletTest
40 public class RepositoryServletTest
41 extends AbstractRepositoryServletTestCase
43 private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
45 private static final String NEW_REPOSITORY_ID = "new-id";
47 private static final String NEW_REPOSITORY_NAME = "New Repository";
50 public void testGetRepository()
53 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
54 assertNotNull( servlet );
56 assertRepositoryValid( servlet, REPOID_INTERNAL );
60 public void testGetRepositoryAfterDelete()
63 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
64 assertNotNull( servlet );
66 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
67 Configuration c = archivaConfiguration.getConfiguration();
68 c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
69 saveConfiguration( archivaConfiguration );
71 ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL );
72 assertNull( repository );
76 public void testGetRepositoryAfterAdd()
79 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
80 assertNotNull( servlet );
82 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
83 Configuration c = archivaConfiguration.getConfiguration();
84 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
85 repo.setId( NEW_REPOSITORY_ID );
86 repo.setName( NEW_REPOSITORY_NAME );
87 File repoRoot = new File( "target/test-repository-root" );
88 if ( !repoRoot.exists() )
92 repo.setLocation( repoRoot.getAbsolutePath() );
93 c.addManagedRepository( repo );
94 saveConfiguration( archivaConfiguration );
96 ManagedRepository repository = servlet.getRepository( NEW_REPOSITORY_ID );
97 assertNotNull( repository );
98 assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
100 // check other is still intact
101 assertRepositoryValid( servlet, REPOID_INTERNAL );
105 public void testGetRepositoryInvalidPathPassthroughPresent()
108 String path = REQUEST_PATH + ".index/filecontent/segments.gen";
110 populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
112 WebRequest request = new GetMethodWebRequest( path );
113 WebResponse response = sc.getResponse( request );
114 assertResponseOK( response );
115 assertEquals( "index file", response.getText() );
119 public void testGetRepositoryInvalidPathPassthroughMissing()
122 String path = REQUEST_PATH + ".index/filecontent/foo.bar";
124 WebRequest request = new GetMethodWebRequest( path );
125 WebResponse response = sc.getResponse( request );
126 assertResponseNotFound( response );
127 assertEquals( "Invalid path to Artifact: legacy paths should have an expected type ending in [s] in the second part of the path.", response.getResponseMessage() );