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 com.meterware.httpunit.GetMethodWebRequest;
23 import com.meterware.httpunit.WebRequest;
24 import com.meterware.httpunit.WebResponse;
25 import org.apache.archiva.admin.model.beans.ManagedRepository;
26 import org.apache.archiva.configuration.ArchivaConfiguration;
27 import org.apache.archiva.configuration.Configuration;
28 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
29 import org.junit.Test;
34 * RepositoryServletTest
38 public class RepositoryServletTest
39 extends AbstractRepositoryServletTestCase
41 private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
43 private static final String NEW_REPOSITORY_ID = "new-id";
45 private static final String NEW_REPOSITORY_NAME = "New Repository";
48 public void testGetRepository()
51 RepositoryServlet servlet = (RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
52 assertNotNull( servlet );
54 assertRepositoryValid( servlet, REPOID_INTERNAL );
58 public void testGetRepositoryAfterDelete()
61 RepositoryServlet servlet = (RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
62 assertNotNull( servlet );
64 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
65 Configuration c = archivaConfiguration.getConfiguration();
66 c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
67 saveConfiguration( archivaConfiguration );
69 ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL );
70 assertNull( repository );
74 public void testGetRepositoryAfterAdd()
77 RepositoryServlet servlet = (RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
78 assertNotNull( servlet );
80 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
81 Configuration c = archivaConfiguration.getConfiguration();
82 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
83 repo.setId( NEW_REPOSITORY_ID );
84 repo.setName( NEW_REPOSITORY_NAME );
85 File repoRoot = new File( "target/test-repository-root" );
86 if ( !repoRoot.exists() )
90 repo.setLocation( repoRoot.getAbsolutePath() );
91 c.addManagedRepository( repo );
92 saveConfiguration( archivaConfiguration );
94 ManagedRepository repository = servlet.getRepository( NEW_REPOSITORY_ID );
95 assertNotNull( repository );
96 assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
98 // check other is still intact
99 assertRepositoryValid( servlet, REPOID_INTERNAL );
103 public void testGetRepositoryInvalidPathPassthroughPresent()
106 String path = REQUEST_PATH + ".index/filecontent/segments.gen";
108 populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
110 WebRequest request = new GetMethodWebRequest( path );
111 WebResponse response = getServletUnitClient().getResponse( request );
112 assertResponseOK( response );
113 assertEquals( "index file", response.getText() );
117 public void testGetRepositoryInvalidPathPassthroughMissing()
120 String path = REQUEST_PATH + ".index/filecontent/foo.bar";
122 WebRequest request = new GetMethodWebRequest( path );
123 WebResponse response = getServletUnitClient().getResponse( request );
124 assertResponseNotFound( response );
125 assertEquals( "Invalid path to Artifact: legacy paths should have an expected type ending in [s] in the second part of the path.", response.getResponseMessage() );