Skip to content

Commit 7fa5461

Browse files
committed
Use local mock server instead external ones
Signed-off-by: Matheus Cruz <[email protected]>
1 parent 1921a5e commit 7fa5461

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/AbstractRequestSupplier.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public WorkflowModel apply(
4040
Builder request, WorkflowContext workflow, TaskContext task, WorkflowModel model) {
4141
HttpModelConverter converter = HttpConverterResolver.converter(workflow, task);
4242

43+
if (!redirect) {
44+
request.property("jersey.config.client.followRedirects", false);
45+
}
46+
4347
Response response = invokeRequest(request, converter, workflow, task, model);
4448
validateStatus(task, response);
4549
return workflow

impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void testWrongSchema_should_throw_illegal_argument() {
367367
}
368368

369369
@Test
370-
void testHeadCall() {
370+
void testHeadCall() throws InterruptedException {
371371
mockServer.enqueue(
372372
new MockResponse(
373373
200,
@@ -380,6 +380,7 @@ void testHeadCall() {
380380
"X-Custom-Header",
381381
"CustomValue")),
382382
""));
383+
383384
assertDoesNotThrow(
384385
() -> {
385386
appl.workflowDefinition(
@@ -388,24 +389,33 @@ void testHeadCall() {
388389
.start()
389390
.join();
390391
});
392+
393+
RecordedRequest recordedRequest = mockServer.takeRequest();
394+
SoftAssertions.assertSoftly(
395+
softly -> {
396+
softly.assertThat(recordedRequest.getMethod()).isEqualTo("HEAD");
397+
softly.assertThat(recordedRequest.getUrl().toString()).contains("/users/1");
398+
});
391399
}
392400

393401
@Test
394-
void testOptionsCall() {
402+
void testOptionsCall() throws IOException, InterruptedException {
395403
mockServer.enqueue(new MockResponse(200, Headers.of("Allow", "GET, POST, OPTIONS"), ""));
404+
appl.workflowDefinition(readWorkflowFromClasspath("workflows-samples/call-http-options.yaml"))
405+
.instance(Map.of())
406+
.start()
407+
.join();
396408

397-
assertDoesNotThrow(
398-
() -> {
399-
appl.workflowDefinition(
400-
readWorkflowFromClasspath("workflows-samples/call-http-options.yaml"))
401-
.instance(Map.of())
402-
.start()
403-
.join();
409+
RecordedRequest recordedRequest = mockServer.takeRequest();
410+
SoftAssertions.assertSoftly(
411+
softly -> {
412+
softly.assertThat(recordedRequest.getMethod()).isEqualTo("OPTIONS");
413+
softly.assertThat(recordedRequest.getUrl().toString()).contains("/users/1");
404414
});
405415
}
406416

407417
@Test
408-
void testRedirectAsFalse() {
418+
void testRedirect_should_throws_when_redirect_is_false_and_response_status_is_not_2xx() {
409419
mockServer.enqueue(
410420
new MockResponse(301, Headers.of("Location", "http://localhost:9876/redirected"), ""));
411421

@@ -419,7 +429,6 @@ void testRedirectAsFalse() {
419429
.instance(Map.of())
420430
.start()
421431
.join());
422-
423432
assertThat(exception.getCause().getMessage())
424433
.contains(
425434
"The property 'redirect' is set to false but received status 301 (Redirection); expected status in the 200-299 range");

impl/test/src/test/resources/workflows-samples/call-http-delete.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ do:
99
with:
1010
method: delete
1111
endpoint:
12-
uri: https://localhost:9876/api/v1/authors/1
12+
uri: http://localhost:9876/api/v1/authors/1

0 commit comments

Comments
 (0)