View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2008, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  package org.dbunit.dataset.datatype;
22  
23  import java.sql.Blob;
24  import java.sql.Types;
25  
26  import junit.framework.TestCase;
27  import junitx.framework.ArrayAssert;
28  
29  import org.dbunit.database.statement.MockPreparedStatement;
30  
31  /**
32   * @author gommma
33   * @version $Revision$
34   * @since 2.3.0
35   */
36  public class BlobDataTypeTest extends TestCase 
37  {
38  	private DataType TYPE = DataType.BLOB;
39  
40  	public BlobDataTypeTest(String name) {
41  		super(name);
42  	}
43  
44  	public void testGetSqlType()
45  	{
46  		assertEquals(Types.BLOB, TYPE.getSqlType());
47  	}
48  
49  	public void testSetSqlValue() throws Exception
50  	{
51  		// Create a hsqldb specific blob
52  		byte[] byteArray = new byte[]{1, 2, 3, 4, 5, 6};
53  		Blob blob = new TestBlob(byteArray);
54  		MockPreparedStatement statement = new MockPreparedStatement();
55  		TYPE.setSqlValue(blob, 1, statement);
56  		assertEquals(1, statement.getLastSetObjectParamIndex());
57  		assertEquals(Types.BLOB, statement.getLastSetObjectTargetSqlType());
58  		assertEquals(byte[].class, statement.getLastSetObjectParamValue().getClass());
59  		ArrayAssert.assertEquals(byteArray, (byte[])statement.getLastSetObjectParamValue());
60  	}
61  
62  	
63  	public void testAsString() throws Exception {
64          assertEquals("name", "BLOB", TYPE.toString());
65  	}
66  
67  	public void testGetTypeClass() throws Exception {
68  		assertEquals("class", byte[].class, TYPE.getTypeClass());
69  	}
70  
71  
72  }