From ee1b1c4bfa207faa232419e64b2778d6aab6a0ee Mon Sep 17 00:00:00 2001
From: eson <474420502@qq.com>
Date: Mon, 20 Jan 2020 03:35:42 +0800
Subject: [PATCH] =?UTF-8?q?TODO:=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 14 ++---
src/main/java/com/yame/uml/Application.java | 4 ++
.../yame/uml/control/{api.java => API.java} | 14 +++--
src/test/java/com/yame/control/TestAPI.java | 53 ++++++++++++++++++-
4 files changed, 74 insertions(+), 11 deletions(-)
rename src/main/java/com/yame/uml/control/{api.java => API.java} (87%)
diff --git a/pom.xml b/pom.xml
index a794d14..d7abf84 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,6 +23,12 @@
spring-boot-starter-logging
+
+ com.jayway.jsonpath
+ json-path
+ 2.4.0
+
+
net.sourceforge.plantuml
plantuml
@@ -49,12 +55,6 @@
org.springframework.boot
spring-boot-starter-test
test
-
-
- org.junit.vintage
- junit-vintage-engine
-
-
@@ -69,4 +69,6 @@
+
+
\ No newline at end of file
diff --git a/src/main/java/com/yame/uml/Application.java b/src/main/java/com/yame/uml/Application.java
index 35b7385..3004a68 100644
--- a/src/main/java/com/yame/uml/Application.java
+++ b/src/main/java/com/yame/uml/Application.java
@@ -2,8 +2,12 @@ package com.yame.uml;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
@SpringBootApplication
+@Configuration
+
public class Application {
public static void main(String[] args) {
diff --git a/src/main/java/com/yame/uml/control/api.java b/src/main/java/com/yame/uml/control/API.java
similarity index 87%
rename from src/main/java/com/yame/uml/control/api.java
rename to src/main/java/com/yame/uml/control/API.java
index ca04103..5566bc4 100644
--- a/src/main/java/com/yame/uml/control/api.java
+++ b/src/main/java/com/yame/uml/control/API.java
@@ -19,12 +19,13 @@ import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.core.Diagram;
+import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.error.PSystemError;
@RestController
@RequestMapping("/api")
@Slf4j
-public class api {
+public class API {
static public String getUmlSource(String source) {
// encapsulate the UML syntax if necessary
@@ -45,7 +46,7 @@ public class api {
}
@PostMapping("/v1/megreflow")
- public Result megreSVG(@RequestParam("src") String src, @RequestParam("dst") String dst) throws IOException {
+ public Result megreSVG(@RequestParam("src") String src, @RequestParam("dst") String dst) throws IOException {
String source = getUmlSource(src);
List srcblocks = new SourceStringReader(source).getBlocks();
@@ -54,9 +55,14 @@ public class api {
Result result = new Result();
- if(srcblocks.size() != 0 && dstblocks.size() != 0) {
+ if (srcblocks.size() != 0 && dstblocks.size() != 0) {
+ BlockUml sblock = srcblocks.get(0);
+ BlockUml dblock = srcblocks.get(0);
+ Diagram d1 = sblock.getDiagram();
+ Diagram d2 = dblock.getDiagram();
-
+ UmlSource s1 = d1.getSource();
+ UmlSource s2 = d2.getSource();
}
result.setType(ResultType.ErrorMegreUML2SVG);
return result;
diff --git a/src/test/java/com/yame/control/TestAPI.java b/src/test/java/com/yame/control/TestAPI.java
index 9785fff..a375cd8 100644
--- a/src/test/java/com/yame/control/TestAPI.java
+++ b/src/test/java/com/yame/control/TestAPI.java
@@ -1,12 +1,63 @@
package com.yame.control;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+
+import com.fasterxml.jackson.core.JsonEncoding;
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.ReadContext;
+import com.yame.uml.Application;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import lombok.extern.slf4j.Slf4j;
/**
* TestAPI
*/
-@SpringBootTest
+
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@Slf4j
public class TestAPI {
+ @LocalServerPort
+ String port;
+
+ @Autowired
+ TestRestTemplate rest;
+
+ String domain;
+
+ @Before
+ public void init() {
+ domain = "http://localhost:" + port;
+ }
+ @Test
+ public void uml2SVG() {
+
+ MultiValueMap map = new LinkedMultiValueMap<>();
+ map.add("data", "123");
+ String resp = rest.postForObject(domain + "/api/v1/uml2svg", map, String.class);
+ ReadContext cxt = JsonPath.parse(resp);
+ assertEquals(cxt.read("$.type").toString(), "{desc=Error Source2SVG, code=-102, success=false}");
+
+ log.info(resp.toString());
+ }
}
\ No newline at end of file