
package com.exedio.cope.lib;

import java.io.IOException;

public class MediaTest extends DatabaseLibTest
{
	private MediaItem item;
	private final byte[] data = new byte[]{-86,122,-8,23};
	private final byte[] data2 = new byte[]{-97,35,-126,86,19,-8};
	
	public void setUp() throws Exception
	{
		super.setUp();
		item = new MediaItem();
	}
	
	public void tearDown() throws Exception
	{
		item.delete();
	}
	
	public void testMedia() throws IOException
	{
		// file
		assertEquals(null, item.getFileData());
		assertEquals(null, item.getFileMimeMajor());
		assertEquals(null, item.getFileMimeMinor());
		assertEquals(null, item.getFileURL());
		
		item.setFileData(stream(data), "fileMajor", "fileMinor");
		assertData(data, item.getFileData());
		assertEquals("fileMajor", item.getFileMimeMajor());
		assertEquals("fileMinor", item.getFileMimeMinor());
		assertTrue(item.getFileURL().endsWith(".fileMajor.fileMinor"));
		
		item.setFileData(stream(data2), "fileMajor2", "fileMinor2");
		assertData(data2, item.getFileData());
		assertEquals("fileMajor2", item.getFileMimeMajor());
		assertEquals("fileMinor2", item.getFileMimeMinor());
		assertTrue(item.getFileURL().endsWith(".fileMajor2.fileMinor2"));
		
		item.setFileData(null, null, null);
		assertEquals(null, item.getFileData());
		assertEquals(null, item.getFileMimeMajor());
		assertEquals(null, item.getFileMimeMinor());
		assertEquals(null, item.getFileURL());


		// image
		assertEquals(null, item.getImageData());
		assertEquals(null, item.getImageMimeMajor());
		assertEquals(null, item.getImageMimeMinor());
		assertEquals(null, item.getImageURL());

		item.setImageData(stream(data), "imageMinor");
		assertData(data, item.getImageData());
		assertEquals("image", item.getImageMimeMajor());
		assertEquals("imageMinor", item.getImageMimeMinor());
		assertTrue(item.getImageURL().endsWith(".image.imageMinor"));

		item.setImageData(stream(data2), "jpeg");
		assertData(data2, item.getImageData());
		assertEquals("image", item.getImageMimeMajor());
		assertEquals("jpeg", item.getImageMimeMinor());
		assertTrue(item.getImageURL().endsWith(".jpg"));

		item.setImageData(null, null);
		assertEquals(null, item.getImageData());
		assertEquals(null, item.getImageMimeMajor());
		assertEquals(null, item.getImageMimeMinor());
		assertEquals(null, item.getImageURL());
		
		
		// photo
		assertEquals(null, item.getPhotoData());
		assertEquals(null, item.getPhotoMimeMajor());
		assertEquals(null, item.getPhotoMimeMinor());
		assertEquals(null, item.getPhotoURL());

		item.setPhotoData(stream(data));
		assertData(data, item.getPhotoData());
		assertEquals("image", item.getPhotoMimeMajor());
		assertEquals("jpeg", item.getPhotoMimeMinor());
		assertTrue(item.getPhotoURL().endsWith(".jpg"));
	}

}

@@ -2754,15 +2754,246 @@
 .jpg%22));
+%0A%0A%09%09item.setPhotoData(stream(data2));%0A%09%09assertData(data2, item.getPhotoData());%0A%09%09assertEquals(%22image%22, item.getPhotoMimeMajor());%0A%09%09assertEquals(%22jpeg%22, item.getPhotoMimeMinor());%0A%09%09assertTrue(item.getPhotoURL().endsWith(%22.jpg%22));
 %0A%09%7D%0A%0A%7D%0A

test resetting data for minor mime type fixed media attributes