Merge pull request #10904 from BhabaniPatel/master
Code commit for moving out package to specific name as per article
This commit is contained in:
commit
d5f1f148e3
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.maxhttpheadersize;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("com.baeldung.maxhttpheadersize")
|
||||
public class MaxHttpHeaderSizeApplication {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(MaxHttpHeaderSizeApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
package com.baeldung.sampleapp.config;
|
||||
package com.baeldung.maxhttpheadersize.config;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan({ "com.baeldung.sampleapp.web" })
|
||||
@EnableWebMvc
|
||||
@ComponentScan({ "com.baeldung.maxhttpheadersize.*" })
|
||||
public class MaxHTTPHeaderSizeConfig implements WebMvcConfigurer {
|
||||
|
||||
public MaxHTTPHeaderSizeConfig() {
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.sampleapp.web.controller;
|
||||
package com.baeldung.maxhttpheadersize.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
|
@ -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)
|
Loading…
Reference in New Issue