Git Product home page Git Product logo

lsd-core's Introduction

semantic-release CI Nightly Build GitHub release Maven Central

LSD Core

A tool for creating sequence diagrams dynamically without needing to worry about markup.

This library generates html reports and each report contains one or more scenarios of captured events to be displayed on a sequence diagram.

(Additionally a component diagram is generated to show relationships).

LSD_example

Usage

  • Add dependency for version: Maven Central

    Maven
      <dependency>
          <groupId>io.github.lsd-consulting</groupId>
          <artifactId>lsd-core</artifactId>
          <version>X.X.X</version>
      </dependency>
    Gradle
        implementation 'io.github.lsd-consulting:lsd-core:X.X.X'
  • User lsd context singleton to capture messages (and other events):

Kotlin:

fun main() {
  val lsd = LsdContext.instance

  lsd.capture(
    MessageBuilder.messageBuilder().from("A").to("B").label("message1").build(),
    MessageBuilder.messageBuilder().from("B").to("A").label("message2").build(),
  )
  lsd.completeScenario("<Scenario Title>")
  lsd.completeReport("<Report Title>")
}

Java:

  public static void main(String[] args) {
      LsdContext lsd = LsdContext.getInstance();
      
      lsd.capture(
          MessageBuilder.messageBuilder().from("A").to("B").label("message1").build(),
          MessageBuilder.messageBuilder().from("B").to("A").label("message2").build()
      );
      lsd.completeScenario("<Scenario Title>", "<description>");
      lsd.completeReport("<Report Title>");
  }

Participants

Instead of using a String to specify a participant you can create a Participant type. This give you more options, e.g. to provide an alias , colour and type. So instead of "A" which will produce a default type of PARTICIPANT in the examples above you could use:

ACTOR.called("A", "Arnie", "blue") which will create a stickman labelled as "Arnie" and will be coloured in red.

ParticipantTypes include:

  • ACTOR
  • BOUNDARY
  • COLLECTIONS
  • CONTROL
  • DATABASE
  • ENTITY
  • PARTICIPANT
  • QUEUE

You can define participants upfront and register them using the lsd context, e.g.

    lsd.addParticipants(listOf(arnie, donnie))

The participants specified here will override any other participants with the same name so if you want to ensure colours or aliases are not overridden set them here before creating a report.


SequenceEvents

There are other event types that can be captured, other than messages.

  • PageTitle - Sets a title on the diagram
  • NoteLeft - Create a note (can be to the left of a provided participant)
  • NoteRight - Similar to NoteLeft but on the right
  • NoteOver - Create a note in the middle of a participant lifeline
  • TimeDelay - Shows that a period of time has elapsed (optional label can be provided)
  • Newpage - Splits a diagram into a new page at the point this event was captured
  • ActivateLifeline - Activates a participant lifeline (colour can be provided)
  • DeactivateLifeline - Deactivates a lifeline that has been activated

Additional options

  • A html index file can be generated if multiple reports are captured:

        lsd.createIndex()
  • Generate a component diagram for events included from multiple scenarios and reports

        lsd.completeComponentsReport("Relationships")
  • To draw attention to some interesting details you can include facts e.g.

        // instances of the keyword Lorem will be highlighted on the report
        lsd.addFact("Something to highlight", "Lorem")
  • Advanced users may want to include additional files for additional icons etc. For example to include a heart icon on a note:

          lsd.includeFiles(listOf("tupadr3/font-awesome-5/heart"))
    
          lsd.capture(NoteLeft("Friends <$heart{scale=0.4,color=red}>"))

Properties

The following properties can be overridden by adding a properties file called lsd.properties on the classpath of your application or by setting a System property. Note that System properties override file properties.

Property Name Default Description
lsd.core.label.maxWidth 200 The width in number of characters for the labels that appear on the diagrams before being abbreviated.
lsd.core.diagram.theme plain The plantUml theme to apply to the diagrams. See the available themes.
lsd.core.report.outputDir build/reports/lsd The directory to write the report files. (This can be a relative path).
lsd.core.ids.deterministic false Determines how the html element ids are generated. Allowing deterministic ids is useful when testing (e.g. approval tests of html output since the generated ids won't be random. The default option which provides random ids should be preferred otherwise.
lsd.core.diagram.sequence.maxEventsPerDiagram 50 To help make really large diagrams easier to read this value is used to decide when to split a potentially large diagram into sub-diagrams. (Each sub diagram will remove any unused participants and include the participant headers and footers).
lsd.core.devMode true Offline mode with inline css and js. Helps development when amending css and js but can also be useful when runninng in environments without internet connectivity
lsd.core.metrics.enabled false Experimental feature to show a table of metrics on the report (e.g. top bottlenecks, time to generate the report etc.)

Gallery

LSD Reports with metrics enabled LSD report example Popups contain additional data. They open when the arrows are clicked Popup example
Components Reports contain a component diagram of all participants from all reports and scenarios that were captured prior to generating the components report via completeComponentsReport() components report example Index pages contain links to all reports that were generated prior to the index page being rendered index page example

Related Libraries

A few related libraries exist to automate some of the steps to capture scenarios and generate reports e.g. via JUnit or Cucumber as plugins or extentions to the libraries.

Building

Prerequisites

  • Java 17 JDK

Git hooks

Git hooks will be configured automatically (to use the hooks in .githooks directory when the gradle clean task is invoked).

Build

./gradlew clean build

Troubleshooting

Static files stale

Since the static css and javascript files are cached on JSDelivr CDN it will occasionally be useful to force clear the cache to avoid waiting for several days (I think it's up to 7 days). Use this tool to clear the cache and specify these files:

Note that the browser cache may also need to be cleared since the browser will also cache css and js files if they have the same url

lsd-core's People

Contributors

dependabot[bot] avatar lukasz-gryzbon avatar nickmcdowall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bonified080

lsd-core's Issues

Automate image/giphy creation of example report

  • Use a tool to take a screenshot or create a giphy of an example report so that the README can stay up to date without too much manual effort.
  • This could be done per release perhaps - maybe github actions could be used

Highlight facts

  • When a provided fact value matches values in the popups or labels we can emphasise those words.

Add additional SequenceEvent types

For convenience extra sequence diagram event types can be created.

Some ideas:

  • Note to the right
  • Time-delay
  • Short inbound arrow
  • Short outbound arrow
  • Arrow from Beginning
  • Arrow to end
  • Start group/End group (perhaps a group object could encapsulate other events to auto close etc.)

Add contents section to report page

  • Each report should have a contents sections with hyperlinks to each scenario to allow for easy navigation to different parts of the report.

Add optional component diagram

If the user contains Graphviz/Dot on their system they can get a Component diagram along with the sequence diagram.

Perhaps this could be disabled via property if the user wants/needs to disable the extra diagram.

Look at using smetana as an alternative to requiring the graphviz (dot) binary for component diagrams

To avoid requiring the user to install Graphviz the following could be applied to the component diagrams:

!pragma layout smetana

The advantage being that this should work out the box without the need to additional tools to be installed on the client's machine.

Possible downsides - the smetana implementation is a port of the graphviz dot functionality so won't be as rich and may contain some bugs but since we only use a tiny bit of the library for layout if could be a good option.

Add ability to split sequence diagram every x number of interactions

To help make viewing larger diagrams easier (where it is hard to see the participants because they may be off the screen) it would be useful to split the diagram into new pages.

  • Add property to specify how many interactions before a newpage is issued for the diagram
  • Set a sensible default value

Fix component diagram markup

  • The participant names are being altered incorrectly when there is no spaces e.g. OneTwoThree is being converted to Onetwothree which no longer matches the actual participant names.

Allow colours for sequence events

  • Add option to colour a sequence event
    This could be useful for highlighting failures, warnings or colour coordinating a group of related events (e.g. from same thread of execution or http trace Ids etc.)

Make popup scrollable

  • Large texts such as stacktraces don't scroll making it difficult to view the full value

Fix squashed up Component diagrams

When no participant type is specified for several participants the generated component diagram uses a strange default type which is usually very small and bunches up the text (names) of the participants and becomes unreadable.

One solution is to default to component type in the component diagrams if none is provided.

Read system properties

To enable consistent passing of properties from plugins to the core, we should consider including the system properties in properties read/loaded by default.

Extract styling to separate file

  • Reference a local css file instead now that the file is getting big
  • Share the file with the Index page to keep the styles in sync.

Index page links should highlight failed and aborted tests

  • Include colour coding that matches the reports for errors, warnings and success reports
  • If any of the scenarios contain an error mark the report hyperlink with an error class or if any contain a warning then mark the hyperlink with a warning class otherwise we can use a success class.

Fix "squashed" sequence diagrams

When the page is resized or the image is too wide the diagrams can be caused to disappear off the left hand size of the screen.

Instead the image should be allowed to scroll so that no part of the image is unviewable.

Accept string pattern for sequence events

  • Sometimes it's easier to use simple string patterns instead of builders, e.g.

sending a message from A to B could be parsed using regex to create a message event (along with a second argument to capture the popup data (and possibly a third for colour once that's implemented).

Set expected order of precedence for properties

System properties should take precedence over the lsd.properties file values. The lsd.properties values should take precedence over the default properties.

Loading them in this order should result in the above order of precedence being true.

  1. Default values
  2. Properties File values
  3. System Property values

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.