summaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins/audit
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2010-12-22 01:53:10 +0000
committerBrett Porter <brett@apache.org>2010-12-22 01:53:10 +0000
commitbadcc9e925b9351d2e1d2b198d082245960ee40a (patch)
tree5ef3f8a7ad494d5560b25fe1ad8ce9bb0dcfd410 /archiva-modules/plugins/audit
parent1ff88d24fe6665e01b57eff1e9db76216e942354 (diff)
downloadarchiva-badcc9e925b9351d2e1d2b198d082245960ee40a.tar.gz
archiva-badcc9e925b9351d2e1d2b198d082245960ee40a.zip
[MRM-1327] add exception handling to the metadata repository implementation
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1051732 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/audit')
-rw-r--r--archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java17
-rw-r--r--archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java21
-rw-r--r--archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java15
-rw-r--r--archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java287
4 files changed, 201 insertions, 139 deletions
diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java
index 29665e5a6..23c0f674c 100644
--- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java
+++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java
@@ -19,17 +19,22 @@ package org.apache.archiva.audit;
* under the License.
*/
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+
import java.util.Collection;
import java.util.Date;
import java.util.List;
public interface AuditManager
{
- List<AuditEvent> getMostRecentAuditEvents( List<String> repositoryIds );
+ List<AuditEvent> getMostRecentAuditEvents( List<String> repositoryIds )
+ throws MetadataRepositoryException;
- void addAuditEvent( AuditEvent event );
+ void addAuditEvent( AuditEvent event )
+ throws MetadataRepositoryException;
- void deleteAuditEvents( String repositoryId );
+ void deleteAuditEvents( String repositoryId )
+ throws MetadataRepositoryException;
/**
* Get all audit events from the given repositories that match a certain range
@@ -39,7 +44,8 @@ public interface AuditManager
* @param endTime find events only before this time
* @return the list of events found
*/
- List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, Date startTime, Date endTime );
+ List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, Date startTime, Date endTime )
+ throws MetadataRepositoryException;
/**
* Get all audit events from the given repositories that match a certain range and resource pattern
@@ -51,5 +57,6 @@ public interface AuditManager
* @return the list of events found
*/
List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, String resourcePattern, Date startTime,
- Date endTime );
+ Date endTime )
+ throws MetadataRepositoryException;
}
diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java
index 73c9094e4..9474ce54c 100644
--- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java
+++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java
@@ -20,6 +20,7 @@ package org.apache.archiva.audit;
*/
import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,6 +52,7 @@ public class DefaultAuditManager
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
public List<AuditEvent> getMostRecentAuditEvents( List<String> repositoryIds )
+ throws MetadataRepositoryException
{
// TODO: consider a more efficient implementation that directly gets the last ten from the content repository
List<AuditRecord> records = new ArrayList<AuditRecord>();
@@ -68,15 +70,16 @@ public class DefaultAuditManager
List<AuditEvent> events = new ArrayList<AuditEvent>( records.size() );
for ( AuditRecord record : records )
{
- AuditEvent auditEvent =
- (AuditEvent) metadataRepository.getMetadataFacet( record.repositoryId, AuditEvent.FACET_ID,
- record.name );
+ AuditEvent auditEvent = (AuditEvent) metadataRepository.getMetadataFacet( record.repositoryId,
+ AuditEvent.FACET_ID,
+ record.name );
events.add( auditEvent );
}
return events;
}
public void addAuditEvent( AuditEvent event )
+ throws MetadataRepositoryException
{
// ignore those with no repository - they will still be logged to the textual audit log
if ( event.getRepositoryId() != null )
@@ -86,17 +89,20 @@ public class DefaultAuditManager
}
public void deleteAuditEvents( String repositoryId )
+ throws MetadataRepositoryException
{
metadataRepository.removeMetadataFacets( repositoryId, AuditEvent.FACET_ID );
}
public List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, Date startTime, Date endTime )
+ throws MetadataRepositoryException
{
return getAuditEventsInRange( repositoryIds, null, startTime, endTime );
}
public List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, String resource, Date startTime,
Date endTime )
+ throws MetadataRepositoryException
{
List<AuditEvent> results = new ArrayList<AuditEvent>();
for ( String repositoryId : repositoryIds )
@@ -107,11 +113,12 @@ public class DefaultAuditManager
try
{
Date date = createNameFormat().parse( name );
- if ( ( startTime == null || !date.before( startTime ) ) &&
- ( endTime == null || !date.after( endTime ) ) )
+ if ( ( startTime == null || !date.before( startTime ) ) && ( endTime == null || !date.after(
+ endTime ) ) )
{
- AuditEvent event =
- (AuditEvent) metadataRepository.getMetadataFacet( repositoryId, AuditEvent.FACET_ID, name );
+ AuditEvent event = (AuditEvent) metadataRepository.getMetadataFacet( repositoryId,
+ AuditEvent.FACET_ID,
+ name );
if ( resource == null || event.getResource().startsWith( resource ) )
{
diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java
index 66383892e..632187c62 100644
--- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java
+++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java
@@ -19,12 +19,18 @@ package org.apache.archiva.audit;
* under the License.
*/
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* @plexus.component role="org.apache.archiva.audit.AuditListener" role-hint="metadata"
*/
public class MetadataAuditListener
implements AuditListener
{
+ private static final Logger log = LoggerFactory.getLogger( MetadataAuditListener.class );
+
/**
* @plexus.requirement
*/
@@ -36,7 +42,14 @@ public class MetadataAuditListener
if ( event.getAction().equals( AuditEvent.CREATE_FILE ) || event.getAction().equals( AuditEvent.UPLOAD_FILE ) ||
event.getAction().equals( AuditEvent.MERGING_REPOSITORIES ) )
{
- auditManager.addAuditEvent( event );
+ try
+ {
+ auditManager.addAuditEvent( event );
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.warn( "Unable to write audit event to repository: " + e.getMessage(), e );
+ }
}
}
}
diff --git a/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java b/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java
index a4e6012d3..2ac2ddcc0 100644
--- a/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java
+++ b/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java
@@ -86,7 +86,7 @@ public class AuditManagerTest
}
public void testGetMostRecentEvents()
- throws ParseException
+ throws Exception
{
int numEvents = 11;
List<AuditEvent> expectedEvents = new ArrayList<AuditEvent>( numEvents );
@@ -96,14 +96,15 @@ public class AuditManagerTest
expectedEvents.add( event );
}
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- getEventNames( expectedEvents ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ getEventNames( expectedEvents ) );
for ( AuditEvent event : expectedEvents.subList( 1, expectedEvents.size() ) )
{
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ), event );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ event.getName() ), event );
}
metadataRepositoryControl.replay();
@@ -122,7 +123,7 @@ public class AuditManagerTest
}
public void testGetMostRecentEventsLessThan10()
- throws ParseException
+ throws Exception
{
int numEvents = 5;
List<AuditEvent> expectedEvents = new ArrayList<AuditEvent>( numEvents );
@@ -131,14 +132,15 @@ public class AuditManagerTest
expectedEvents.add( createEvent( AUDIT_EVENT_BASE + MILLIS_FORMAT.format( i ) ) );
}
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- getEventNames( expectedEvents ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ getEventNames( expectedEvents ) );
for ( AuditEvent event : expectedEvents )
{
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ), event );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ event.getName() ), event );
}
metadataRepositoryControl.replay();
@@ -157,7 +159,7 @@ public class AuditManagerTest
}
public void testGetMostRecentEventsInterleavedRepositories()
- throws ParseException
+ throws Exception
{
int numEvents = 11;
Map<String, List<String>> eventNames = new LinkedHashMap<String, List<String>>();
@@ -173,17 +175,18 @@ public class AuditManagerTest
eventNames.get( repositoryId ).add( event.getName() );
}
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), eventNames.get( TEST_REPO_ID ) );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ),
- eventNames.get( TEST_REPO_ID_2 ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ eventNames.get( TEST_REPO_ID ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID_2,
+ AuditEvent.FACET_ID ),
+ eventNames.get( TEST_REPO_ID_2 ) );
for ( AuditEvent event : events.subList( 1, events.size() ) )
{
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( event.getRepositoryId(), AuditEvent.FACET_ID, event.getName() ),
- event );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( event.getRepositoryId(),
+ AuditEvent.FACET_ID,
+ event.getName() ), event );
}
metadataRepositoryControl.replay();
@@ -203,9 +206,12 @@ public class AuditManagerTest
}
public void testGetMostRecentEventsWhenEmpty()
+ throws Exception
+
{
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), Collections.emptyList() );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Collections.emptyList() );
metadataRepositoryControl.replay();
assertTrue( auditManager.getMostRecentAuditEvents( Collections.singletonList( TEST_REPO_ID ) ).isEmpty() );
@@ -214,7 +220,8 @@ public class AuditManagerTest
}
public void testAddAuditEvent()
- throws ParseException
+ throws Exception
+
{
AuditEvent event = createEvent( new Date() );
@@ -228,7 +235,7 @@ public class AuditManagerTest
}
public void testAddAuditEventNoRepositoryId()
- throws ParseException
+ throws Exception
{
AuditEvent event = createEvent( new Date() );
event.setRepositoryId( null );
@@ -243,6 +250,8 @@ public class AuditManagerTest
}
public void testDeleteStats()
+ throws Exception
+
{
metadataRepository.removeMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID );
@@ -254,7 +263,8 @@ public class AuditManagerTest
}
public void testGetEventsRangeInside()
- throws ParseException
+ throws Exception
+
{
Date current = new Date();
@@ -263,20 +273,22 @@ public class AuditManagerTest
AuditEvent expectedEvent = createEvent( expectedTimestamp );
AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- Arrays.asList( event1.getName(), expectedEvent.getName(), event3.getName() ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( event1.getName(), expectedEvent.getName(),
+ event3.getName() ) );
// only match the middle one
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent.getName() ),
- expectedEvent );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent.getName() ),
+ expectedEvent );
metadataRepositoryControl.replay();
List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ),
- new Date( current.getTime() - 4000 ),
- new Date( current.getTime() - 2000 ) );
+ new Date( current.getTime() - 4000 ), new Date(
+ current.getTime() - 2000 ) );
assertEquals( 1, events.size() );
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent.getResource() );
@@ -285,7 +297,7 @@ public class AuditManagerTest
}
public void testGetEventsRangeUpperOutside()
- throws ParseException
+ throws Exception
{
Date current = new Date();
@@ -295,16 +307,19 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- Arrays.asList( event1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( event1.getName(), expectedEvent2.getName(),
+ expectedEvent3.getName() ) );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ),
- expectedEvent2 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ),
- expectedEvent3 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent2.getName() ),
+ expectedEvent2 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent3.getName() ),
+ expectedEvent3 );
metadataRepositoryControl.replay();
@@ -319,7 +334,7 @@ public class AuditManagerTest
}
public void testGetEventsRangeLowerOutside()
- throws ParseException
+ throws Exception
{
Date current = new Date();
@@ -329,22 +344,25 @@ public class AuditManagerTest
AuditEvent expectedEvent2 = createEvent( expectedTimestamp );
AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), event3.getName() ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(),
+ event3.getName() ) );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ),
- expectedEvent1 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ),
- expectedEvent2 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent1.getName() ),
+ expectedEvent1 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent2.getName() ),
+ expectedEvent2 );
metadataRepositoryControl.replay();
List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ),
- new Date( current.getTime() - 20000 ),
- new Date( current.getTime() - 2000 ) );
+ new Date( current.getTime() - 20000 ), new Date(
+ current.getTime() - 2000 ) );
assertEquals( 2, events.size() );
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() );
@@ -354,7 +372,7 @@ public class AuditManagerTest
}
public void testGetEventsRangeLowerAndUpperOutside()
- throws ParseException
+ throws Exception
{
Date current = new Date();
@@ -365,19 +383,23 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) );
-
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ),
- expectedEvent1 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ),
- expectedEvent2 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ),
- expectedEvent3 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(),
+ expectedEvent3.getName() ) );
+
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent1.getName() ),
+ expectedEvent1 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent2.getName() ),
+ expectedEvent2 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent3.getName() ),
+ expectedEvent3 );
metadataRepositoryControl.replay();
@@ -393,7 +415,7 @@ public class AuditManagerTest
}
public void testGetEventsWithResource()
- throws ParseException
+ throws Exception
{
Date current = new Date();
@@ -405,25 +427,29 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) );
-
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ),
- expectedEvent1 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ),
- expectedEvent2 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ),
- expectedEvent3 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(),
+ expectedEvent3.getName() ) );
+
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent1.getName() ),
+ expectedEvent1 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent2.getName() ),
+ expectedEvent2 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent3.getName() ),
+ expectedEvent3 );
metadataRepositoryControl.replay();
- List<AuditEvent> events =
- auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ), TEST_RESOURCE_BASE,
- new Date( current.getTime() - 20000 ), current );
+ List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ),
+ TEST_RESOURCE_BASE, new Date(
+ current.getTime() - 20000 ), current );
assertEquals( 2, events.size() );
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() );
@@ -433,7 +459,7 @@ public class AuditManagerTest
}
public void testGetEventsWithNonExistantResource()
- throws ParseException
+ throws Exception
{
Date current = new Date();
@@ -443,19 +469,23 @@ public class AuditManagerTest
expectedEvent2.setResource( "different-resource" );
AuditEvent expectedEvent3 = createEvent( new Date( current.getTime() - 1000 ) );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) );
-
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ),
- expectedEvent1 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ),
- expectedEvent2 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ),
- expectedEvent3 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(),
+ expectedEvent3.getName() ) );
+
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent1.getName() ),
+ expectedEvent1 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent2.getName() ),
+ expectedEvent2 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent3.getName() ),
+ expectedEvent3 );
metadataRepositoryControl.replay();
@@ -468,7 +498,7 @@ public class AuditManagerTest
}
public void testGetEventsRangeMultipleRepositories()
- throws ParseException
+ throws Exception
{
Date current = new Date();
@@ -480,22 +510,26 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- Arrays.asList( expectedEvent1.getName(), expectedEvent3.getName() ) );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ),
- Arrays.asList( expectedEvent2.getName() ) );
-
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ),
- expectedEvent1 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName() ),
- expectedEvent2 );
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ),
- expectedEvent3 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( expectedEvent1.getName(),
+ expectedEvent3.getName() ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID_2,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( expectedEvent2.getName() ) );
+
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent1.getName() ),
+ expectedEvent1 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID_2,
+ AuditEvent.FACET_ID,
+ expectedEvent2.getName() ),
+ expectedEvent2 );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
+ AuditEvent.FACET_ID,
+ expectedEvent3.getName() ),
+ expectedEvent3 );
metadataRepositoryControl.replay();
@@ -512,7 +546,7 @@ public class AuditManagerTest
}
public void testGetEventsRangeNotInside()
- throws ParseException
+ throws Exception
{
Date current = new Date();
@@ -521,15 +555,15 @@ public class AuditManagerTest
String name2 = createEvent( expectedTimestamp ).getName();
String name3 = createEvent( new Date( current.getTime() - 1000 ) ).getName();
- metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
- Arrays.asList( name1, name2, name3 ) );
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+ AuditEvent.FACET_ID ),
+ Arrays.asList( name1, name2, name3 ) );
metadataRepositoryControl.replay();
List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ),
- new Date( current.getTime() - 20000 ),
- new Date( current.getTime() - 16000 ) );
+ new Date( current.getTime() - 20000 ), new Date(
+ current.getTime() - 16000 ) );
assertEquals( 0, events.size() );
@@ -550,8 +584,9 @@ public class AuditManagerTest
private static AuditEvent createEvent( String ts )
throws ParseException
{
- return createEvent( TEST_REPO_ID, ts, getDefaultTestResourceName(
- ts.substring( AUDIT_EVENT_BASE.length(), AUDIT_EVENT_BASE.length() + 3 ) ) );
+ return createEvent( TEST_REPO_ID, ts, getDefaultTestResourceName( ts.substring( AUDIT_EVENT_BASE.length(),
+ AUDIT_EVENT_BASE.length() +
+ 3 ) ) );
}
private static AuditEvent createEvent( String repositoryId, String timestamp, String resource )