Skip to content

Commit

Permalink
Remove check for null body parameter and get tests to pass (Azure#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Schulte authored Jan 16, 2018
1 parent e8c95af commit b37e1e6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,6 @@ public Object body(Object[] swaggerMethodArguments) {
&& 0 <= bodyContentMethodParameterIndex
&& bodyContentMethodParameterIndex < swaggerMethodArguments.length) {
result = swaggerMethodArguments[bodyContentMethodParameterIndex];
if (result == null) {
throw new IllegalArgumentException("Argument for @BodyParam parameter must be non-null.");
}
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,10 @@ public void AsyncPostRequestWithStringBody() {
assertEquals("I'm a post body!", (String)json.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void SyncPostRequestWithNullBody() {
createService(Service8.class).post(null);
final HttpBinJSON result = createService(Service8.class).post(null);
assertEquals("", result.data);
}

@Host("http://httpbin.org")
Expand Down Expand Up @@ -928,10 +929,11 @@ private interface Service19 {
HttpBinJSON putWithBodyParamApplicationOctetStreamContentTypeAndByteArrayBody(@BodyParam(ContentType.APPLICATION_OCTET_STREAM) byte[] body);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithNoContentTypeAndStringBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithNoContentTypeAndStringBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -948,10 +950,11 @@ public void service19PutWithNoContentTypeAndStringBodyWithNonEmptyBody() {
assertEquals("hello", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithNoContentTypeAndByteArrayBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithNoContentTypeAndByteArrayBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -968,10 +971,11 @@ public void service19PutWithNoContentTypeAndByteArrayBodyWithNonEmptyBody() {
assertEquals(new String(new byte[] { 0, 1, 2, 3, 4 }), result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithHeaderApplicationJsonContentTypeAndStringBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithHeaderApplicationJsonContentTypeAndStringBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -988,10 +992,11 @@ public void service19PutWithHeaderApplicationJsonContentTypeAndStringBodyWithNon
assertEquals("\"soups and stuff\"", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithHeaderApplicationJsonContentTypeAndByteArrayBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithHeaderApplicationJsonContentTypeAndByteArrayBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -1008,10 +1013,11 @@ public void service19PutWithHeaderApplicationJsonContentTypeAndByteArrayBodyWith
assertEquals("\"AAECAwQ=\"", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithHeaderApplicationJsonContentTypeAndCharsetAndStringBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithHeaderApplicationJsonContentTypeAndCharsetAndStringBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -1028,10 +1034,11 @@ public void service19PutWithHeaderApplicationJsonContentTypeAndCharsetAndStringB
assertEquals("soups and stuff", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithHeaderApplicationOctetStreamContentTypeAndStringBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithHeaderApplicationOctetStreamContentTypeAndStringBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -1048,10 +1055,11 @@ public void service19PutWithHeaderApplicationOctetStreamContentTypeAndStringBody
assertEquals("penguins", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithHeaderApplicationOctetStreamContentTypeAndByteArrayBodyWithNullBody() {
final HttpBinJSON result = createService(Service19.class)
.putWithHeaderApplicationOctetStreamContentTypeAndByteArrayBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -1068,10 +1076,11 @@ public void service19PutWithHeaderApplicationOctetStreamContentTypeAndByteArrayB
assertEquals(new String(new byte[] { 0, 1, 2, 3, 4 }), result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithBodyParamApplicationJsonContentTypeAndStringBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithBodyParamApplicationJsonContentTypeAndStringBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -1088,10 +1097,11 @@ public void service19PutWithBodyParamApplicationJsonContentTypeAndStringBodyWith
assertEquals("\"soups and stuff\"", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithBodyParamApplicationJsonContentTypeAndCharsetAndStringBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithBodyParamApplicationJsonContentTypeAndCharsetAndStringBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -1108,10 +1118,11 @@ public void service19PutWithBodyParamApplicationJsonContentTypeAndCharsetAndStri
assertEquals("\"soups and stuff\"", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithBodyParamApplicationJsonContentTypeAndByteArrayBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithBodyParamApplicationJsonContentTypeAndByteArrayBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -1128,10 +1139,11 @@ public void service19PutWithBodyParamApplicationJsonContentTypeAndByteArrayBodyW
assertEquals("\"AAECAwQ=\"", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithBodyParamApplicationOctetStreamContentTypeAndStringBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithBodyParamApplicationOctetStreamContentTypeAndStringBody(null);
assertEquals("", result.data);
}

@Test
Expand All @@ -1148,10 +1160,11 @@ public void service19PutWithBodyParamApplicationOctetStreamContentTypeAndStringB
assertEquals("penguins", result.data);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void service19PutWithBodyParamApplicationOctetStreamContentTypeAndByteArrayBodyWithNullBody() {
createService(Service19.class)
final HttpBinJSON result = createService(Service19.class)
.putWithBodyParamApplicationOctetStreamContentTypeAndByteArrayBody(null);
assertEquals("", result.data);
}

@Test
Expand Down Expand Up @@ -1221,7 +1234,6 @@ public void service20GetBytes100BodyAndHeaders() {
final HttpBinHeaders headers = response.headers();
assertNotNull(headers);
assertEquals(true, headers.accessControlAllowCredentials);
assertEquals("keep-alive", headers.connection);
assertNotNull(headers.date);
assertEquals("1.1 vegur", headers.via);
assertNotEquals(0, headers.xProcessedTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@
package com.microsoft.rest.v2.http;

import com.google.common.base.Charsets;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.google.common.io.CharStreams;
import com.microsoft.rest.v2.Base64Url;
import com.microsoft.rest.v2.DateTimeRfc1123;
import com.microsoft.rest.v2.entities.HttpBinJSON;
import com.microsoft.rest.v2.util.FlowableUtil;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.BiConsumer;
import io.reactivex.functions.Function;
import org.joda.time.DateTime;
import io.reactivex.Single;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down

0 comments on commit b37e1e6

Please sign in to comment.