@Test
public void addAndUpdateAndDelete()
throws Exception
{
mockAuditListener.clearEvents();
RemoteRepository remoteRepository = getRemoteRepository( "test-new-one" );
remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
assertEquals( "not proxyConnectors 1 " + proxyConnectorAdmin.getProxyConnectors(), 1,
proxyConnectorAdmin.getProxyConnectors().size() );
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setSourceRepoId( "snapshots" );
proxyConnector.setTargetRepoId( "central" );
proxyConnector.setWhiteListPatterns( Arrays.asList( "foo", "bar" ) );
proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
assertEquals( Arrays.asList( "foo", "bar" ),
proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ).getWhiteListPatterns() );
proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
proxyConnector.setTargetRepoId( remoteRepository.getId() );
proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
assertNotNull( remoteRepository.getId(),
proxyConnectorAdmin.getProxyConnector( "snapshots", remoteRepository.getId() ) );
proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
assertEquals( 1, proxyConnectorAdmin.getProxyConnectors().size() );
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
assertEquals( 5, mockAuditListener.getAuditEvents().size() );
assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 2 ).getRemoteIP() );
assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 3 ).getAction() );
assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 4 ).getAction() );
assertEquals( "root", mockAuditListener.getAuditEvents().get( 4 ).getUserId() );
remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() );
mockAuditListener.clearEvents();
}