/*
 * The Gemma project
 * 
 * Copyright (c) 2007 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package ubic.gemma.model.common.auditAndSecurity;

import ubic.gemma.model.common.Auditable;
import ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignGeneMappingEvent;
import ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType;
import ubic.gemma.model.expression.arrayDesign.ArrayDesign;
import ubic.gemma.testing.BaseSpringContextTest;

/**
 * @author pavlidis
 * @version $Id$
 */
public class AuditTrailServiceImplTest extends BaseSpringContextTest {

    Auditable auditable;
    AuditTrailService auditTrailService;

    @Override
    protected void onSetUpInTransaction() throws Exception {
        super.onSetUpInTransaction();
        auditable = ArrayDesign.Factory.newInstance();
        auditable.setName( "testing audit" );
        auditable = ( ArrayDesign ) this.persisterHelper.persist( auditable );
        auditTrailService = ( AuditTrailService ) this.getBean( "auditTrailService" );
        endTransaction();
    }

    public final void testAddUpdateEventAuditableString() {
        AuditEvent ev = auditTrailService.addUpdateEvent( auditable, "nothing special, just testing" );
        assertNotNull( ev.getId() );
    }

    public final void testAddUpdateEventAuditableAuditEventTypeString() {
        AuditEventType f = ArrayDesignGeneMappingEvent.Factory.newInstance();
        AuditEvent ev = auditTrailService.addUpdateEvent( auditable, f, "nothing special, just testing" );
        assertNotNull( ev.getId() );
    }

}

@@ -693,16 +693,40 @@
 urity;%0A%0A
+import java.util.List;%0A%0A
 import u
@@ -759,16 +759,16 @@
 itable;%0A
-
 import u
@@ -846,16 +846,107 @@
 gEvent;%0A
+import ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignGeneMappingEventImpl;%0A
 import u
@@ -1303,16 +1303,38 @@
 Service;
+%0A    private int size;
 %0A%0A    @O
@@ -1729,24 +1729,85 @@
 nsaction();%0A
+        size = auditable.getAuditTrail().getEvents().size();%0A
     %7D%0A%0A    p
@@ -1998,24 +1998,104 @@
 .getId() );%0A
+        assertEquals( size + 1, auditable.getAuditTrail().getEvents().size() );%0A
     %7D%0A%0A    p
@@ -2340,32 +2340,32 @@
 ust testing%22 );%0A
-
         assertNo
@@ -2381,21 +2381,280 @@
 .getId() );%0A
+        assertEquals( size + 1, auditable.getAuditTrail().getEvents().size() );%0A        assertEquals( ArrayDesignGeneMappingEventImpl.class, ( ( List%3CAuditEvent%3E ) auditable.getAuditTrail()%0A                .getEvents() ).get( 2 ).getEventType().getClass() );%0A
     %7D%0A%0A%7D%0A

test more rigorous