-
Notifications
You must be signed in to change notification settings - Fork 5
/
GridIoITbackup.groovy
157 lines (123 loc) · 4.82 KB
/
GridIoITbackup.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*package edu.ie3.datamodel.io
import edu.ie3.datamodel.io.sink.CsvFileSink
import edu.ie3.datamodel.io.source.csv.CsvGraphicSource
import edu.ie3.datamodel.io.source.csv.CsvGraphicSourceTest
import edu.ie3.datamodel.io.source.csv.CsvJointGridContainerSource
import edu.ie3.datamodel.io.source.csv.CsvRawGridSource
import edu.ie3.datamodel.io.source.csv.CsvTestDataMeta
import edu.ie3.datamodel.io.source.csv.CsvTypeSource
import edu.ie3.datamodel.models.input.NodeInput
import edu.ie3.datamodel.models.input.OperatorInput
import spock.lang.Specification
import java.nio.file.Path
import java.security.MessageDigest
import org.apache.commons.io.FileUtils
class GridIoIT extends Specification implements CsvTestDataMeta {
def setup(){
println "setup in progress..."
}
def cleanup(){
println "cleanup in progress..."
}
def "Imported files into a JointGridContainer get exported in the correct way."(){
given:
// create joint grid container
def gridname = new String("vn_simona")
def seperator = new String(",")
def folderpath = new String(jointGridFolderPath)
def firstgridContainer = CsvJointGridContainerSource.read(gridname, seperator, folderpath)
def secondgridContainer = CsvJointGridContainerSource.read(gridname, seperator, folderpath)
println("joint grid container created")
// input
def inDirectory = new File(folderpath)
def inHashCodes = [:]
println("input")
// output
def outFolderpath = new String("./exampleGridOut")
def sink = new CsvFileSink(outFolderpath)
def outDirectory = new File(outFolderpath)
def outHashCodes = [:]
println("output")
// list and number of filenames
def filenames = []
def filesCount = 0
def checkUpCount = 0
println("lists")
when:
String file = "src/test/resources/edu/ie3/datamodel/io/source/csv/_joint_grid/line_input.csv"
List<String> hashcodes = new ArrayList<String>()
BufferedReader br = new BufferedReader(new FileReader(file))
String line
String test = "Hallo"
println("br setup")
while ((line = br.readLine()) != null) {
String values = line.split(",")
println test.hashCode()
println "NEW LINE!!!"
}
println("br loop")
// Read original grid from input directory and generate hashcodes
inDirectory.eachFile {
inHashCodes.putAt(it.name, generateMD5(it))
}
println("inHashCodes generated")
// write files in output directory
sink.persistJointGrid(firstgridContainer)
// read files from output folder and generate hashcodes
outDirectory.eachFile {
outHashCodes.putAt(it.name, generateMD5(it))
filenames.add(it.name)
filesCount++ // geht auch über filenames
}
println("outHashCodes generated")
// delete files in output directory
outDirectory.eachFile {
it.deleteOnExit()
}
then:
firstgridContainer.getSystemParticipants().equals(second)
//SPA, RawGrid eleemnts, ...
/*while(checkUpCount < filesCount) {
print(inHashCodes.get(filenames.get(checkUpCount)))
print(" = ")
println(outHashCodes.get(filenames.get(checkUpCount)))
inHashCodes.get(filenames.get(checkUpCount)) == outHashCodes.get(filenames.get(checkUpCount))
checkUpCount++
}
inHashCodes.keySet().each{assert inHashCodes.get(it) == outHashCodes.get(it)}
}
def csvreader(final file) {
List<String> hashcodes = new ArrayList<String>()
BufferedReader br = new BufferedReader(new FileReader(file))
String line
String delimiter = ","
while ((line = br.readLine()) != null) {
String values = line.split(delimiter)
println "line"
}
}
List<List<String>> records = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader("book.csv"))) {
String line;
while ((line = br.readLine()) != null) {
String[] values = line.split(COMMA_DELIMITER);
records.add(Arrays.asList(values));
}
}
def generateMD5(final file) {
//StringBuilder strb = new StringBuilder()
//strb.append()
MessageDigest digest = MessageDigest.getInstance("MD5")
file.withInputStream() { is ->
byte[] buffer = new byte[8192]
int read = 0
while( (read = is.read(buffer)) > 0) {
digest.update(buffer, 0, read);
}
}
byte[] md5sum = digest.digest()
BigInteger bigInt = new BigInteger(1, md5sum)
return bigInt.toString(16).padLeft(32, '0')
}
}
*/