@Test public void thatSequenceDiagramIsRead() { final String puml = "@startuml\n" + "title First Level Components\n" + "caption Level 1 Building Blocks\n" + "\n" + "legend right\n" + " | Element | Description |\n" + " |<#42788e>| Component |\n" + " | A --> B | A depends on B |\n" + "endlegend\n" + "\n" + "autonumber\n" + "participant de.kontext_e.spikes.trace_to_plantuml.application.Controller <<Controller>>\n" + "de.kontext_e.spikes.trace_to_plantuml.application.Controller -> de.kontext_e.spikes.trace_to_plantuml.application.Boundary : loadEntity([1])\n" + "de.kontext_e.spikes.trace_to_plantuml.application.Boundary -> de.kontext_e.spikes.trace_to_plantuml.application.Repository : readEntity([1])\n" + "de.kontext_e.spikes.trace_to_plantuml.application.Repository -> de.kontext_e.spikes.trace_to_plantuml.application.Boundary : throws(NoSuchEntityException{id=1})\n" + "de.kontext_e.spikes.trace_to_plantuml.application.Boundary -> de.kontext_e.spikes.trace_to_plantuml.application.Controller : return([LoadEntityResult{results=NO_RESULT}])\n" + "de.kontext_e.spikes.trace_to_plantuml.application.Controller -> de.kontext_e.spikes.trace_to_plantuml.application.LoadEntityResult : getResults([])\n" + "de.kontext_e.spikes.trace_to_plantuml.application.LoadEntityResult -> de.kontext_e.spikes.trace_to_plantuml.application.Controller : return([NO_RESULT])\n" + "@enduml"; String[] lines = puml.split("\\n"); pumlLineParser = new PumlLineParser(mockStore, plantUmlFileDescriptor, ParsingState.ACCEPTING); final PlantUmlSequenceDiagramDescriptor mockDescriptor = mock(PlantUmlSequenceDiagramDescriptor.class); when(mockStore.create(PlantUmlSequenceDiagramDescriptor.class)).thenReturn(mockDescriptor); final PlantUmlParticipantDescriptor participantDescriptor = mock(PlantUmlParticipantDescriptor.class); when(mockStore.create(PlantUmlParticipantDescriptor.class)).thenReturn(participantDescriptor); final PlantUmlSequenceDiagramMessageDescriptor messageDescriptor = mock(PlantUmlSequenceDiagramMessageDescriptor.class); when(mockStore.create(participantDescriptor, PlantUmlSequenceDiagramMessageDescriptor.class, participantDescriptor)).thenReturn(messageDescriptor); for (String line : lines) { pumlLineParser.parseLine(line); } verify(mockStore).create(PlantUmlSequenceDiagramDescriptor.class); verify(mockDescriptor).setType("SEQUENCEDIAGRAM"); verify(mockDescriptor).setTitle("first level components"); verify(mockDescriptor).setCaption("level 1 building blocks"); verify(mockDescriptor).setLegend("| element | description ||<#42788e>| component || a --> b | a depends on b |"); verify(participantDescriptor, times(4)).setType("PARTICIPANT"); verify(participantDescriptor).setName("de.kontext_e.spikes.trace_to_plantuml.application.controller"); verify(messageDescriptor).setMessage("[loadentity([1])]"); verify(messageDescriptor).setMessageNumber("<b>1</b>"); }
void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } }
PumlLineParser { void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } } }
PumlLineParser { void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } } PumlLineParser(final Store store, final PlantUmlFileDescriptor plantUmlFileDescriptor, final ParsingState parsingState); }
PumlLineParser { void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } } PumlLineParser(final Store store, final PlantUmlFileDescriptor plantUmlFileDescriptor, final ParsingState parsingState);  }
PumlLineParser { void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } } PumlLineParser(final Store store, final PlantUmlFileDescriptor plantUmlFileDescriptor, final ParsingState parsingState);   }