Code commit for moving out package to specific name as per article

This commit is contained in:
Bhabani Prasad Patel
2021-06-14 08:34:16 +05:30
parent 44932b2cbe
commit 35e56303d3
5 changed files with 33 additions and 17 deletions
@@ -1,4 +1,4 @@
package com.baeldung.web.controller;
package com.baeldung.maxhttpheadersize.controller;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -16,10 +16,10 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import com.baeldung.sampleapp.config.WebConfig;
import com.baeldung.maxhttpheadersize.config.MaxHTTPHeaderSizeConfig;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = WebConfig.class)
@ContextConfiguration(classes = MaxHTTPHeaderSizeConfig.class)
@WebAppConfiguration
public class MaxHttpHeaderSizeControllerIntegrationTest {
@@ -30,19 +30,23 @@ public class MaxHttpHeaderSizeControllerIntegrationTest {
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.build();
}
@Test
public void givenTokenWithLessThan8KBLegth_whenSendGetRequest_thenReturnsOK() throws Exception {
mockMvc.perform(get("/request-header-test").contentType(MediaType.APPLICATION_JSON_VALUE)
.with(httpBasic("user", "password")).header("token", "token")).andExpect(status().isOk());
.with(httpBasic("user", "password"))
.header("token", "token"))
.andExpect(status().isOk());
}
@Test
public void givenTokenIsMissingInHeade_whenSendGetRequest_thenThrowsBadRequest() throws Exception {
public void givenTokenIsMissingInHeader_whenSendGetRequest_thenThrowsBadRequest() throws Exception {
mockMvc.perform(get("/request-header-test").contentType(MediaType.APPLICATION_JSON_VALUE)
.with(httpBasic("user", "password"))).andExpect(status().isBadRequest());
.with(httpBasic("user", "password")))
.andExpect(status().isBadRequest());
}
}
@@ -1,4 +1,4 @@
package com.baeldung.web.controller;
package com.baeldung.maxhttpheadersize.controller;
import java.io.BufferedReader;
import java.io.FileReader;
@@ -11,18 +11,13 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import com.baeldung.sampleapp.config.MaxHTTPHeaderSizeConfig;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MaxHTTPHeaderSizeConfig.class }, loader = AnnotationConfigContextLoader.class)
@ActiveProfiles("test")
// Start MaxHttpHeaderSizeController Spring Boot App(MainApplication) first
// Start MaxHttpHeaderSizeController Spring Boot App(MaxHttpHeaderSizeApplication) first
public class MaxHttpHeaderSizeControllerLiveTest {
@Test(expected = HttpClientErrorException.class)