From: Jean-Marc V. <jm...@us...> - 2004-07-09 12:20:40
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18026/src/org/exist/xmldb/test Modified Files: CreateCollectionsTest.java Log Message: add test for storing binary resource Index: CreateCollectionsTest.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/test/CreateCollectionsTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CreateCollectionsTest.java 9 Jul 2004 08:31:40 -0000 1.7 --- CreateCollectionsTest.java 9 Jul 2004 12:20:31 -0000 1.8 *************** *** 1,5 **** --- 1,7 ---- package org.exist.xmldb.test; + import java.io.BufferedInputStream; import java.io.File; + import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; *************** *** 134,137 **** --- 136,145 ---- testCollection); + byte[] data = storeBinaryResourceFromFile( new File( "../webapp/logo.jpg"), testCollection); + Object content = testCollection.getResource("logo.jpg").getContent(); + byte[] dataStored = (byte[])content; + assertTrue("After storing binary resource, data out==data in", + Arrays.equals(dataStored, data) ); + } catch (XMLDBException e) { e.printStackTrace(); *************** *** 162,165 **** --- 170,199 ---- } + private byte[] storeBinaryResourceFromFile( + File file, + Collection testCollection) + throws XMLDBException, IOException { + System.out.println("storing " + file.getAbsolutePath()); + + Resource res = + (BinaryResource) testCollection.createResource( + file.getName(), + "BinaryResource" ); + assertNotNull("store binary Resource From File", res); + + // Get an array of bytes from the file: + FileInputStream istr = new FileInputStream(file); + BufferedInputStream bstr = new BufferedInputStream( istr ); // promote + int size = (int) file.length(); // get the file size (in bytes) + byte[] data = new byte[size]; // allocate byte array of right size + bstr.read( data, 0, size ); // read into byte array + bstr.close(); + + res.setContent(data); + testCollection.storeResource(res); + System.out.println("stored " + file.getAbsolutePath()); + return data; + } + public void testMultipleCreates() { try { |