Add Apimposter container to mock out backend APIs
This commit is contained in:
parent
449dcafb5a
commit
896e78679d
bff
@ -11,4 +11,8 @@ The application will be available at http://localhost:8080 and tracing telemetry
|
||||
If running via some other means start the containers with `docker compose up`.
|
||||
Make sure you're using the correct JVM arguments (`--enable-preview`).
|
||||
Optionally add `-javaagent:opentelemetry-javaagent.jar -Dotel.javaagent.configuration-file=opentelemetry-javaagent.properties`
|
||||
to enable OpenTelemetry tracing.
|
||||
to enable OpenTelemetry tracing.
|
||||
|
||||
## Mocking backend APIs
|
||||
[Apimposter](https://gitea.dsv.su.se/DMC/apimposter) is used to mock the backend APIs.
|
||||
The mock data is defined in `src/mock-api`. See the linked documentation for details on how to define the mock data.
|
||||
|
@ -7,3 +7,13 @@ services:
|
||||
ports:
|
||||
- "4318:4318" # OpenTelemetry Collector
|
||||
- "16686:16686" # Jaeger UI
|
||||
mock-apis:
|
||||
build: https://gitea.dsv.su.se/DMC/apimposter.git
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- '63163:8080'
|
||||
environment:
|
||||
MOCK_BASE_PATH: / # HTTP base path for the mock server
|
||||
MOCK_FILE_PATH: /mocks
|
||||
volumes:
|
||||
- ./src/mock-api:/mocks
|
||||
|
@ -0,0 +1,7 @@
|
||||
package se.su.dsv.studentportalen.bff;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties("se.su.dsv.backend-api")
|
||||
public record BackendApiConfiguration(String daisyUrl) {
|
||||
}
|
@ -2,9 +2,13 @@ package se.su.dsv.studentportalen.bff;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableConfigurationProperties
|
||||
@ConfigurationPropertiesScan
|
||||
public class Studentportalen extends SpringBootServletInitializer {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Studentportalen.class, args);
|
||||
|
@ -16,8 +16,10 @@ import java.util.concurrent.StructuredTaskScope.Subtask;
|
||||
public class TestController {
|
||||
|
||||
private final RestClient restClient;
|
||||
private final BackendApiConfiguration backendApiConfiguration;
|
||||
|
||||
public TestController() {
|
||||
public TestController(final BackendApiConfiguration backendApiConfiguration) {
|
||||
this.backendApiConfiguration = backendApiConfiguration;
|
||||
this.restClient = RestClient.builder()
|
||||
.baseUrl("http://localhost:8080")
|
||||
.build();
|
||||
@ -43,6 +45,15 @@ public class TestController {
|
||||
return email;
|
||||
});
|
||||
|
||||
Subtask<DaisyProfile> daisyProfile = scope.fork(() -> {
|
||||
DaisyProfile profile = restClient.get()
|
||||
.uri(backendApiConfiguration.daisyUrl(), builder -> builder
|
||||
.path("/profile")
|
||||
.build())
|
||||
.retrieve()
|
||||
.body(DaisyProfile.class);
|
||||
return profile;
|
||||
});
|
||||
|
||||
// Wait for all tasks to complete (either success or failure)
|
||||
scope.join();
|
||||
@ -50,9 +61,10 @@ public class TestController {
|
||||
// Error if any task failed (or check each individual subtask for partial responses)
|
||||
scope.throwIfFailed();
|
||||
|
||||
return "Hello, I am %s and my email is %s.".formatted(
|
||||
return "Hello, I am %s and my email is %s. My Daisy profile is: %s".formatted(
|
||||
nameTask.get(),
|
||||
emailTask.get());
|
||||
emailTask.get(),
|
||||
daisyProfile.get());
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,4 +79,6 @@ public class TestController {
|
||||
Thread.sleep(Duration.ofSeconds(3));
|
||||
return "greg@localhost";
|
||||
}
|
||||
|
||||
record DaisyProfile(String name, String mail) {}
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
se:
|
||||
su:
|
||||
dsv:
|
||||
backend-api:
|
||||
daisy-url: http://localhost:63163/daisy
|
10
bff/src/mock-api/daisy/profile.yaml
Normal file
10
bff/src/mock-api/daisy/profile.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
- method: "GET"
|
||||
path: "/"
|
||||
delay: 200
|
||||
response:
|
||||
status: 200
|
||||
headers:
|
||||
Content-Type: "application/json"
|
||||
body:
|
||||
name: "Gregorious the Glorious"
|
||||
mail: "greg_da_great@localhost"
|
Loading…
x
Reference in New Issue
Block a user