From ab081d7d969dad51f0ce4270c3e7f1fa9f437b5d Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Sat, 16 Feb 2019 15:14:05 +0100 Subject: [PATCH] add more tests --- ...leValidationControllerIntegrationTest.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java b/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java index 95507a61e8..318a15d8f7 100644 --- a/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java +++ b/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java @@ -33,11 +33,40 @@ public class RequestAndPathVariableValidationControllerIntegrationTest { @Test public void getNameOfDayByNumberRequestParam_whenGetWithProperRequestParam_thenReturn200() throws Exception { - mockMvc.perform(get("/public/api/1/name-for-day").param("dayOfWeek", Integer.toString(5))).andExpect(status().isOk()); + mockMvc.perform(get("/public/api/1/name-for-day").param("dayOfWeek", Integer.toString(5))) + .andExpect(status().isOk()); } @Test - public void getNameOfDayByNumberRequestParam_whenGetWithInvalidRequestParam_thenReturn400() throws Exception { - mockMvc.perform(get("/public/api/1/name-for-day").param("dayOfWeek", Integer.toString(5))).andExpect(status().isBadRequest()); + public void getNameOfDayByNumberRequestParam_whenGetWithRequestParamOutOfRange_thenReturn400() throws Exception { + mockMvc.perform(get("/public/api/1/name-for-day").param("dayOfWeek", Integer.toString(15))) + .andExpect(status().isBadRequest()); + } + + @Test + public void getNameOfDayByPathVariable_whenGetWithProperRequestParam_thenReturn200() throws Exception { + mockMvc.perform(get("/public/api/1/name-for-day/{dayOfWeek}", Integer.toString(5))).andExpect(status().isOk()); + } + + @Test + public void getNameOfDayByPathVariable_whenGetWithRequestParamOutOfRange_thenReturn400() throws Exception { + mockMvc.perform(get("/public/api/1/name-for-day/{dayOfWeek}", Integer.toString(15))) + .andExpect(status().isBadRequest()); + } + + @Test + public void validStringRequestParam_whenGetWithProperRequestParam_thenReturn200() throws Exception { + mockMvc.perform(get("/public/api/1/valid-name").param("name", "John")).andExpect(status().isOk()); + } + + @Test + public void validStringRequestParam_whenGetWithTooLongRequestParam_thenReturn400() throws Exception { + mockMvc.perform(get("/public/api/1/valid-name").param("name", "asdfghjklqw")) + .andExpect(status().isBadRequest()); + } + + @Test + public void validStringRequestParam_whenGetWithLowerCaseRequestParam_thenReturn400() throws Exception { + mockMvc.perform(get("/public/api/1/valid-name").param("name", "john")).andExpect(status().isBadRequest()); } }