package org.sagebionetworks.util;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class ContentDispositionUtilsTest {

	@Test
	public void testGetContentDispositionValue(){
		String result = ContentDispositionUtils.getContentDispositionValue("foo.txt");
		assertEquals("attachment; filename=\"foo.txt\"; filename*=utf-8''foo.txt", result);
	}

	@Test
	public void testGetContentDispositionValueWithSpaceCharacters(){
		String result = ContentDispositionUtils.getContentDispositionValue("foo bar(baz).txt");
		assertEquals("attachment; filename=\"foo bar(baz).txt\"; filename*=utf-8''foo%20bar%28baz%29.txt", result);
	}

	@Test
	public void testGetContentDispositionValueWithCommaCharacters(){
		String result = ContentDispositionUtils.getContentDispositionValue("foo,bar,(baz).txt");
		assertEquals("attachment; filename=\"foo,bar,(baz).txt\"; filename*=utf-8''foo%2Cbar%2C%28baz%29.txt", result);
	}

	@Test
	public void testGetContentDispositionValueWithISO_8859_1(){
		String result = ContentDispositionUtils.getContentDispositionValue("fÖØ bær.txt");
		assertEquals("attachment; filename=\"fÖØ bær.txt\"; filename*=utf-8''f%C3%96%C3%98%20b%C3%A6r.txt", result);
	}
	// NOTE: at a higher level, we don't support filehandles w/ unicode character filenames, but if we were to lift that restriction,
	// uploads should still work
	@Test
	public void testGetContentDispositionValueWithUnicodeCharacters(){
		String result = ContentDispositionUtils.getContentDispositionValue("foo文件bar.txt");
		assertEquals("attachment; filename=\"foo__bar.txt\"; filename*=utf-8''foo%E6%96%87%E4%BB%B6bar.txt", result);
	}
}


@@ -918,32 +918,306 @@
 %22, result);%0A%09%7D%0A%0A
+%09@Test%0A%09public void testGetContentDispositionValueWithPercentCharacters()%7B%0A%09%09String result = ContentDispositionUtils.getContentDispositionValue(%22foo%25bar%25baz.txt%22);%0A%09%09assertEquals(%22attachment; filename=%5C%22foo%25bar%25baz.txt%5C%22; filename*=utf-8''foo%2525bar%2525baz.txt%22, result);%0A%09%7D%0A%0A
 %09@Test%0A%09public v

add test for percent signs