Configuration
Configuration options
You have two basic options to configure the PlantUMLSequenceDiagramGenerator for diagram generation:
-
construct a PlantUMLSequenceDiagramConfig object on your own and pass it into the constructor of the generator (not recommended)
-
use the PlantUMLSequenceDiagramConfigBuilder to build the configuration object and pass it into the constructor of the generator (recommended)
The first approach to fill all configuration data in an object of type PlantUMLSequenceDiagramConfig and pass it into the PlantUMLSequenceDiagramGenerator constructor is supported but should not be used, as it is not so readable and more errorprone than the third option via the PlantUMLSequenceDiagramConfigBuilder class and therefore this option is the recommended one.
Builder customization
If you construct a PlantUMLSequenceDiagramConfigBuilder - as recommended - , you need to pass to mandatory parameters to it:
If you have done this, you can add the following list of parameters via builder methods:
-
class blacklist regular expression
to filter out the classes being part of the diagram -
classloader
to specify the classloader to search for the classes -
hide method name
to hide the names of the called methods in the diagram -
hide super class
to show the method call as part of the child class instead of the super class -
ignore JPA entities
to remove all calls to a JPA entity from the sequence flow -
ignore standard classes
to remove all calls to a standard classes (every package starting with java.*) from the diagram -
method blacklist regular expression
to filter out calls to methods in the sequence flow -
show return types
to show the type of the return types in the diagram -
use short class names
to use only the class name itself without the package name
After you configured everything you can construct the PlantUMLSequenceDiagramConfig object via the build() method and pass this configuration as parameter to the PlantUMLSequenceDiagramGenerator and create the diagram text.
Builder usage example
Here is a simple example for the usage of the PlantUMLSequenceDiagramConfigBuilder with the two mandatory parameters (startClass, startMethod) retrieved from the JUnit tests:
// ARRANGE
PlantUMLSequenceDiagramConfigBuilder builder = new PlantUMLSequenceDiagramConfigBuilder(CallerA.class.getName(), (1)
"callSomething"); (2)
PlantUMLSequenceDiagramGenerator generator = new PlantUMLSequenceDiagramGenerator(builder.build()); (3)
String expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource("sequence/0001_basic_caller_test.txt")),
StandardCharsets.UTF_8);
// ACT
String generatedDiagram = generator.generateDiagramText(); (4)
// ASSERT
assertAll(() -> assertNotNull(generatedDiagram), () -> assertEquals(expectedDiagramText.replaceAll("\\s+", ""),
generatedDiagram.replaceAll("\\s+", "")));
the result of this generation is
@startuml
participant CallerA
participant CallerB
activate CallerA
CallerA -> CallerB : callSomething
activate CallerB
CallerB -> CallerB : privateMethodCall
activate CallerB
CallerB --> CallerB
deactivate CallerB
CallerB -> CallerB : protectedMethodCall
activate CallerB
CallerB --> CallerB
deactivate CallerB
CallerB --> CallerA
deactivate CallerB
CallerA -> CallerB : callSomethingElse
activate CallerB
CallerB --> CallerA
deactivate CallerB
deactivate CallerA
@enduml
which is rendered in PlantUML this way: