Search in sources :

Example 1 with SourceDecoder

use of io.kroki.server.decode.SourceDecoder in project kroki by yuzutech.

the class DiagramHandlerTest method should_extract_options_as_query_params_from_get_request.

@Test
void should_extract_options_as_query_params_from_get_request() {
    DiagramService mockDiagramService = mockDiagramService(Lists.newArrayList(FileFormat.SVG), new SourceDecoder() {

        @Override
        public String decode(String encoded) throws DecodeException {
            return DiagramSource.decode(encoded);
        }
    });
    DiagramHandler diagramHandler = new DiagramHandler(mockDiagramService);
    MockDiagramRequest mockDiagramRequest = new MockDiagramRequest();
    MultiMap params = MultiMap.caseInsensitiveMultiMap();
    // /graphviz/svg/eNpLyUwvSizIUKhWSFTQtVNIUqgFADrsBaY=
    params.add("output_format", "svg");
    params.add("source_encoded", "eNpLyUwvSizIUKhWSFTQtVNIUqgFADrsBaY=");
    params.add("node-attribute-fontcolor", "Crimson");
    params.add("node-attribute-shape", "rect");
    params.add("layout", "neato");
    params.add("graph-attribute-fontcolor", "SteelBlue");
    params.add("graph-attribute-label", "Hello World");
    params.add("edge-attribute-color", "NavajoWhite");
    params.add("edge-attribute-arrowhead", "diamond");
    mockDiagramRequest.setParams(params);
    mockDiagramRequest.setHeaders(MultiMap.caseInsensitiveMultiMap());
    mockDiagramRequest.setMethod(HttpMethod.GET);
    RoutingContext routingContext = mockDiagramRequest.getRoutingContext();
    diagramHandler.createGet("graphviz").handle(routingContext);
    JsonObject options = new JsonObject();
    options.put("layout", "neato");
    options.put("edge-attribute-arrowhead", "diamond");
    options.put("graph-attribute-fontcolor", "SteelBlue");
    options.put("node-attribute-fontcolor", "Crimson");
    options.put("edge-attribute-color", "NavajoWhite");
    options.put("node-attribute-shape", "rect");
    options.put("graph-attribute-label", "Hello World");
    verify(mockDiagramService).convert(eq("digraph { a -> b }"), eq("graphviz"), eq(FileFormat.SVG), eq(options), any());
}
Also used : MultiMap(io.vertx.core.MultiMap) RoutingContext(io.vertx.ext.web.RoutingContext) SourceDecoder(io.kroki.server.decode.SourceDecoder) JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.kroki.server.error.DecodeException) Test(org.junit.jupiter.api.Test)

Example 2 with SourceDecoder

use of io.kroki.server.decode.SourceDecoder in project kroki by yuzutech.

the class DiagramHandlerTest method should_extract_options_as_headers_from_get_request.

@Test
void should_extract_options_as_headers_from_get_request() {
    DiagramService mockDiagramService = mockDiagramService(Lists.newArrayList(FileFormat.SVG), new SourceDecoder() {

        @Override
        public String decode(String encoded) throws DecodeException {
            return DiagramSource.decode(encoded);
        }
    });
    DiagramHandler diagramHandler = new DiagramHandler(mockDiagramService);
    MockDiagramRequest mockDiagramRequest = new MockDiagramRequest();
    MultiMap params = MultiMap.caseInsensitiveMultiMap();
    // /graphviz/svg/eNpLyUwvSizIUKhWSFTQtVNIUqgFADrsBaY=
    params.add("output_format", "svg");
    params.add("source_encoded", "eNpLyUwvSizIUKhWSFTQtVNIUqgFADrsBaY=");
    mockDiagramRequest.setParams(params);
    MultiMap headers = MultiMap.caseInsensitiveMultiMap();
    headers.add("kroki-diagram-options-node-attribute-fontcolor", "Crimson");
    headers.add("KROKI-DIAGRAM-OPTIONS-NODE-ATTRIBUTE-SHAPE", "rect");
    headers.add("KROKI-DIAGRAM-OPTIONS-layout", "neato");
    headers.add("KROKI-DIAGRAM-OPTIONS-GRAPH-ATTRIBUTE-FONTCOLOR", "SteelBlue");
    headers.add("kroki-diagram-options-graph-attribute-label", "Hello World");
    headers.add("kroki-diagram-options-EDGE-ATTRIBUTE-COLOR", "NavajoWhite");
    headers.add("Kroki-Diagram-Options-Edge-Attribute-ArrowHead", "diamond");
    mockDiagramRequest.setHeaders(headers);
    mockDiagramRequest.setMethod(HttpMethod.GET);
    RoutingContext routingContext = mockDiagramRequest.getRoutingContext();
    diagramHandler.createGet("graphviz").handle(routingContext);
    JsonObject options = new JsonObject();
    options.put("layout", "neato");
    options.put("edge-attribute-arrowhead", "diamond");
    options.put("graph-attribute-fontcolor", "SteelBlue");
    options.put("node-attribute-fontcolor", "Crimson");
    options.put("edge-attribute-color", "NavajoWhite");
    options.put("node-attribute-shape", "rect");
    options.put("graph-attribute-label", "Hello World");
    verify(mockDiagramService).convert(eq("digraph { a -> b }"), eq("graphviz"), eq(FileFormat.SVG), eq(options), any());
}
Also used : MultiMap(io.vertx.core.MultiMap) RoutingContext(io.vertx.ext.web.RoutingContext) SourceDecoder(io.kroki.server.decode.SourceDecoder) JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.kroki.server.error.DecodeException) Test(org.junit.jupiter.api.Test)

Example 3 with SourceDecoder

use of io.kroki.server.decode.SourceDecoder in project kroki by yuzutech.

the class DiagramHandlerTest method should_accept_get_request.

/**
 * Request:
 * <p>
 * POST /plantuml
 * Accept: image/svg+xml
 * Content-Type: text/plain
 * <p>
 * Bob -> Alice : hello
 */
@Test
void should_accept_get_request() {
    DiagramService mockDiagramService = mockDiagramService(Lists.newArrayList(FileFormat.SVG), new SourceDecoder() {

        @Override
        public String decode(String encoded) throws DecodeException {
            return DiagramSource.plantumlDecode(encoded);
        }
    });
    DiagramHandler diagramHandler = new DiagramHandler(mockDiagramService);
    MockDiagramRequest mockDiagramRequest = new MockDiagramRequest();
    mockDiagramRequest.setMethod(HttpMethod.GET);
    // /plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000
    mockDiagramRequest.addParam("output_format", "svg");
    mockDiagramRequest.addParam("source_encoded", "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000");
    RoutingContext routingContext = mockDiagramRequest.getRoutingContext();
    diagramHandler.createGet("plantuml").handle(routingContext);
    verify(mockDiagramService).convert(eq("@startuml\nBob -> Alice : hello\n@enduml"), eq("plantuml"), eq(FileFormat.SVG), any(), any());
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) SourceDecoder(io.kroki.server.decode.SourceDecoder) DecodeException(io.kroki.server.error.DecodeException) Test(org.junit.jupiter.api.Test)

Aggregations

SourceDecoder (io.kroki.server.decode.SourceDecoder)3 DecodeException (io.kroki.server.error.DecodeException)3 RoutingContext (io.vertx.ext.web.RoutingContext)3 Test (org.junit.jupiter.api.Test)3 MultiMap (io.vertx.core.MultiMap)2 JsonObject (io.vertx.core.json.JsonObject)2