/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   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 org.bodington.server.events;

import java.math.BigInteger;

import org.bodington.server.BuildingServerException;
import org.bodington.server.BuildingServerTest;

/**
 * @author buckett
 */
public class UserFileEventTest extends BuildingServerTest
{

    /*
     * Class under test for void UserFileEvent(int, PrimaryKey, PrimaryKey,
     * PrimaryKey, Integer, BigInteger, String)
     */
    public void testUserFileEventintPrimaryKeyPrimaryKeyPrimaryKeyIntegerBigIntegerString()
        throws BuildingServerException
    {
        UserFileEvent userFileEvent;

        // Doing Unit tests involving overflowing field in HSQLDB doesn't work as it
        // stores everything as strings which can be any length.
        
        // Test with a normal filename.
        userFileEvent = new UserFileEvent(UserFileEvent.EVENT_DELETE, resource
            .getResourceId(), user.getUserId(), null, null, BigInteger.ONE,
            "test");
        assertTrue (userFileEvent.getFileName().length() < 64);


        // Test with a filename of 63 characters.
        userFileEvent = new UserFileEvent(UserFileEvent.EVENT_DELETE, resource
            .getResourceId(), user.getUserId(), null, null, BigInteger.ONE,
            "012345678901234567890123456789012345678901234567890123456789123");
        assertTrue (userFileEvent.getFileName().length() < 64);

        // Test with 130 characters in the filename. Regression test substring error in setFileName.
        userFileEvent = new UserFileEvent(
            UserFileEvent.EVENT_DELETE,
            resource.getResourceId(),
            user.getUserId(),
            null,
            null,
            BigInteger.ONE,
           "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
        assertTrue (userFileEvent.getFileName().length() < 64);

        

    }
}
