From 35e56303d34dbedaa1f051b54a8dce5ef00f5002 Mon Sep 17 00:00:00 2001 From: Bhabani Prasad Patel Date: Mon, 14 Jun 2021 08:34:16 +0530 Subject: [PATCH] Code commit for moving out package to specific name as per article --- .../MaxHttpHeaderSizeApplication.java | 15 +++++++++++++++ .../config/MaxHTTPHeaderSizeConfig.java | 6 ++++-- .../MaxHttpHeaderSizeController.java | 2 +- ...ttpHeaderSizeControllerIntegrationTest.java | 18 +++++++++++------- .../MaxHttpHeaderSizeControllerLiveTest.java | 9 ++------- 5 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java rename spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/{sampleapp => maxhttpheadersize}/config/MaxHTTPHeaderSizeConfig.java (64%) rename spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/{sampleapp/web => maxhttpheadersize}/controller/MaxHttpHeaderSizeController.java (90%) rename spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/{web => maxhttpheadersize}/controller/MaxHttpHeaderSizeControllerIntegrationTest.java (73%) rename spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/{web => maxhttpheadersize}/controller/MaxHttpHeaderSizeControllerLiveTest.java (81%) diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java new file mode 100644 index 0000000000..ab8c52687b --- /dev/null +++ b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java @@ -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); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/sampleapp/config/MaxHTTPHeaderSizeConfig.java b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java similarity index 64% rename from spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/sampleapp/config/MaxHTTPHeaderSizeConfig.java rename to spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java index 0a71f914db..3f500e0074 100644 --- a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/sampleapp/config/MaxHTTPHeaderSizeConfig.java +++ b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java @@ -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() { diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/sampleapp/web/controller/MaxHttpHeaderSizeController.java b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeController.java similarity index 90% rename from spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/sampleapp/web/controller/MaxHttpHeaderSizeController.java rename to spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeController.java index 0c55f88fa1..89444c7875 100644 --- a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/sampleapp/web/controller/MaxHttpHeaderSizeController.java +++ b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeController.java @@ -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; diff --git a/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/web/controller/MaxHttpHeaderSizeControllerIntegrationTest.java b/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerIntegrationTest.java similarity index 73% rename from spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/web/controller/MaxHttpHeaderSizeControllerIntegrationTest.java rename to spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerIntegrationTest.java index 9b839f34a0..dd824491a0 100644 --- a/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/web/controller/MaxHttpHeaderSizeControllerIntegrationTest.java +++ b/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerIntegrationTest.java @@ -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()); } } diff --git a/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/web/controller/MaxHttpHeaderSizeControllerLiveTest.java b/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerLiveTest.java similarity index 81% rename from spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/web/controller/MaxHttpHeaderSizeControllerLiveTest.java rename to spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerLiveTest.java index 9c7e7c9029..2178be288d 100644 --- a/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/web/controller/MaxHttpHeaderSizeControllerLiveTest.java +++ b/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerLiveTest.java @@ -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)