11/*
2- * Copyright 2014-2018 the original author or authors.
2+ * Copyright 2014-2019 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3030import org .junit .Rule ;
3131import org .junit .Test ;
3232import com .github .tomakehurst .wiremock .core .Options ;
33+ import com .github .tomakehurst .wiremock .http .Fault ;
3334import com .github .tomakehurst .wiremock .junit .WireMockRule ;
3435
3536import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
3637import static com .github .tomakehurst .wiremock .client .WireMock .notFound ;
3738import static com .github .tomakehurst .wiremock .client .WireMock .ok ;
3839import static com .github .tomakehurst .wiremock .client .WireMock .options ;
40+ import static com .github .tomakehurst .wiremock .client .WireMock .serverError ;
3941import static com .github .tomakehurst .wiremock .client .WireMock .urlEqualTo ;
4042import static com .github .tomakehurst .wiremock .stubbing .Scenario .STARTED ;
4143import static org .assertj .core .api .Assertions .assertThatThrownBy ;
@@ -45,8 +47,8 @@ public class ProbeEndpointsStrategyTest {
4547 public WireMockRule wireMock = new WireMockRule (Options .DYNAMIC_PORT );
4648
4749 private InstanceWebClient instanceWebClient = InstanceWebClient .builder ()
48- .connectTimeout (Duration .ofSeconds (2 ))
49- .readTimeout (Duration .ofSeconds (2 ))
50+ .connectTimeout (Duration .ofSeconds (1 ))
51+ .readTimeout (Duration .ofSeconds (1 ))
5052 .defaultRetries (1 )
5153 .build ();
5254
@@ -62,48 +64,52 @@ public static void tearDown() {
6264
6365 @ Test
6466 public void invariants () {
65- assertThatThrownBy (() -> new ProbeEndpointsStrategy (instanceWebClient , null )).isInstanceOf (
67+ assertThatThrownBy (() -> new ProbeEndpointsStrategy (this . instanceWebClient , null )).isInstanceOf (
6668 IllegalArgumentException .class ).hasMessage ("'endpoints' must not be null." );
67- assertThatThrownBy (() -> new ProbeEndpointsStrategy (instanceWebClient , new String []{null })).isInstanceOf (
69+ assertThatThrownBy (() -> new ProbeEndpointsStrategy (this . instanceWebClient , new String []{null })).isInstanceOf (
6870 IllegalArgumentException .class ).hasMessage ("'endpoints' must not contain null." );
6971 }
7072
7173 @ Test
7274 public void should_return_detect_endpoints () {
7375 //given
7476 Instance instance = Instance .create (InstanceId .of ("id" ))
75- .register (Registration .create ("test" , wireMock .url ("/mgmt/health" ))
76- .managementUrl (wireMock .url ("/mgmt" ))
77+ .register (Registration .create ("test" , this . wireMock .url ("/mgmt/health" ))
78+ .managementUrl (this . wireMock .url ("/mgmt" ))
7779 .build ());
7880
79- wireMock .stubFor (options (urlEqualTo ("/mgmt/metrics" )).willReturn (ok ()));
80- wireMock .stubFor (options (urlEqualTo ("/mgmt/stats" )).willReturn (ok ()));
81- wireMock .stubFor (options (urlEqualTo ("/mgmt/info" )).willReturn (ok ()));
82- wireMock .stubFor (options (urlEqualTo ("/mgmt/non-exist" )).willReturn (notFound ()));
81+ this .wireMock .stubFor (options (urlEqualTo ("/mgmt/metrics" )).willReturn (ok ()));
82+ this .wireMock .stubFor (options (urlEqualTo ("/mgmt/stats" )).willReturn (ok ()));
83+ this .wireMock .stubFor (options (urlEqualTo ("/mgmt/info" )).willReturn (ok ()));
84+ this .wireMock .stubFor (options (urlEqualTo ("/mgmt/non-exist" )).willReturn (notFound ()));
85+ this .wireMock .stubFor (options (urlEqualTo ("/mgmt/error" )).willReturn (serverError ()));
86+ this .wireMock .stubFor (options (urlEqualTo ("/mgmt/exception" )).willReturn (aResponse ().withFault (Fault .EMPTY_RESPONSE )));
8387
84- ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy (instanceWebClient ,
85- new String []{"metrics:stats" , "metrics" , "info" , "non-exist" }
88+ ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy (this . instanceWebClient ,
89+ new String []{"metrics:stats" , "metrics" , "info" , "non-exist" , "error" , "exception" }
8690 );
8791
8892 //when
8993 StepVerifier .create (strategy .detectEndpoints (instance ))
9094 //then
91- .expectNext (Endpoints .single ("metrics" , wireMock .url ("/mgmt/stats" ))
92- .withEndpoint ("info" , wireMock .url ("/mgmt/info" )))//
95+ .expectNext (Endpoints .single ("metrics" , this . wireMock .url ("/mgmt/stats" ))
96+ .withEndpoint ("info" , this . wireMock .url ("/mgmt/info" )))//
9397 .verifyComplete ();
9498 }
9599
96100 @ Test
97101 public void should_return_empty () {
98102 //given
99103 Instance instance = Instance .create (InstanceId .of ("id" ))
100- .register (Registration .create ("test" , wireMock .url ("/mgmt/health" ))
101- .managementUrl (wireMock .url ("/mgmt" ))
104+ .register (Registration .create ("test" , this . wireMock .url ("/mgmt/health" ))
105+ .managementUrl (this . wireMock .url ("/mgmt" ))
102106 .build ());
103107
104- wireMock .stubFor (options (urlEqualTo ("/mgmt/stats" )).willReturn (aResponse ().withStatus (HttpStatus .NOT_FOUND_404 )));
108+ this . wireMock .stubFor (options (urlEqualTo ("/mgmt/stats" )).willReturn (aResponse ().withStatus (HttpStatus .NOT_FOUND_404 )));
105109
106- ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy (instanceWebClient , new String []{"metrics:stats" });
110+ ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy (this .instanceWebClient ,
111+ new String []{"metrics:stats" }
112+ );
107113
108114 //when
109115 StepVerifier .create (strategy .detectEndpoints (instance ))
@@ -115,31 +121,32 @@ public void should_return_empty() {
115121 public void should_retry () {
116122 //given
117123 Instance instance = Instance .create (InstanceId .of ("id" ))
118- .register (Registration .create ("test" , wireMock .url ("/mgmt/health" ))
119- .managementUrl (wireMock .url ("/mgmt" ))
124+ .register (Registration .create ("test" , this . wireMock .url ("/mgmt/health" ))
125+ .managementUrl (this . wireMock .url ("/mgmt" ))
120126 .build ());
121127
122- wireMock .stubFor (options (urlEqualTo ("/mgmt/metrics" )).inScenario ("retry" )
123- .whenScenarioStateIs (STARTED )
124- .willReturn (aResponse ().withFixedDelay (5000 ))
125- .willSetStateTo ("recovered" ));
128+ this . wireMock .stubFor (options (urlEqualTo ("/mgmt/metrics" )).inScenario ("retry" )
129+ .whenScenarioStateIs (STARTED )
130+ .willReturn (aResponse ().withFixedDelay (5000 ))
131+ .willSetStateTo ("recovered" ));
126132
127- wireMock .stubFor (options (urlEqualTo ("/mgmt/metrics" )).inScenario ("retry" )
128- .whenScenarioStateIs ("recovered" )
129- .willReturn (ok ()));
130- wireMock .stubFor (options (urlEqualTo ("/mgmt/stats" )).willReturn (ok ()));
131- wireMock .stubFor (options (urlEqualTo ("/mgmt/info" )).willReturn (ok ()));
132- wireMock .stubFor (options (urlEqualTo ("/mgmt/non-exist" )).willReturn (notFound ()));
133+ this . wireMock .stubFor (options (urlEqualTo ("/mgmt/metrics" )).inScenario ("retry" )
134+ .whenScenarioStateIs ("recovered" )
135+ .willReturn (ok ()));
136+ this . wireMock .stubFor (options (urlEqualTo ("/mgmt/stats" )).willReturn (ok ()));
137+ this . wireMock .stubFor (options (urlEqualTo ("/mgmt/info" )).willReturn (ok ()));
138+ this . wireMock .stubFor (options (urlEqualTo ("/mgmt/non-exist" )).willReturn (notFound ()));
133139
134- ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy (instanceWebClient ,
140+ ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy (
141+ this .instanceWebClient ,
135142 new String []{"metrics:stats" , "metrics" , "info" , "non-exist" }
136143 );
137144
138145 //when
139146 StepVerifier .create (strategy .detectEndpoints (instance ))
140147 //then
141- .expectNext (Endpoints .single ("metrics" , wireMock .url ("/mgmt/stats" ))
142- .withEndpoint ("info" , wireMock .url ("/mgmt/info" )))//
148+ .expectNext (Endpoints .single ("metrics" , this . wireMock .url ("/mgmt/stats" ))
149+ .withEndpoint ("info" , this . wireMock .url ("/mgmt/info" )))//
143150 .verifyComplete ();
144151 }
145152}
0 commit comments