Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amoldavsky committed May 18, 2021
1 parent c35ff95 commit 0e6dd8d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ModelPredictionController {
@RequestMapping(
value = "/predict",
method = {RequestMethod.GET, RequestMethod.POST},
params = {"json"},
produces = MediaType.APPLICATION_JSON_UTF8_VALUE
)
public ResponseEntity<String> predictLegacy(@RequestParam("json") String json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import static io.seldon.wrapper.util.TestUtils.readFile;

import io.seldon.protos.PredictionProtos;
import java.nio.charset.StandardCharsets;
import org.junit.Assert;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
Expand All @@ -21,6 +26,7 @@

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
// @AutoConfigureMockMvc
public class ModelPredictionControllerTest {

Expand Down Expand Up @@ -61,7 +67,7 @@ public void testPredictLegacyPostQuery() throws Exception {
mvc.perform(
MockMvcRequestBuilders.post("/predict")
.accept(MediaType.APPLICATION_JSON_UTF8)
.param("json", predictJson)
.queryParam("json", predictJson)
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn();
String response = res.getResponse().getContentAsString();
Expand All @@ -84,6 +90,43 @@ public void testPredictLegacyPostForm() throws Exception {
Assert.assertEquals(200, res.getResponse().getStatus());
}

@Test
public void testPredictLegacyButNotPredict() throws Exception {
final String predictJson = readFile("src/test/resources/request.json", StandardCharsets.UTF_8);
MvcResult res =
mvc.perform(
MockMvcRequestBuilders.post("/predict")
.accept(MediaType.APPLICATION_JSON_UTF8)
.param("json", predictJson)
.content(predictJson)
.contentType(MediaType.APPLICATION_FORM_URLENCODED))
.andReturn();
String response = res.getResponse().getContentAsString();
System.out.println(response);
Assert.assertEquals(200, res.getResponse().getStatus());

// if we get back a header of "application/json;charset=UTF-8" then we are hitting the legacy predict
Assert.assertEquals(res.getResponse().getContentType(), MediaType.APPLICATION_JSON_UTF8_VALUE);
}

@Test
public void testPredictButNotPredictLegacy() throws Exception {
final String predictJson = readFile("src/test/resources/request.json", StandardCharsets.UTF_8);
MvcResult res =
mvc.perform(
MockMvcRequestBuilders.post("/predict")
.accept(MediaType.APPLICATION_JSON)
.content(predictJson)
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn();
String response = res.getResponse().getContentAsString();
System.out.println(response);
Assert.assertEquals(200, res.getResponse().getStatus());

// if we get back a header of "application/json" then we are hitting the legacy predict
Assert.assertEquals(res.getResponse().getContentType(), MediaType.APPLICATION_JSON_VALUE);
}

@Test
public void testPredict() throws Exception {
final String predictJson = readFile("src/test/resources/request.json", StandardCharsets.UTF_8);
Expand All @@ -99,6 +142,24 @@ public void testPredict() throws Exception {
Assert.assertEquals(200, res.getResponse().getStatus());
}

@Test
public void testPredictWithUTF8Header() throws Exception {
final String predictJson = readFile("src/test/resources/request.json", StandardCharsets.UTF_8);
MvcResult res =
mvc.perform(
MockMvcRequestBuilders.post("/predict")
.accept(MediaType.APPLICATION_JSON)
.content(predictJson)
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn();
String response = res.getResponse().getContentAsString();
System.out.println(response);
Assert.assertEquals(200, res.getResponse().getStatus());

// if we get back a header of "application/json" then we are hitting the legacy predict
Assert.assertEquals(res.getResponse().getContentType(), MediaType.APPLICATION_JSON_VALUE);
}

@Test
public void testFeedback() throws Exception {
final String predictJson = readFile("src/test/resources/feedback.json", StandardCharsets.UTF_8);
Expand Down

0 comments on commit 0e6dd8d

Please sign in to comment.