TODO: 单元测试
This commit is contained in:
parent
d6194985c4
commit
ee1b1c4bfa
14
pom.xml
14
pom.xml
|
@ -23,6 +23,12 @@
|
||||||
<artifactId>spring-boot-starter-logging</artifactId>
|
<artifactId>spring-boot-starter-logging</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.jayway.jsonpath</groupId>
|
||||||
|
<artifactId>json-path</artifactId>
|
||||||
|
<version>2.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sourceforge.plantuml</groupId>
|
<groupId>net.sourceforge.plantuml</groupId>
|
||||||
<artifactId>plantuml</artifactId>
|
<artifactId>plantuml</artifactId>
|
||||||
|
@ -49,12 +55,6 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,4 +69,6 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -2,8 +2,12 @@ package com.yame.uml;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@Configuration
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -19,12 +19,13 @@ import net.sourceforge.plantuml.FileFormat;
|
||||||
import net.sourceforge.plantuml.FileFormatOption;
|
import net.sourceforge.plantuml.FileFormatOption;
|
||||||
import net.sourceforge.plantuml.SourceStringReader;
|
import net.sourceforge.plantuml.SourceStringReader;
|
||||||
import net.sourceforge.plantuml.core.Diagram;
|
import net.sourceforge.plantuml.core.Diagram;
|
||||||
|
import net.sourceforge.plantuml.core.UmlSource;
|
||||||
import net.sourceforge.plantuml.error.PSystemError;
|
import net.sourceforge.plantuml.error.PSystemError;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class api {
|
public class API {
|
||||||
|
|
||||||
static public String getUmlSource(String source) {
|
static public String getUmlSource(String source) {
|
||||||
// encapsulate the UML syntax if necessary
|
// encapsulate the UML syntax if necessary
|
||||||
|
@ -45,7 +46,7 @@ public class api {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/v1/megreflow")
|
@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);
|
String source = getUmlSource(src);
|
||||||
List<BlockUml> srcblocks = new SourceStringReader(source).getBlocks();
|
List<BlockUml> srcblocks = new SourceStringReader(source).getBlocks();
|
||||||
|
|
||||||
|
@ -54,9 +55,14 @@ public class api {
|
||||||
|
|
||||||
Result result = new Result();
|
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);
|
result.setType(ResultType.ErrorMegreUML2SVG);
|
||||||
return result;
|
return result;
|
|
@ -1,12 +1,63 @@
|
||||||
package com.yame.control;
|
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.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
|
* TestAPI
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
@Slf4j
|
||||||
public class TestAPI {
|
public class TestAPI {
|
||||||
|
|
||||||
|
@LocalServerPort
|
||||||
|
String port;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TestRestTemplate rest;
|
||||||
|
|
||||||
|
String domain;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
domain = "http://localhost:" + port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void uml2SVG() {
|
||||||
|
|
||||||
|
MultiValueMap<String, String> 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());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user