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:

  • the name of the class where the sequence starts

  • the name of the method where the sequence starts
    (this name needs to be unique or a random method with the same name is chosen)

If you have done this, you can add the following list of parameters via builder methods:

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+", "")));
1 add start class as string
2 add start method as string
3 create generator object with config from builder
4 generate diagram text

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:

0001_basic_caller_test_diagram