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 org.apache.maven.archiva.configuration.ArchivaConfiguration;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
29 * RepositoryServletTest
31 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
34 public class RepositoryServletTest
35 extends AbstractRepositoryServletTestCase
37 private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
39 private static final String NEW_REPOSITORY_ID = "new-id";
41 private static final String NEW_REPOSITORY_NAME = "New Repository";
43 public void testGetRepository()
46 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
47 assertNotNull( servlet );
49 assertRepositoryValid( servlet, REPOID_INTERNAL );
52 public void testGetRepositoryAfterDelete()
55 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
56 assertNotNull( servlet );
58 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
59 Configuration c = archivaConfiguration.getConfiguration();
60 c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
61 saveConfiguration( archivaConfiguration );
63 ManagedRepositoryConfiguration repository = servlet.getRepository( REPOID_INTERNAL );
64 assertNull( repository );
67 public void testGetRepositoryAfterAdd()
70 RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
71 assertNotNull( servlet );
73 ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
74 Configuration c = archivaConfiguration.getConfiguration();
75 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
76 repo.setId( NEW_REPOSITORY_ID );
77 repo.setName( NEW_REPOSITORY_NAME );
78 File repoRoot = new File( getBasedir(), "target/test-repository-root" );
79 if ( !repoRoot.exists() )
83 repo.setLocation( repoRoot.getAbsolutePath() );
84 c.addManagedRepository( repo );
85 saveConfiguration( archivaConfiguration );
87 ManagedRepositoryConfiguration repository = servlet.getRepository( NEW_REPOSITORY_ID );
88 assertNotNull( repository );
89 assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
91 // check other is still intact
92 assertRepositoryValid( servlet, REPOID_INTERNAL );