View Javadoc

1   package org.apache.continuum.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.continuum.dao.RepositoryPurgeConfigurationDao;
23  import org.apache.continuum.model.repository.LocalRepository;
24  import org.apache.continuum.model.repository.RepositoryPurgeConfiguration;
25  import org.apache.maven.continuum.AbstractContinuumTest;
26  import org.apache.maven.continuum.model.project.ProjectGroup;
27  
28  import java.util.List;
29  
30  /**
31   * @author Maria Catherine Tan
32   * @version $Id: DefaultRepositoryServiceTest.java 1372260 2012-08-13 04:29:09Z brett $
33   * @since 25 jul 07
34   */
35  public class DefaultRepositoryServiceTest
36      extends AbstractContinuumTest
37  {
38      private RepositoryPurgeConfigurationDao repositoryPurgeConfigurationDao;
39  
40      private RepositoryService repositoryService;
41  
42      private LocalRepository repository;
43  
44      @Override
45      protected void setUp()
46          throws Exception
47      {
48          super.setUp();
49  
50          repositoryPurgeConfigurationDao = (RepositoryPurgeConfigurationDao) lookup(
51              RepositoryPurgeConfigurationDao.class.getName() );
52  
53          repositoryService = (RepositoryService) lookup( RepositoryService.ROLE );
54  
55          setupDefaultRepository();
56      }
57  
58      public void testRemoveRepository()
59          throws Exception
60      {
61          repositoryService.removeLocalRepository( repository.getId() );
62  
63          List<LocalRepository> repositories = repositoryService.getAllLocalRepositories();
64          assertEquals( "check # repositories", 0, repositories.size() );
65  
66          ProjectGroup group = getDefaultProjectGroup();
67          assertNull( group.getLocalRepository() );
68  
69          List<RepositoryPurgeConfiguration> purgeConfigs =
70              repositoryPurgeConfigurationDao.getRepositoryPurgeConfigurationsByLocalRepository( repository.getId() );
71          assertEquals( "check # purge configs of repository", 0, purgeConfigs.size() );
72      }
73  
74      private void setupDefaultRepository()
75          throws Exception
76      {
77          repository = new LocalRepository();
78          repository.setName( "DefaultRepo" );
79          repository.setLocation( getTestFile( "target/default-repo" ).getAbsolutePath() );
80          repository = repositoryService.addLocalRepository( repository );
81  
82          ProjectGroup group = getDefaultProjectGroup();
83          group.setLocalRepository( repository );
84          getProjectGroupDao().updateProjectGroup( group );
85  
86          RepositoryPurgeConfiguration repoConfig = new RepositoryPurgeConfiguration();
87          repoConfig.setRepository( repository );
88          repoConfig = repositoryPurgeConfigurationDao.addRepositoryPurgeConfiguration( repoConfig );
89  
90          List<LocalRepository> repositories = repositoryService.getAllLocalRepositories();
91          assertEquals( "check # repositories", 1, repositories.size() );
92          assertTrue( "check if repository was added", repositories.contains( repository ) );
93  
94          LocalRepository repo = repositoryService.getLocalRepositoryByName( "DefaultRepo" );
95          assertNotNull( repo );
96          assertEquals( "check if repository name is the same", repository.getName(), repo.getName() );
97  
98          repo = repositoryService.getLocalRepositoryByLocation( repository.getLocation() );
99          assertNotNull( repo );
100         assertEquals( "check if repository location is the same", repository.getLocation(), repo.getLocation() );
101 
102         ProjectGroup retrievedGroup = getDefaultProjectGroup();
103         assertNotNull( retrievedGroup.getLocalRepository() );
104         assertEquals( "check if repository is the same", repository, retrievedGroup.getLocalRepository() );
105 
106         List<RepositoryPurgeConfiguration> purgeConfigs =
107             repositoryPurgeConfigurationDao.getRepositoryPurgeConfigurationsByLocalRepository( repository.getId() );
108         assertEquals( "check # purge configs found", 1, purgeConfigs.size() );
109         assertEquals( "check if purge configuration is the same", repoConfig, purgeConfigs.get( 0 ) );
110     }
111 }