View Javadoc
1   package org.apache.archiva.admin.repository.remote;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.archiva.admin.model.beans.RemoteRepository;
22  import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
23  import org.apache.archiva.metadata.model.facets.AuditEvent;
24  import org.junit.Test;
25  
26  import java.util.List;
27  
28  /**
29   * @author Olivier Lamy
30   */
31  public class RemoteRepositoryAdminTest
32      extends AbstractRepositoryAdminTest
33  {
34  
35      @Test
36      public void getAll()
37          throws Exception
38      {
39          List<RemoteRepository> remoteRepositories = remoteRepositoryAdmin.getRemoteRepositories();
40          assertNotNull( remoteRepositories );
41          assertTrue( remoteRepositories.size() > 0 );
42          log.info( "remote {}", remoteRepositories );
43      }
44  
45      @Test
46      public void getById()
47          throws Exception
48      {
49          RemoteRepository central = remoteRepositoryAdmin.getRemoteRepository( "central" );
50          assertNotNull( central );
51          assertEquals( "https://repo.maven.apache.org/maven2", central.getUrl() );
52          assertEquals( 60, central.getTimeout() );
53          assertNull( central.getUserName() );
54          assertNull( central.getPassword() );
55      }
56  
57      @Test
58      public void addAndDelete()
59          throws Exception
60      {
61          mockAuditListener.clearEvents();
62          int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
63  
64          RemoteRepository remoteRepository = getRemoteRepository();
65  
66          remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
67  
68          assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
69  
70          RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
71          assertNotNull( repo );
72          assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
73          assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
74          assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
75          assertEquals( getRemoteRepository().getName(), repo.getName() );
76          assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
77          assertEquals( getRemoteRepository().getDescription(), repo.getDescription() );
78          assertEquals( 1, remoteRepository.getExtraHeaders().size() );
79          assertEquals( "wine", remoteRepository.getExtraHeaders().get( "beer" ) );
80  
81          assertEquals( 1, remoteRepository.getExtraParameters().size() );
82          assertEquals( "bar", remoteRepository.getExtraParameters().get( "foo" ) );
83  
84          remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
85  
86          assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
87  
88          repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
89          assertNull( repo );
90  
91          assertEquals( 2, mockAuditListener.getAuditEvents().size() );
92  
93          assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
94          assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
95          assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
96  
97          assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
98          assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
99  
100     }
101 
102 
103     @Test
104     public void addAndUpdateAndDelete()
105         throws Exception
106     {
107         mockAuditListener.clearEvents();
108         int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
109 
110         RemoteRepository remoteRepository = getRemoteRepository();
111 
112         remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
113 
114         assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
115 
116         RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
117         assertNotNull( repo );
118         assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
119         assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
120         assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
121         assertEquals( getRemoteRepository().getName(), repo.getName() );
122         assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
123         assertEquals( getRemoteRepository().getRemoteDownloadNetworkProxyId(), repo.getRemoteDownloadNetworkProxyId() );
124 
125         repo.setUserName( "foo-name-changed" );
126         repo.setPassword( "titi" );
127         repo.setUrl( "http://foo.com/maven-really-rocks" );
128         repo.setRemoteDownloadNetworkProxyId( "toto" );
129         repo.setDescription( "archiva rocks!" );
130 
131         remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() );
132 
133         repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
134 
135         assertEquals( "foo-name-changed", repo.getUserName() );
136         assertEquals( "titi", repo.getPassword() );
137         assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() );
138         assertEquals( "toto", repo.getRemoteDownloadNetworkProxyId() );
139         assertEquals( "archiva rocks!", repo.getDescription() );
140 
141         remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
142 
143         assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
144 
145         repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
146         assertNull( repo );
147 
148         assertEquals( 3, mockAuditListener.getAuditEvents().size() );
149 
150         assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
151         assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
152         assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
153 
154         assertEquals( AuditEvent.MODIFY_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
155         assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
156         assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 1 ).getRemoteIP() );
157 
158         assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
159         assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
160 
161     }
162 
163 
164 }