4747
4848@ ExtendWith (SpringExtension .class )
4949@ ContextConfiguration (classes = {
50- GetCacheHandler .class ,
51- PrebidServerResponseBuilder .class ,
52- CacheConfig .class ,
53- CacheConfig .class ,
54- MetricsRecorderTest .class ,
55- MetricsRecorder .class ,
56- ApiConfig .class ,
57- CircuitBreakerPropertyConfiguration .class
50+ GetCacheHandler .class ,
51+ PrebidServerResponseBuilder .class ,
52+ CacheConfig .class ,
53+ CacheConfig .class ,
54+ MetricsRecorderTest .class ,
55+ MetricsRecorder .class ,
56+ ApiConfig .class ,
57+ CircuitBreakerPropertyConfiguration .class
5858})
5959@ EnableConfigurationProperties
6060@ SpringBootTest
@@ -110,18 +110,14 @@ void testVerifyError() {
110110 verifyRepositoryError (handler );
111111 }
112112
113- private static Consumer <ServerResponse > assertNotFoundStatusCode () {
114- return response -> assertEquals (response .statusCode ().value (), 404 );
115- }
116-
117113 @ Test
118114 void testVerifyFetch () {
119115 given (repository .findById ("prebid_a8db2208-d085-444c-9721-c1161d7f09ce" )).willReturn (Mono .just (PAYLOAD_WRAPPER ));
120116
121117 final var requestMono = MockServerRequest .builder ()
122- .method (HttpMethod .GET )
123- .queryParam ("uuid" , "a8db2208-d085-444c-9721-c1161d7f09ce" )
124- .build ();
118+ .method (HttpMethod .GET )
119+ .queryParam ("uuid" , "a8db2208-d085-444c-9721-c1161d7f09ce" )
120+ .build ();
125121
126122 final var responseMono = handler .fetch (requestMono );
127123
@@ -142,18 +138,18 @@ void testVerifyFetchWithCacheHostParam() {
142138 final var requestMono = MockServerRequest .builder ()
143139 .method (HttpMethod .GET )
144140 .header (CONTENT_TYPE , MediaType .APPLICATION_JSON_UTF8_VALUE )
145- .queryParam ("uuid" , "a8db2208-d085-444c-9721-c1161d7f09ce" )
146- .queryParam ("ch" , "localhost:8080" )
147- .build ();
141+ .queryParam ("uuid" , "a8db2208-d085-444c-9721-c1161d7f09ce" )
142+ .queryParam ("ch" , "localhost:8080" )
143+ .build ();
148144
149145 final var responseMono = handler .fetch (requestMono );
150146 responseMono .doOnEach (assertSignalStatusCode (200 )).subscribe ();
151147
152148 StepVerifier .create (responseMono )
153- .expectSubscription ()
154- .expectNextMatches (t -> true )
155- .expectComplete ()
156- .verify ();
149+ .expectSubscription ()
150+ .expectNextMatches (t -> true )
151+ .expectComplete ()
152+ .verify ();
157153
158154 verify (getRequestedFor (urlPathEqualTo ("/cache" ))
159155 .withQueryParam ("uuid" , equalTo ("a8db2208-d085-444c-9721-c1161d7f09ce" ))
@@ -164,34 +160,34 @@ void testVerifyFetchWithCacheHostParam() {
164160 @ Test
165161 void testVerifyFailForNotFoundResourceWithCacheHostParam () {
166162 final var requestMono = MockServerRequest .builder ()
167- .method (HttpMethod .GET )
168- .queryParam ("uuid" , "a8db2208-d085-444c-9721-c1161d7f09ce" )
169- .queryParam ("ch" , "localhost:8080" )
170- .build ();
163+ .method (HttpMethod .GET )
164+ .queryParam ("uuid" , "a8db2208-d085-444c-9721-c1161d7f09ce" )
165+ .queryParam ("ch" , "localhost:8080" )
166+ .build ();
171167
172168 final var responseMono = handler .fetch (requestMono );
173169
174170 responseMono .doOnEach (assertSignalStatusCode (404 )).subscribe ();
175171 StepVerifier .create (responseMono )
176172 .consumeNextWith (assertNotFoundStatusCode ())
177- .expectComplete ()
178- .verify ();
173+ .expectComplete ()
174+ .verify ();
179175 }
180176
181177 @ Test
182178 void testVerifyFetchReturnsBadRequestWhenResponseStatusIsNotOk () {
183179
184180 serverMock .stubFor (get (urlPathEqualTo ("/cache" ))
185- .willReturn (aResponse ().withHeader (HttpHeaders .CONTENT_TYPE , "application/json;charset=utf-8" )
186- .withStatus (201 )
187- .withBody ("{\" uuid\" :\" 2be04ba5-8f9b-4a1e-8100-d573c40312f8\" }" )));
181+ .willReturn (aResponse ().withHeader (HttpHeaders .CONTENT_TYPE , "application/json;charset=utf-8" )
182+ .withStatus (201 )
183+ .withBody ("{\" uuid\" :\" 2be04ba5-8f9b-4a1e-8100-d573c40312f8\" }" )));
188184
189185 final var requestMono = MockServerRequest .builder ()
190186 .method (HttpMethod .GET )
191187 .header (CONTENT_TYPE , MediaType .APPLICATION_JSON_UTF8_VALUE )
192- .queryParam ("uuid" , "a8db2208-d085-444c-9721-c1161d7f09ce" )
193- .queryParam ("ch" , "localhost:8080" )
194- .build ();
188+ .queryParam ("uuid" , "a8db2208-d085-444c-9721-c1161d7f09ce" )
189+ .queryParam ("ch" , "localhost:8080" )
190+ .build ();
195191
196192 final var responseMono = handler .fetch (requestMono );
197193
@@ -208,10 +204,49 @@ void testVerifyFetchReturnsBadRequestWhenResponseStatusIsNotOk() {
208204 );
209205 }
210206
207+ @ Test
208+ void testVerifyFetchReturnsBadRequestWhenNoUuid () {
209+ final var requestMono = MockServerRequest .builder ()
210+ .method (HttpMethod .GET )
211+ .header (CONTENT_TYPE , MediaType .APPLICATION_JSON_UTF8_VALUE )
212+ .build ();
213+
214+ final var responseMono = handler .fetch (requestMono );
215+
216+ StepVerifier .create (responseMono )
217+ .consumeNextWith (assertBadRequestStatusCode ())
218+ .expectComplete ()
219+ .verify ();
220+ }
221+
222+ @ Test
223+ void testVerifyFetchReturnsBadRequestWhenUuidIsEmpty () {
224+ final var requestMono = MockServerRequest .builder ()
225+ .method (HttpMethod .GET )
226+ .header (CONTENT_TYPE , MediaType .APPLICATION_JSON_UTF8_VALUE )
227+ .queryParam ("uuid" , "" )
228+ .build ();
229+
230+ final var responseMono = handler .fetch (requestMono );
231+
232+ StepVerifier .create (responseMono )
233+ .consumeNextWith (assertBadRequestStatusCode ())
234+ .expectComplete ()
235+ .verify ();
236+ }
237+
211238 private static Consumer <Signal <ServerResponse >> assertSignalStatusCode (int statusCode ) {
212239 return signal -> {
213240 assertTrue (signal .isOnComplete ());
214241 assertEquals (signal .get ().statusCode ().value (), statusCode );
215242 };
216243 }
244+
245+ private static Consumer <ServerResponse > assertNotFoundStatusCode () {
246+ return response -> assertEquals (response .statusCode ().value (), 404 );
247+ }
248+
249+ private static Consumer <ServerResponse > assertBadRequestStatusCode () {
250+ return response -> assertEquals (response .statusCode ().value (), 400 );
251+ }
217252}
0 commit comments