Skip to content

Commit 7b8f5d0

Browse files
authored
Examples: Orchestration Refactoring (#2686)
* feat(dispatcher): add production mode support for error handling and extend URI validation tests - Introduced `productionRouter` in `DummyTestRouter` to enable production mode configuration. - Updated `DispatchingInterceptor` to adjust error messages in production mode. - Expanded `DispatchingInterceptorTest` with production-specific URI validation. * refactor(tests): update test method names and improve flow structure in `CallAuthenticationExampleTest`
1 parent 337f81b commit 7b8f5d0

2 files changed

Lines changed: 40 additions & 30 deletions

File tree

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# yaml-language-server: $schema=https://www.membrane-api.io/v7.0.6.json
2+
#
23
# API on port 2000: fetch login cookie then proxy to backend
34
api:
45
port: 2000
56
flow:
67
- request:
7-
# Call auth service to obtain SESSION cookie
8+
- log:
9+
message: Calling login API
810
- call:
911
url: http://localhost:3000/login
12+
- log:
13+
message: "Got: ${header['set-cookie']}"
1014
# Inject received Set-Cookie header as Cookie
1115
- setHeader:
1216
name: Cookie
@@ -23,26 +27,32 @@ api:
2327
uri: /login
2428
flow:
2529
- response:
26-
# Return a static SESSION cookie
27-
- setHeader:
28-
name: Set-Cookie
29-
value: SESSION=akj34
30-
- return: {}
30+
# Return a static SESSION cookie
31+
- setHeader:
32+
name: Set-Cookie
33+
value: SESSION=akj34
34+
- log:
35+
message: Logged in. Cookie is set.
36+
- return:
37+
status: 200
3138

3239
---
3340
# Protected backend on port 3001
3441
api:
3542
port: 3001
3643
flow:
37-
# If correct SESSION cookie present, succeed
38-
- if:
39-
test: cookie.SESSION == 'akj34'
40-
flow:
41-
- static:
42-
src: Success!
43-
- return: {}
44-
# Otherwise, ask to log in with 401 status
45-
- static:
46-
src: Please log in!
44+
- request:
45+
- log:
46+
message: "Got: ${header['set-cookie']}"
47+
- if:
48+
test: cookie.SESSION != 'akj34'
49+
flow:
50+
- static:
51+
src: Unauthorized!
52+
- return:
53+
status: 401
54+
- response:
55+
- static:
56+
src: Success!
4757
- return:
48-
status: 401
58+
status: 200

distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/CallAuthenticationExampleTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
package com.predic8.membrane.examples.withoutinternet.test;
1616

17-
import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
18-
import org.junit.jupiter.api.Test;
17+
import com.predic8.membrane.examples.util.*;
18+
import org.junit.jupiter.api.*;
1919

20-
import static io.restassured.RestAssured.given;
20+
import static io.restassured.RestAssured.*;
2121
import static org.hamcrest.CoreMatchers.containsString;
2222

2323
public class CallAuthenticationExampleTest extends AbstractSampleMembraneStartStopTestcase {
@@ -28,34 +28,34 @@ protected String getExampleDirName() {
2828
}
2929

3030
@Test
31-
void testCall() {
31+
void authService() {
3232
// @formatter:off
3333
given().when()
34-
.get("http://localhost:2000")
34+
.get("http://localhost:3000/login")
3535
.then()
36-
.body(containsString("Success"))
36+
.header("Set-Cookie", "SESSION=akj34")
3737
.statusCode(200);
3838
// @formatter:on
3939
}
4040

4141
@Test
42-
void testAuthService() {
42+
void securedBackend() {
4343
// @formatter:off
4444
given().when()
45-
.get("http://localhost:3000/login")
45+
.get("http://localhost:3001")
4646
.then()
47-
.header("Set-Cookie", "SESSION=akj34")
48-
.statusCode(200);
47+
.statusCode(401);
4948
// @formatter:on
5049
}
5150

5251
@Test
53-
void testSecuredBackend() {
52+
void call() {
5453
// @formatter:off
5554
given().when()
56-
.get("http://localhost:3001")
55+
.get("http://localhost:2000")
5756
.then()
58-
.statusCode(401);
57+
.body(containsString("Success"))
58+
.statusCode(200);
5959
// @formatter:on
6060
}
6161
}

0 commit comments

Comments
 (0)