Handling my custom exception in Spring MVC integration test












1















I have the following method in a controller class:



@PostMapping("employees")
@ResponseStatus(HttpStatus.CREATED)
public Employee addEmployee(@Valid @RequestBody Employee employee) {
try {
return employeeRepository.save(employee);
} catch (DataIntegrityViolationException e) {
e.printStackTrace();
Optional<Employee> existingEmployee = employeeRepository.findByTagId(employee.getTagId());
if (!existingEmployee.isPresent()) {
//The exception root cause was not due to a unique ID violation then
throw e;
}
throw new DuplicateEntryException(
"An employee named " + existingEmployee.get().getName() + " already uses RFID tagID " + existingEmployee.get().getTagId());
}
}


Where the Employee class has a string field called tagId which has a @NaturalId annotation on it. (Please ignore that there is no dedicated service layer, this is a small and simple app).



Here is my custom DuplicateEntryException:



@ResponseStatus(HttpStatus.CONFLICT)
public class DuplicateEntryException extends RuntimeException {

public DuplicateEntryException() {
super();
}

public DuplicateEntryException(String message) {
super(message);
}

public DuplicateEntryException(String message, Throwable cause) {
super(message, cause);
}

}


Thanks to the @ResponseStatus(HttpStatus.CONFLICT) line, when I manually test the method, I get the default spring boot REST message with the timestamp, status, error, message and path fields.



I'm still getting familiar with testing in Spring and I have this test:



@Test
public void _02addEmployee_whenDuplicateTagId_thenExceptionIsReturned() throws Exception {
Employee sampleEmployee = new Employee("tagId01", "John Doe");
System.out.println("Employees in the database: " + repository.findAll().size()); //prints 1
// @formatter:off
mvc.perform(post("/employees").contentType(MediaType.APPLICATION_JSON).content(JsonUtil.toJson(sampleEmployee)))
.andExpect(status().isConflict())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value("An employee named John Doe already uses RFID tagID tagId01"));
// @formatter:on

int employeeCount = repository.findAll().size();
Assert.assertEquals(1, employeeCount);
}


As you can guess, there is another test that runs first, called _01addEmployee_whenValidInput_thenCreateEmployee(), which inserts an employee with the same tagID, which is used in test #2. Test #1 passes, but test #2 does not, because the HTTP response looks like this:



MockHttpServletResponse:
Status = 409
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies =


And in the console before the above response, I see this:



Resolved Exception:
Type = ai.aitia.rfid_employee.exception.DuplicateEntryException


So my 2nd test fails because java.lang.AssertionError: Content type not set.
What causes the different behaviour compared to the manual testing? Why isn't this returned?



{
"timestamp": "2019-01-03T09:47:33.371+0000",
"status": 409,
"error": "Conflict",
"message": "An employee named John Doe already uses RFID tagID tagId01",
"path": "/employees"
}


Update: I experienced the same thing with a different REST endpoint as well, where the test case resulted in my own ResourceNotFoundException, but the actual JSON error object was not received by the MockMvc object.



Update2: Here are my class level annotations for the test class:



@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = RfidEmployeeApplication.class)
@AutoConfigureMockMvc
@AutoConfigureTestDatabase
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@TestPropertySource(locations = "classpath:application-test.properties")









share|improve this question

























  • are you using a @RestController or @Controller?

    – stacker
    Jan 3 at 10:49











  • yes, the former

    – Zoltán Umlauf
    Jan 3 at 10:55











  • like I said, that's the one I'm already using

    – Zoltán Umlauf
    Jan 3 at 11:02











  • have you tried @PostMapping(value="employees",produces = "application/json")?

    – stacker
    Jan 3 at 11:06











  • i've just tried it, it did not make a difference

    – Zoltán Umlauf
    Jan 3 at 11:09
















1















I have the following method in a controller class:



@PostMapping("employees")
@ResponseStatus(HttpStatus.CREATED)
public Employee addEmployee(@Valid @RequestBody Employee employee) {
try {
return employeeRepository.save(employee);
} catch (DataIntegrityViolationException e) {
e.printStackTrace();
Optional<Employee> existingEmployee = employeeRepository.findByTagId(employee.getTagId());
if (!existingEmployee.isPresent()) {
//The exception root cause was not due to a unique ID violation then
throw e;
}
throw new DuplicateEntryException(
"An employee named " + existingEmployee.get().getName() + " already uses RFID tagID " + existingEmployee.get().getTagId());
}
}


Where the Employee class has a string field called tagId which has a @NaturalId annotation on it. (Please ignore that there is no dedicated service layer, this is a small and simple app).



Here is my custom DuplicateEntryException:



@ResponseStatus(HttpStatus.CONFLICT)
public class DuplicateEntryException extends RuntimeException {

public DuplicateEntryException() {
super();
}

public DuplicateEntryException(String message) {
super(message);
}

public DuplicateEntryException(String message, Throwable cause) {
super(message, cause);
}

}


Thanks to the @ResponseStatus(HttpStatus.CONFLICT) line, when I manually test the method, I get the default spring boot REST message with the timestamp, status, error, message and path fields.



I'm still getting familiar with testing in Spring and I have this test:



@Test
public void _02addEmployee_whenDuplicateTagId_thenExceptionIsReturned() throws Exception {
Employee sampleEmployee = new Employee("tagId01", "John Doe");
System.out.println("Employees in the database: " + repository.findAll().size()); //prints 1
// @formatter:off
mvc.perform(post("/employees").contentType(MediaType.APPLICATION_JSON).content(JsonUtil.toJson(sampleEmployee)))
.andExpect(status().isConflict())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value("An employee named John Doe already uses RFID tagID tagId01"));
// @formatter:on

int employeeCount = repository.findAll().size();
Assert.assertEquals(1, employeeCount);
}


As you can guess, there is another test that runs first, called _01addEmployee_whenValidInput_thenCreateEmployee(), which inserts an employee with the same tagID, which is used in test #2. Test #1 passes, but test #2 does not, because the HTTP response looks like this:



MockHttpServletResponse:
Status = 409
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies =


And in the console before the above response, I see this:



Resolved Exception:
Type = ai.aitia.rfid_employee.exception.DuplicateEntryException


So my 2nd test fails because java.lang.AssertionError: Content type not set.
What causes the different behaviour compared to the manual testing? Why isn't this returned?



{
"timestamp": "2019-01-03T09:47:33.371+0000",
"status": 409,
"error": "Conflict",
"message": "An employee named John Doe already uses RFID tagID tagId01",
"path": "/employees"
}


Update: I experienced the same thing with a different REST endpoint as well, where the test case resulted in my own ResourceNotFoundException, but the actual JSON error object was not received by the MockMvc object.



Update2: Here are my class level annotations for the test class:



@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = RfidEmployeeApplication.class)
@AutoConfigureMockMvc
@AutoConfigureTestDatabase
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@TestPropertySource(locations = "classpath:application-test.properties")









share|improve this question

























  • are you using a @RestController or @Controller?

    – stacker
    Jan 3 at 10:49











  • yes, the former

    – Zoltán Umlauf
    Jan 3 at 10:55











  • like I said, that's the one I'm already using

    – Zoltán Umlauf
    Jan 3 at 11:02











  • have you tried @PostMapping(value="employees",produces = "application/json")?

    – stacker
    Jan 3 at 11:06











  • i've just tried it, it did not make a difference

    – Zoltán Umlauf
    Jan 3 at 11:09














1












1








1








I have the following method in a controller class:



@PostMapping("employees")
@ResponseStatus(HttpStatus.CREATED)
public Employee addEmployee(@Valid @RequestBody Employee employee) {
try {
return employeeRepository.save(employee);
} catch (DataIntegrityViolationException e) {
e.printStackTrace();
Optional<Employee> existingEmployee = employeeRepository.findByTagId(employee.getTagId());
if (!existingEmployee.isPresent()) {
//The exception root cause was not due to a unique ID violation then
throw e;
}
throw new DuplicateEntryException(
"An employee named " + existingEmployee.get().getName() + " already uses RFID tagID " + existingEmployee.get().getTagId());
}
}


Where the Employee class has a string field called tagId which has a @NaturalId annotation on it. (Please ignore that there is no dedicated service layer, this is a small and simple app).



Here is my custom DuplicateEntryException:



@ResponseStatus(HttpStatus.CONFLICT)
public class DuplicateEntryException extends RuntimeException {

public DuplicateEntryException() {
super();
}

public DuplicateEntryException(String message) {
super(message);
}

public DuplicateEntryException(String message, Throwable cause) {
super(message, cause);
}

}


Thanks to the @ResponseStatus(HttpStatus.CONFLICT) line, when I manually test the method, I get the default spring boot REST message with the timestamp, status, error, message and path fields.



I'm still getting familiar with testing in Spring and I have this test:



@Test
public void _02addEmployee_whenDuplicateTagId_thenExceptionIsReturned() throws Exception {
Employee sampleEmployee = new Employee("tagId01", "John Doe");
System.out.println("Employees in the database: " + repository.findAll().size()); //prints 1
// @formatter:off
mvc.perform(post("/employees").contentType(MediaType.APPLICATION_JSON).content(JsonUtil.toJson(sampleEmployee)))
.andExpect(status().isConflict())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value("An employee named John Doe already uses RFID tagID tagId01"));
// @formatter:on

int employeeCount = repository.findAll().size();
Assert.assertEquals(1, employeeCount);
}


As you can guess, there is another test that runs first, called _01addEmployee_whenValidInput_thenCreateEmployee(), which inserts an employee with the same tagID, which is used in test #2. Test #1 passes, but test #2 does not, because the HTTP response looks like this:



MockHttpServletResponse:
Status = 409
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies =


And in the console before the above response, I see this:



Resolved Exception:
Type = ai.aitia.rfid_employee.exception.DuplicateEntryException


So my 2nd test fails because java.lang.AssertionError: Content type not set.
What causes the different behaviour compared to the manual testing? Why isn't this returned?



{
"timestamp": "2019-01-03T09:47:33.371+0000",
"status": 409,
"error": "Conflict",
"message": "An employee named John Doe already uses RFID tagID tagId01",
"path": "/employees"
}


Update: I experienced the same thing with a different REST endpoint as well, where the test case resulted in my own ResourceNotFoundException, but the actual JSON error object was not received by the MockMvc object.



Update2: Here are my class level annotations for the test class:



@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = RfidEmployeeApplication.class)
@AutoConfigureMockMvc
@AutoConfigureTestDatabase
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@TestPropertySource(locations = "classpath:application-test.properties")









share|improve this question
















I have the following method in a controller class:



@PostMapping("employees")
@ResponseStatus(HttpStatus.CREATED)
public Employee addEmployee(@Valid @RequestBody Employee employee) {
try {
return employeeRepository.save(employee);
} catch (DataIntegrityViolationException e) {
e.printStackTrace();
Optional<Employee> existingEmployee = employeeRepository.findByTagId(employee.getTagId());
if (!existingEmployee.isPresent()) {
//The exception root cause was not due to a unique ID violation then
throw e;
}
throw new DuplicateEntryException(
"An employee named " + existingEmployee.get().getName() + " already uses RFID tagID " + existingEmployee.get().getTagId());
}
}


Where the Employee class has a string field called tagId which has a @NaturalId annotation on it. (Please ignore that there is no dedicated service layer, this is a small and simple app).



Here is my custom DuplicateEntryException:



@ResponseStatus(HttpStatus.CONFLICT)
public class DuplicateEntryException extends RuntimeException {

public DuplicateEntryException() {
super();
}

public DuplicateEntryException(String message) {
super(message);
}

public DuplicateEntryException(String message, Throwable cause) {
super(message, cause);
}

}


Thanks to the @ResponseStatus(HttpStatus.CONFLICT) line, when I manually test the method, I get the default spring boot REST message with the timestamp, status, error, message and path fields.



I'm still getting familiar with testing in Spring and I have this test:



@Test
public void _02addEmployee_whenDuplicateTagId_thenExceptionIsReturned() throws Exception {
Employee sampleEmployee = new Employee("tagId01", "John Doe");
System.out.println("Employees in the database: " + repository.findAll().size()); //prints 1
// @formatter:off
mvc.perform(post("/employees").contentType(MediaType.APPLICATION_JSON).content(JsonUtil.toJson(sampleEmployee)))
.andExpect(status().isConflict())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value("An employee named John Doe already uses RFID tagID tagId01"));
// @formatter:on

int employeeCount = repository.findAll().size();
Assert.assertEquals(1, employeeCount);
}


As you can guess, there is another test that runs first, called _01addEmployee_whenValidInput_thenCreateEmployee(), which inserts an employee with the same tagID, which is used in test #2. Test #1 passes, but test #2 does not, because the HTTP response looks like this:



MockHttpServletResponse:
Status = 409
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies =


And in the console before the above response, I see this:



Resolved Exception:
Type = ai.aitia.rfid_employee.exception.DuplicateEntryException


So my 2nd test fails because java.lang.AssertionError: Content type not set.
What causes the different behaviour compared to the manual testing? Why isn't this returned?



{
"timestamp": "2019-01-03T09:47:33.371+0000",
"status": 409,
"error": "Conflict",
"message": "An employee named John Doe already uses RFID tagID tagId01",
"path": "/employees"
}


Update: I experienced the same thing with a different REST endpoint as well, where the test case resulted in my own ResourceNotFoundException, but the actual JSON error object was not received by the MockMvc object.



Update2: Here are my class level annotations for the test class:



@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = RfidEmployeeApplication.class)
@AutoConfigureMockMvc
@AutoConfigureTestDatabase
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@TestPropertySource(locations = "classpath:application-test.properties")






spring-boot spring-mvc spring-test junit5 spring-test-mvc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 10:05







Zoltán Umlauf

















asked Jan 3 at 10:15









Zoltán UmlaufZoltán Umlauf

351622




351622













  • are you using a @RestController or @Controller?

    – stacker
    Jan 3 at 10:49











  • yes, the former

    – Zoltán Umlauf
    Jan 3 at 10:55











  • like I said, that's the one I'm already using

    – Zoltán Umlauf
    Jan 3 at 11:02











  • have you tried @PostMapping(value="employees",produces = "application/json")?

    – stacker
    Jan 3 at 11:06











  • i've just tried it, it did not make a difference

    – Zoltán Umlauf
    Jan 3 at 11:09



















  • are you using a @RestController or @Controller?

    – stacker
    Jan 3 at 10:49











  • yes, the former

    – Zoltán Umlauf
    Jan 3 at 10:55











  • like I said, that's the one I'm already using

    – Zoltán Umlauf
    Jan 3 at 11:02











  • have you tried @PostMapping(value="employees",produces = "application/json")?

    – stacker
    Jan 3 at 11:06











  • i've just tried it, it did not make a difference

    – Zoltán Umlauf
    Jan 3 at 11:09

















are you using a @RestController or @Controller?

– stacker
Jan 3 at 10:49





are you using a @RestController or @Controller?

– stacker
Jan 3 at 10:49













yes, the former

– Zoltán Umlauf
Jan 3 at 10:55





yes, the former

– Zoltán Umlauf
Jan 3 at 10:55













like I said, that's the one I'm already using

– Zoltán Umlauf
Jan 3 at 11:02





like I said, that's the one I'm already using

– Zoltán Umlauf
Jan 3 at 11:02













have you tried @PostMapping(value="employees",produces = "application/json")?

– stacker
Jan 3 at 11:06





have you tried @PostMapping(value="employees",produces = "application/json")?

– stacker
Jan 3 at 11:06













i've just tried it, it did not make a difference

– Zoltán Umlauf
Jan 3 at 11:09





i've just tried it, it did not make a difference

– Zoltán Umlauf
Jan 3 at 11:09












1 Answer
1






active

oldest

votes


















1














org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error
fills full information for error response body, but for MockMvc it is not working. I just checked you can easily use in this case TestRestTemplate.



First just @Autowired private TestRestTemplate testRestTemplate; in test class.



and modify your test method for example:



ResponseEntity<String> response = testRestTemplate.postForEntity("/employees", sampleEmployee, String.class);
String message = com.jayway.jsonpath.JsonPath.read(response.getBody(), "$.message");
String expectedMessage = "An employee named John Doe already uses RFID tagID tagId01";
Assert.assertEquals(expectedMessage, message);
Assert.assertTrue(response.getStatusCode().is4xxClientError());

for example.




share|improve this answer
























  • Big thanks for your persistent help. I wonder If I should just stop using MockMvc alltogether in favour of TestRestTemplate then.

    – Zoltán Umlauf
    Jan 9 at 8:33











  • Although reading up about it, it looks like it's better to keep using MockMvc whereever possible, for server side tests.

    – Zoltán Umlauf
    Jan 9 at 8:36











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020222%2fhandling-my-custom-exception-in-spring-mvc-integration-test%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error
fills full information for error response body, but for MockMvc it is not working. I just checked you can easily use in this case TestRestTemplate.



First just @Autowired private TestRestTemplate testRestTemplate; in test class.



and modify your test method for example:



ResponseEntity<String> response = testRestTemplate.postForEntity("/employees", sampleEmployee, String.class);
String message = com.jayway.jsonpath.JsonPath.read(response.getBody(), "$.message");
String expectedMessage = "An employee named John Doe already uses RFID tagID tagId01";
Assert.assertEquals(expectedMessage, message);
Assert.assertTrue(response.getStatusCode().is4xxClientError());

for example.




share|improve this answer
























  • Big thanks for your persistent help. I wonder If I should just stop using MockMvc alltogether in favour of TestRestTemplate then.

    – Zoltán Umlauf
    Jan 9 at 8:33











  • Although reading up about it, it looks like it's better to keep using MockMvc whereever possible, for server side tests.

    – Zoltán Umlauf
    Jan 9 at 8:36
















1














org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error
fills full information for error response body, but for MockMvc it is not working. I just checked you can easily use in this case TestRestTemplate.



First just @Autowired private TestRestTemplate testRestTemplate; in test class.



and modify your test method for example:



ResponseEntity<String> response = testRestTemplate.postForEntity("/employees", sampleEmployee, String.class);
String message = com.jayway.jsonpath.JsonPath.read(response.getBody(), "$.message");
String expectedMessage = "An employee named John Doe already uses RFID tagID tagId01";
Assert.assertEquals(expectedMessage, message);
Assert.assertTrue(response.getStatusCode().is4xxClientError());

for example.




share|improve this answer
























  • Big thanks for your persistent help. I wonder If I should just stop using MockMvc alltogether in favour of TestRestTemplate then.

    – Zoltán Umlauf
    Jan 9 at 8:33











  • Although reading up about it, it looks like it's better to keep using MockMvc whereever possible, for server side tests.

    – Zoltán Umlauf
    Jan 9 at 8:36














1












1








1







org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error
fills full information for error response body, but for MockMvc it is not working. I just checked you can easily use in this case TestRestTemplate.



First just @Autowired private TestRestTemplate testRestTemplate; in test class.



and modify your test method for example:



ResponseEntity<String> response = testRestTemplate.postForEntity("/employees", sampleEmployee, String.class);
String message = com.jayway.jsonpath.JsonPath.read(response.getBody(), "$.message");
String expectedMessage = "An employee named John Doe already uses RFID tagID tagId01";
Assert.assertEquals(expectedMessage, message);
Assert.assertTrue(response.getStatusCode().is4xxClientError());

for example.




share|improve this answer













org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error
fills full information for error response body, but for MockMvc it is not working. I just checked you can easily use in this case TestRestTemplate.



First just @Autowired private TestRestTemplate testRestTemplate; in test class.



and modify your test method for example:



ResponseEntity<String> response = testRestTemplate.postForEntity("/employees", sampleEmployee, String.class);
String message = com.jayway.jsonpath.JsonPath.read(response.getBody(), "$.message");
String expectedMessage = "An employee named John Doe already uses RFID tagID tagId01";
Assert.assertEquals(expectedMessage, message);
Assert.assertTrue(response.getStatusCode().is4xxClientError());

for example.





share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 9 at 6:21









borinoborino

908716




908716













  • Big thanks for your persistent help. I wonder If I should just stop using MockMvc alltogether in favour of TestRestTemplate then.

    – Zoltán Umlauf
    Jan 9 at 8:33











  • Although reading up about it, it looks like it's better to keep using MockMvc whereever possible, for server side tests.

    – Zoltán Umlauf
    Jan 9 at 8:36



















  • Big thanks for your persistent help. I wonder If I should just stop using MockMvc alltogether in favour of TestRestTemplate then.

    – Zoltán Umlauf
    Jan 9 at 8:33











  • Although reading up about it, it looks like it's better to keep using MockMvc whereever possible, for server side tests.

    – Zoltán Umlauf
    Jan 9 at 8:36

















Big thanks for your persistent help. I wonder If I should just stop using MockMvc alltogether in favour of TestRestTemplate then.

– Zoltán Umlauf
Jan 9 at 8:33





Big thanks for your persistent help. I wonder If I should just stop using MockMvc alltogether in favour of TestRestTemplate then.

– Zoltán Umlauf
Jan 9 at 8:33













Although reading up about it, it looks like it's better to keep using MockMvc whereever possible, for server side tests.

– Zoltán Umlauf
Jan 9 at 8:36





Although reading up about it, it looks like it's better to keep using MockMvc whereever possible, for server side tests.

– Zoltán Umlauf
Jan 9 at 8:36




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020222%2fhandling-my-custom-exception-in-spring-mvc-integration-test%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas