Revize 7740b8c5
Přidáno uživatelem Martin Matas před téměř 6 roky(ů)
sources/imiger-dot-converter/src/test/java/cz/zcu/kiv/imiger/plugin/dot/DOTIntegrityTest.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.dot; |
|
2 |
|
|
3 |
import org.junit.Test; |
|
4 |
|
|
5 |
import java.io.IOException; |
|
6 |
import java.net.URISyntaxException; |
|
7 |
import java.net.URL; |
|
8 |
import java.nio.file.Files; |
|
9 |
import java.nio.file.Path; |
|
10 |
import java.nio.file.Paths; |
|
11 |
import java.util.Objects; |
|
12 |
import java.util.stream.Collectors; |
|
13 |
import java.util.stream.Stream; |
|
14 |
|
|
15 |
import static org.hamcrest.CoreMatchers.*; |
|
16 |
import static org.hamcrest.MatcherAssert.assertThat; |
|
17 |
|
|
18 |
/** |
|
19 |
* Integrity test fot DOT module. Verifies that for given DOT file module produces correct JSON output. |
|
20 |
* |
|
21 |
* Date: 03.04.2019 |
|
22 |
* |
|
23 |
* @author Martin Matas |
|
24 |
*/ |
|
25 |
public class DOTIntegrityTest { |
|
26 |
|
|
27 |
/** |
|
28 |
* Loaded test DOT file. Loaded string contains simple graph definition (two vertices connected with edge, |
|
29 |
* each of them has defined attribute). |
|
30 |
*/ |
|
31 |
private final String integrityTestDOTFile = loadTestDOTFile(); |
|
32 |
|
|
33 |
/** |
|
34 |
* Loaded JSON file. Represents correct test result. |
|
35 |
*/ |
|
36 |
private final String integrityTestExpectedResult = loadTestResult(); |
|
37 |
|
|
38 |
/** |
|
39 |
* Test verifies that for given DOT file module produces correct JSON output. |
|
40 |
*/ |
|
41 |
@Test |
|
42 |
public void getRawJson() { |
|
43 |
assertThat(integrityTestDOTFile, is(not(nullValue()))); |
|
44 |
assertThat(integrityTestExpectedResult, is(not(nullValue()))); |
|
45 |
|
|
46 |
DOT dotModule = new DOT(); |
|
47 |
String result = dotModule.getRawJson(integrityTestDOTFile); |
|
48 |
|
|
49 |
assertThat(result, is(equalTo(integrityTestExpectedResult))); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Method loads DOT file from resources and returns it as a string. |
|
54 |
* |
|
55 |
* @return - string that contains loaded DOT file |
|
56 |
*/ |
|
57 |
private String loadTestDOTFile() { |
|
58 |
return readFile(Objects.requireNonNull(getClass().getClassLoader().getResource("integrityTestSource.dot"))); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Method loads JSON file from resources and returns it as a string. |
|
63 |
* |
|
64 |
* @return - string that contains loaded JSON file |
|
65 |
*/ |
|
66 |
private String loadTestResult() { |
|
67 |
return readFile(Objects.requireNonNull(getClass().getClassLoader().getResource("integrityTestResult.json"))); |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Method loads file based on given URL and returns it as a string. |
|
72 |
* |
|
73 |
* @param url - URL of file |
|
74 |
* @return - file content as a string |
|
75 |
*/ |
|
76 |
private String readFile(URL url) { |
|
77 |
String data = null; |
|
78 |
|
|
79 |
try { |
|
80 |
Path path = Paths.get(url.toURI()); |
|
81 |
Stream<String> lines = Files.lines(path); |
|
82 |
data = lines.collect(Collectors.joining("\n")); |
|
83 |
lines.close(); |
|
84 |
} catch (IOException | URISyntaxException e) { |
|
85 |
System.err.println("Loading test resource failed."); |
|
86 |
} |
|
87 |
|
|
88 |
return data; |
|
89 |
} |
|
90 |
|
|
91 |
} |
sources/imiger-dot-converter/src/test/resources/integrityTestResult.json | ||
---|---|---|
1 |
{"vertices":[{"attributes":[["test","test value"]],"id":0,"name":"A","archetype":0,"text":""},{"attributes":[["test","test value"]],"id":1,"name":"B","archetype":0,"text":""}],"edges":[{"subedgeInfo":[{"archetype":0,"id":0,"attributes":[["test","test value"]]}],"id":0,"from":0,"to":1,"text":"A-B"}],"vertexArchetypes":[{"name":"Vertex","text":"","icon":""}],"edgeArchetypes":[{"name":"Edge","text":""}],"attributeTypes":[{"name":"test","dataType":"STRING","text":""}],"possibleEnumValues":{},"groups":[],"sideBar":[],"highlightedVertex":"","highlightedEdge":""} |
sources/imiger-dot-converter/src/test/resources/integrityTestSource.dot | ||
---|---|---|
1 |
digraph "test" { |
|
2 |
"A" [test="test value"]; |
|
3 |
"B" [test="test value"]; |
|
4 |
"A" -> "B" [test="test value"]; |
|
5 |
} |
Také k dispozici: Unified diff
Integrity test for DOT module with necessary test files