1 package org.apache.archiva.web.servlet;
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.maven.archiva.configuration.ArchivaConfiguration;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26 import com.meterware.httpunit.GetMethodWebRequest;
27 import com.meterware.httpunit.WebRequest;
28 import com.meterware.httpunit.WebResponse;
33 * RepositoryServletTest
37 public class RepositoryServletTest
38 extends AbstractRepositoryServletTestCase
40 private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
42 private static final String NEW_REPOSITORY_ID = "new-id";
44 private static final String NEW_REPOSITORY_NAME = "New Repository";
46 public void testGetRepository()
49 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
50 assertNotNull( servlet );
52 assertRepositoryValid( servlet, REPOID_INTERNAL );
55 public void testGetRepositoryAfterDelete()
58 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
59 assertNotNull( servlet );
61 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
62 Configuration c = archivaConfiguration.getConfiguration();
63 c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
64 saveConfiguration( archivaConfiguration );
66 ManagedRepositoryConfiguration repository = servlet.getRepository( REPOID_INTERNAL );
67 assertNull( repository );
70 public void testGetRepositoryAfterAdd()
73 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
74 assertNotNull( servlet );
76 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
77 Configuration c = archivaConfiguration.getConfiguration();
78 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
79 repo.setId( NEW_REPOSITORY_ID );
80 repo.setName( NEW_REPOSITORY_NAME );
81 File repoRoot = new File( getBasedir(), "target/test-repository-root" );
82 if ( !repoRoot.exists() )
86 repo.setLocation( repoRoot.getAbsolutePath() );
87 c.addManagedRepository( repo );
88 saveConfiguration( archivaConfiguration );
90 ManagedRepositoryConfiguration repository = servlet.getRepository( NEW_REPOSITORY_ID );
91 assertNotNull( repository );
92 assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
94 // check other is still intact
95 assertRepositoryValid( servlet, REPOID_INTERNAL );
98 public void testGetRepositoryInvalidPathPassthroughPresent()
101 String path = REQUEST_PATH + ".index/filecontent/segments.gen";
103 populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
105 WebRequest request = new GetMethodWebRequest( path );
106 WebResponse response = sc.getResponse( request );
107 assertResponseOK( response );
108 assertEquals( "index file", response.getText() );
111 public void testGetRepositoryInvalidPathPassthroughMissing()
114 String path = REQUEST_PATH + ".index/filecontent/foo.bar";
116 WebRequest request = new GetMethodWebRequest( path );
117 WebResponse response = sc.getResponse( request );
118 assertResponseNotFound( response );
119 assertEquals( "Invalid path to Artifact: legacy paths should have an expected type ending in [s] in the second part of the path.", response.getResponseMessage() );