Skip to content

Commit

Permalink
docs: advanced concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Nov 13, 2023
1 parent a0ca1c6 commit 61a09f3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions simulator-docs/src/main/asciidoc/concepts-advanced.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[[concepts-advanced]]
= Advanced Concepts

[[concept-advanced-database-schema]]
== Database Schema

In some cases, it may be useful to keep the database schema in mind.
The following diagram illustrates the database schema as defined in the package `org.citrusframework.simulator.model`, which should be considered the source of truth.
This visual representation can help understand the relationships and structure of the database entities.

image::database-schema.png[Database Schema, title="Database Schema of the Citrus Simulator"]

[[concept-runtime-scenario-registration]]
== Registering Simulator Scenarios at Runtime

Registering simulator scenarios at runtime is a perfectly valid approach.
However, it's crucial to ensure that the scenario cache used by the simulator remains synchronized.

A "Scenario" in this context is not a database entity but rather a conceptual object that exists only during runtime.
Essentially, these are simply Spring beans.
The `ScenarioLookupService` is responsible for tracking these scenarios but cannot do so automatically.
Therefore, after making modifications, it's necessary to call `ScenarioLookupService#evictAndReloadScenarioCache()` to update the cache.

The following Java source code illustrates how to register a custom scenario and update the scenario cache:

[source,java]
----
import org.citrusframework.simulator.service.ScenarioLookupService;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyCustomBeanConfiguration {
public MyCustomBeanConfiguration(ApplicationContext applicationContext, ScenarioLookupService scenarioLookupService) {
// Replace 'MyCustomSimulatorScenario' with your custom scenario class
SimulatorScenario simulatorScenario = new MyCustomSimulatorScenario();
ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
beanFactory.registerSingleton(simulatorScenario.getClass().getSimpleName(), simulatorScenario);
scenarioLookupService.evictAndReloadScenarioCache();
}
}
----
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
1 change: 1 addition & 0 deletions simulator-docs/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ifdef::basebackend-html[toc::[]]
include::introduction.adoc[]
include::installation.adoc[]
include::concepts.adoc[]
include::concepts-advanced.adoc[]

include::rest-support.adoc[]
include::ws-support.adoc[]
Expand Down

0 comments on commit 61a09f3

Please sign in to comment.