throws Exception
{
Date current = new Date();
Date ts1 = new Date( current.getTime() - 12345 );
AuditEvent expectedEvent1 = createEvent( ts1 );
Date expectedTimestamp = new Date( current.getTime() - 3000 );
AuditEvent expectedEvent2 = createEvent( expectedTimestamp );
expectedEvent2.setRepositoryId( TEST_REPO_ID_2 );
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) )
.andReturn( Arrays.asList( expectedEvent1.getName(), expectedEvent3.getName() ) );
EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ) )
.andReturn( Arrays.asList( expectedEvent2.getName() ) );
EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ) )
.andReturn( expectedEvent1 );
EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName() ) )
.andReturn( expectedEvent2 );
EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ) )
.andReturn( expectedEvent3 );
metadataRepositoryControl.replay();
List<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Arrays.asList( TEST_REPO_ID, TEST_REPO_ID_2 ),
new Date( current.getTime() - 20000 ), current );
assertEquals( 3, events.size() );
assertTestEvent( events.get( 0 ), TEST_REPO_ID, TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() );
assertTestEvent( events.get( 1 ), TEST_REPO_ID_2, TIMESTAMP_FORMAT.format( expectedTimestamp ),
expectedEvent2.getResource() );
assertTestEvent( events.get( 2 ), TEST_REPO_ID, TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
metadataRepositoryControl.verify();