
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"));

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

		item.setPhotoData(null);
		assertEquals(null, item.getPhotoData());
		assertEquals(null, item.getPhotoMimeMajor());
		assertEquals(null, item.getPhotoMimeMinor());
		assertEquals(null, item.getPhotoURL());
	}

}

@@ -396,32 +396,377 @@
 .delete();%0A%09%7D%0A%09%0A
+%09private void assertExtension(final String mimeMajor, final String mimeMinor, final String extension)%0A%09%09throws IOException%0A%09%7B%0A%09%09item.setFileData(stream(data2), mimeMajor, mimeMinor);%0A%09%09assertEquals(mimeMajor, item.getFileMimeMajor());%0A%09%09assertEquals(mimeMinor, item.getFileMimeMinor());%0A%09%09assertTrue(item.getFileURL().endsWith(extension));%0A%09%7D%0A%09%0A
 %09public void tes
@@ -1540,32 +1540,340 @@
 leMinor2%22));%0A%09%09%0A
+%09%09assertExtension(%22image%22, %22jpeg%22, %22.jpg%22);%0A%09%09assertExtension(%22image%22, %22pjpeg%22, %22.jpg%22);%0A%09%09assertExtension(%22image%22, %22png%22, %22.png%22);%0A%09%09assertExtension(%22image%22, %22gif%22, %22.gif%22);%0A%09%09assertExtension(%22text%22, %22html%22, %22.html%22);%0A%09%09assertExtension(%22text%22, %22plain%22, %22.txt%22);%0A%09%09assertExtension(%22text%22, %22css%22, %22.css%22);%0A%09%09%0A
 %09%09item.setFileDa

test compact media url extensions