View Javadoc
1   package org.apache.archiva.repository;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import org.apache.archiva.admin.model.beans.ManagedRepository;
23  import org.apache.archiva.admin.model.beans.RemoteRepository;
24  import org.junit.Rule;
25  import org.junit.rules.TestName;
26  import org.junit.runner.RunWith;
27  import org.springframework.context.ApplicationContext;
28  import org.springframework.test.context.ContextConfiguration;
29  
30  import java.io.File;
31  import javax.inject.Inject;
32  import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
33  
34  /**
35   * AbstractRepositoryLayerTestCase
36   *
37   *
38   */
39  @RunWith( ArchivaSpringJUnit4ClassRunner.class )
40  @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
41  public abstract class AbstractRepositoryLayerTestCase
42  {
43      @Rule
44      public TestName name = new TestName();
45  
46      @Inject
47      protected ApplicationContext applicationContext;
48  
49      protected ManagedRepository createRepository( String id, String name, File location )
50      {
51          ManagedRepository repo = new ManagedRepository();
52          repo.setId( id );
53          repo.setName( name );
54          repo.setLocation( location.getAbsolutePath() );
55          return repo;
56      }
57  
58      protected RemoteRepository createRemoteRepository( String id, String name, String url )
59      {
60          RemoteRepository repo = new RemoteRepository();
61          repo.setId( id );
62          repo.setName( name );
63          repo.setUrl( url );
64          return repo;
65      }
66  
67      protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, File location,
68                                                                         String layout )
69          throws Exception
70      {
71          ManagedRepository repo = new ManagedRepository();
72          repo.setId( id );
73          repo.setName( name );
74          repo.setLocation( location.getAbsolutePath() );
75          repo.setLayout( layout );
76  
77          ManagedRepositoryContent repoContent =
78              applicationContext.getBean( "managedRepositoryContent#" + layout, ManagedRepositoryContent.class );
79          repoContent.setRepository( repo );
80  
81          return repoContent;
82      }
83  
84      protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
85          throws Exception
86      {
87          RemoteRepository repo = new RemoteRepository();
88          repo.setId( id );
89          repo.setName( name );
90          repo.setUrl( url );
91          repo.setLayout( layout );
92  
93          RemoteRepositoryContent repoContent =
94              applicationContext.getBean( "remoteRepositoryContent#" + layout, RemoteRepositoryContent.class );
95          repoContent.setRepository( repo );
96  
97          return repoContent;
98      }
99  }