fixed content-disposition tests

This commit is contained in:
Adrian Cole 2010-09-18 18:51:13 -07:00
parent a8852e54f9
commit 50a44b91c4
4 changed files with 61 additions and 11 deletions

View File

@ -203,6 +203,10 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentType());
if (request.getPayload().getContentDisposition() != null)
connection.setRequestProperty("Content-Disposition", request.getPayload().getContentDisposition());
if (request.getPayload().getContentEncoding() != null)
connection.setRequestProperty("Content-Encoding", request.getPayload().getContentEncoding());
if (request.getPayload().getContentLanguage() != null)
connection.setRequestProperty("Content-Language", request.getPayload().getContentLanguage());
if (chunked) {
connection.setChunkedStreamingMode(8196);
} else {

View File

@ -242,6 +242,26 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
payload.release();
}
@Test(invocationCount = 5, timeOut = 5000)
public void testPostContentEncoding() throws ExecutionException, InterruptedException, TimeoutException,
IOException {
Payload payload = Payloads.newStringPayload("foo");
payload.setContentEncoding("gzip");
Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
assertEquals(headers.get("x-Content-Encoding"), Collections.singleton("gzip"));
payload.release();
}
@Test(invocationCount = 5, timeOut = 5000)
public void testPostContentLanguage() throws ExecutionException, InterruptedException, TimeoutException,
IOException {
Payload payload = Payloads.newStringPayload("foo");
payload.setContentLanguage("mi, en");
Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
assertEquals(headers.get("x-Content-Language"), Collections.singleton("mi, en"));
payload.release();
}
@Test(invocationCount = 5, timeOut = 5000)
public void testPut() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
assertEquals(client.upload("", "foo").trim(), "fooPUT");

View File

@ -72,10 +72,13 @@ public abstract class BaseRestClientTest {
bind(TransformingHttpCommandExecutorService.class).toInstance(mock);
}
}
protected void assertPayloadEquals(HttpRequest request, String toMatch, String contentType, boolean contentMD5) {
assertPayloadEquals(request, toMatch, contentType, null, contentMD5);
assertPayloadEquals(request, toMatch, contentType, null, null, null, contentMD5);
}
protected void assertPayloadEquals(HttpRequest request, String toMatch, String contentType, String contentDispositon, boolean contentMD5) {
protected void assertPayloadEquals(HttpRequest request, String toMatch, String contentType,
String contentDispositon, String contentEncoding, String contentLanguage, boolean contentMD5) {
if (request.getPayload() == null) {
assertNull(toMatch);
} else {
@ -88,15 +91,16 @@ public abstract class BaseRestClientTest {
assertEquals(payload, toMatch);
Long length = new Long(payload.getBytes().length);
try {
assertContentHeadersEqual(request, contentType, contentDispositon, length, contentMD5 ? CryptoStreams
.md5(request.getPayload()) : null);
assertContentHeadersEqual(request, contentType, contentDispositon, contentEncoding, contentLanguage,
length, contentMD5 ? CryptoStreams.md5(request.getPayload()) : null);
} catch (IOException e) {
propagate(e);
}
}
}
protected void assertContentHeadersEqual(HttpRequest request, String contentType, String contentDispositon, Long length, byte[] contentMD5) {
protected void assertContentHeadersEqual(HttpRequest request, String contentType, String contentDispositon,
String contentEncoding, String contentLanguage, Long length, byte[] contentMD5) {
if (request.getFirstHeaderOrNull(TRANSFER_ENCODING) == null) {
assertEquals(request.getPayload().getContentLength(), length);
} else {
@ -106,10 +110,12 @@ public abstract class BaseRestClientTest {
}
assertEquals(request.getPayload().getContentType(), contentType);
assertEquals(request.getPayload().getContentDisposition(), contentDispositon);
assertEquals(request.getPayload().getContentEncoding(), contentEncoding);
assertEquals(request.getPayload().getContentLanguage(), contentLanguage);
assertEquals(request.getPayload().getContentMD5(), contentMD5);
}
//FIXME Shouldn't be assertPayloadHeadersEqual?
// FIXME Shouldn't be assertPayloadHeadersEqual?
protected void assertNonPayloadHeadersEqual(HttpRequest request, String toMatch) {
assertEquals(sortAndConcatHeadersIntoString(request.getHeaders()), toMatch);
}

View File

@ -1501,7 +1501,27 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
HttpRequest request = factory(TestQuery.class).createRequest(method, payload);
assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, "whoops", "application/unknown", "attachment; filename=photo.jpg", false);
assertPayloadEquals(request, "whoops", "application/unknown", "attachment; filename=photo.jpg", null, null, false);
}
public void testPutPayloadContentEncoding() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestTransformers.class.getMethod("put", Payload.class);
Payload payload = newStringPayload("whoops");
payload.setContentEncoding("gzip");
HttpRequest request = factory(TestQuery.class).createRequest(method, payload);
assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, "whoops", "application/unknown", null, "gzip", null, false);
}
public void testPutPayloadContentLanguage() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestTransformers.class.getMethod("put", Payload.class);
Payload payload = newStringPayload("whoops");
payload.setContentLanguage("en");
HttpRequest request = factory(TestQuery.class).createRequest(method, payload);
assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, "whoops", "application/unknown", null, null, "en", false);
}
public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException,