2020import java .util .List ;
2121import java .util .Map ;
2222
23+ import feign .FeignException ;
2324import org .junit .jupiter .api .Test ;
2425
2526import org .springframework .beans .factory .annotation .Autowired ;
3536import org .springframework .context .annotation .Bean ;
3637import org .springframework .context .annotation .Import ;
3738import org .springframework .http .HttpHeaders ;
39+ import org .springframework .http .HttpStatus ;
40+ import org .springframework .http .ResponseEntity ;
3841import org .springframework .test .context .ActiveProfiles ;
3942import org .springframework .web .bind .annotation .GetMapping ;
4043import org .springframework .web .bind .annotation .RequestHeader ;
4447
4548import static java .util .Map .entry ;
4649import static org .assertj .core .api .Assertions .assertThat ;
50+ import static org .assertj .core .api .Assertions .assertThatCode ;
51+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
4752import static org .springframework .http .MediaType .APPLICATION_JSON_VALUE ;
4853
4954/**
5257 * @author Olga Maciaszek-Sharma
5358 */
5459@ SpringBootTest (classes = FeignClientFactoryBeanIntegrationTests .Application .class ,
55- webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
60+ webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
5661@ ActiveProfiles ("defaultstest" )
5762class FeignClientFactoryBeanIntegrationTests {
5863
@@ -64,51 +69,58 @@ class FeignClientFactoryBeanIntegrationTests {
6469
6570 @ Test
6671 void shouldProcessDefaultRequestHeadersPerClient () {
67- assertThat (testClientA .headers ()).isNotNull ()
68- .contains (entry ("x-custom-header-2" , List .of ("2 from default" )),
72+ assertThat (testClientA .headers ()).isNotNull ().contains (entry ("x-custom-header-2" , List .of ("2 from default" )),
6973 entry ("x-custom-header" , List .of ("from client A" )));
70- assertThat (testClientB .headers ()).isNotNull ()
71- .contains (entry ("x-custom-header-2" , List .of ("2 from default" )),
74+ assertThat (testClientB .headers ()).isNotNull ().contains (entry ("x-custom-header-2" , List .of ("2 from default" )),
7275 entry ("x-custom-header" , List .of ("from client B" )));
7376 }
7477
7578 @ Test
7679 void shouldProcessDefaultQueryParamsPerClient () {
77- assertThat (testClientA .params ()).isNotNull ()
78- .contains (entry ("customParam2" , "2 from default" ),
80+ assertThat (testClientA .params ()).isNotNull ().contains (entry ("customParam2" , "2 from default" ),
7981 entry ("customParam1" , "from client A" ));
80- assertThat (testClientB .params ()).isNotNull ()
81- .contains (entry ("customParam2" , "2 from default" ),
82+ assertThat (testClientB .params ()).isNotNull ().contains (entry ("customParam2" , "2 from default" ),
8283 entry ("customParam1" , "from client B" ));
8384 }
8485
86+ @ Test
87+ void shouldProcessDismiss404PerClient () {
88+ assertThatExceptionOfType (FeignException .FeignClientException .class ).isThrownBy (() -> testClientA .test404 ());
89+ assertThatCode (() -> {
90+ ResponseEntity <String > response404 = testClientB .test404 ();
91+ assertThat (response404 .getStatusCode ()).isEqualTo (HttpStatus .NOT_FOUND );
92+ assertThat (response404 .getBody ()).isNull ();
93+ }).doesNotThrowAnyException ();
94+ }
95+
8596 @ FeignClient ("testClientA" )
86- public interface TestClientA {
97+ public interface TestClientA extends TestClient {
8798
88- @ GetMapping ("/headers" )
89- Map <String , List <String >> headers ();
99+ }
90100
91- @ GetMapping ( "/params " )
92- Map < String , String > params ();
101+ @ FeignClient ( "testClientB " )
102+ public interface TestClientB extends TestClient {
93103
94104 }
95105
96- @ FeignClient ("testClientB" )
97- public interface TestClientB {
106+ public interface TestClient {
98107
99108 @ GetMapping ("/headers" )
100109 Map <String , List <String >> headers ();
101110
102111 @ GetMapping ("/params" )
103112 Map <String , String > params ();
104113
114+ @ GetMapping
115+ ResponseEntity <String > test404 ();
116+
105117 }
106118
107119 @ EnableAutoConfiguration
108- @ EnableFeignClients (clients = {TestClientA .class , TestClientB .class })
120+ @ EnableFeignClients (clients = { TestClientA .class , TestClientB .class })
109121 @ RestController
110- @ LoadBalancerClients ({@ LoadBalancerClient (name = "testClientA" , configuration = TestClientAConfiguration .class ),
111- @ LoadBalancerClient (name = "testClientB" , configuration = TestClientBConfiguration .class )})
122+ @ LoadBalancerClients ({ @ LoadBalancerClient (name = "testClientA" , configuration = TestClientAConfiguration .class ),
123+ @ LoadBalancerClient (name = "testClientB" , configuration = TestClientBConfiguration .class ) })
112124 @ RequestMapping
113125 @ Import (NoSecurityConfiguration .class )
114126 protected static class Application {
@@ -123,6 +135,11 @@ public Map<String, String> headersB(@RequestParam Map<String, String> params) {
123135 return params ;
124136 }
125137
138+ @ GetMapping
139+ ResponseEntity <String > test404 () {
140+ return ResponseEntity .notFound ().build ();
141+ }
142+
126143 }
127144
128145 // LoadBalancer with fixed server list for "testClientA" pointing to localhost
@@ -134,7 +151,7 @@ static class TestClientAConfiguration {
134151 @ Bean
135152 public ServiceInstanceListSupplier testClientAServiceInstanceListSupplier () {
136153 return ServiceInstanceListSuppliers .from ("testClientA" ,
137- new DefaultServiceInstance ("local-1" , "testClientA" , "localhost" , port , false ));
154+ new DefaultServiceInstance ("local-1" , "testClientA" , "localhost" , port , false ));
138155 }
139156
140157 }
@@ -148,7 +165,7 @@ static class TestClientBConfiguration {
148165 @ Bean
149166 public ServiceInstanceListSupplier testClientBServiceInstanceListSupplier () {
150167 return ServiceInstanceListSuppliers .from ("testClientB" ,
151- new DefaultServiceInstance ("local-1" , "testClientB" , "localhost" , port , false ));
168+ new DefaultServiceInstance ("local-1" , "testClientB" , "localhost" , port , false ));
152169 }
153170
154171 }
0 commit comments