@Test public void thatEmbeddedPlantUMLInAsciidocIsRead2() { String[] lines = ("=== Level 1\n" + "\n" + "\n" + "The following diagram shows the main building blocks of the system and their interdependencies:\n" + "\n" + "[\"plantuml\",\"MainBuildingBlocks\",\"png\"]\n" + "-----\n" + "component Backend\n" + "component [Some UI]\n" + "\n" + "[Some UI] --> Backend\n" + "-----\n" + "\n" + "Comments regarding structure and interdependencies at Level 1:\n") .split("\\n"); pumlLineParser = new PumlLineParser(mockStore, plantUmlFileDescriptor, ParsingState.IGNORING); final PlantUmlDescriptionDiagramDescriptor mockDescriptionDiagramDescriptor = mock(PlantUmlDescriptionDiagramDescriptor.class); when(mockStore.create(PlantUmlDescriptionDiagramDescriptor.class)).thenReturn(mockDescriptionDiagramDescriptor); final PlantUmlLeafDescriptor mockPlantUmlLeafDescriptor = mock(PlantUmlLeafDescriptor.class); when(mockStore.create(PlantUmlLeafDescriptor.class)).thenReturn(mockPlantUmlLeafDescriptor); final Set<PlantUmlElement> leafs = new HashSet<>(); when(mockDescriptionDiagramDescriptor.getLeafs()).thenReturn(leafs); stream(lines).forEach(line -> pumlLineParser.parseLine(line)); verify(mockStore).create(PlantUmlDescriptionDiagramDescriptor.class); verify(mockStore, times(2)).create(PlantUmlLeafDescriptor.class); verify(mockPlantUmlLeafDescriptor, times(2)).setType("DESCRIPTION"); verify(mockPlantUmlLeafDescriptor, times(1)).setFullName("backend"); verify(mockPlantUmlLeafDescriptor, times(1)).setFullName("some ui"); verify(mockPlantUmlLeafDescriptor, times(1)).getLinkTargets(); assertEquals(1, leafs.size()); }
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);   }