Skip to content

Commit

Permalink
Merge pull request eugenp#10904 from BhabaniPatel/master
Browse files Browse the repository at this point in the history
Code commit for moving out package to specific name as per article
  • Loading branch information
JonCook authored Jun 15, 2021
2 parents 071dae8 + 35e5630 commit d5f1f14
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,10 +16,10 @@
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 {

Expand All @@ -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());
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.web.controller;
package com.baeldung.maxhttpheadersize.controller;

import java.io.BufferedReader;
import java.io.FileReader;
Expand All @@ -11,18 +11,13 @@
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)
Expand Down

0 comments on commit d5f1f14

Please sign in to comment.