You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RemoteRepositoryAdminTest.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. import org.apache.archiva.admin.model.beans.RemoteRepository;
  21. import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
  22. import org.apache.archiva.metadata.model.facets.AuditEvent;
  23. import org.junit.Test;
  24. import java.util.List;
  25. /**
  26. * @author Olivier Lamy
  27. */
  28. public class RemoteRepositoryAdminTest
  29. extends AbstractRepositoryAdminTest
  30. {
  31. @Test
  32. public void getAll()
  33. throws Exception
  34. {
  35. List<RemoteRepository> remoteRepositories = remoteRepositoryAdmin.getRemoteRepositories();
  36. assertNotNull( remoteRepositories );
  37. assertTrue( remoteRepositories.size() > 0 );
  38. log.info( "remote {}", remoteRepositories );
  39. }
  40. @Test
  41. public void getById()
  42. throws Exception
  43. {
  44. RemoteRepository central = remoteRepositoryAdmin.getRemoteRepository( "central" );
  45. assertNotNull( central );
  46. assertEquals( "http://repo.maven.apache.org/maven2", central.getUrl() );
  47. assertEquals( 60, central.getTimeout() );
  48. assertNull( central.getUserName() );
  49. assertNull( central.getPassword() );
  50. }
  51. @Test
  52. public void addAndDelete()
  53. throws Exception
  54. {
  55. mockAuditListener.clearEvents();
  56. int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
  57. RemoteRepository remoteRepository = getRemoteRepository();
  58. remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
  59. assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
  60. RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
  61. assertNotNull( repo );
  62. assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
  63. assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
  64. assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
  65. assertEquals( getRemoteRepository().getName(), repo.getName() );
  66. assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
  67. assertEquals( getRemoteRepository().getDescription(), repo.getDescription() );
  68. assertEquals( 1, remoteRepository.getExtraHeaders().size() );
  69. assertEquals( "wine", remoteRepository.getExtraHeaders().get( "beer" ) );
  70. assertEquals( 1, remoteRepository.getExtraParameters().size() );
  71. assertEquals( "bar", remoteRepository.getExtraParameters().get( "foo" ) );
  72. remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
  73. assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
  74. repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
  75. assertNull( repo );
  76. assertEquals( 2, mockAuditListener.getAuditEvents().size() );
  77. assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
  78. assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
  79. assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
  80. assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
  81. assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
  82. }
  83. @Test
  84. public void addAndUpdateAndDelete()
  85. throws Exception
  86. {
  87. mockAuditListener.clearEvents();
  88. int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
  89. RemoteRepository remoteRepository = getRemoteRepository();
  90. remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
  91. assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
  92. RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
  93. assertNotNull( repo );
  94. assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
  95. assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
  96. assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
  97. assertEquals( getRemoteRepository().getName(), repo.getName() );
  98. assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
  99. assertEquals( getRemoteRepository().getRemoteDownloadNetworkProxyId(), repo.getRemoteDownloadNetworkProxyId() );
  100. repo.setUserName( "foo-name-changed" );
  101. repo.setPassword( "titi" );
  102. repo.setUrl( "http://foo.com/maven-really-rocks" );
  103. repo.setRemoteDownloadNetworkProxyId( "toto" );
  104. repo.setDescription( "archiva rocks!" );
  105. remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() );
  106. repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
  107. assertEquals( "foo-name-changed", repo.getUserName() );
  108. assertEquals( "titi", repo.getPassword() );
  109. assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() );
  110. assertEquals( "toto", repo.getRemoteDownloadNetworkProxyId() );
  111. assertEquals( "archiva rocks!", repo.getDescription() );
  112. remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
  113. assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
  114. repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
  115. assertNull( repo );
  116. assertEquals( 3, mockAuditListener.getAuditEvents().size() );
  117. assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
  118. assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
  119. assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
  120. assertEquals( AuditEvent.MODIFY_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
  121. assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
  122. assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 1 ).getRemoteIP() );
  123. assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
  124. assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
  125. }
  126. }