-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplayerForReplayableLocalProcessModelTest.java
More file actions
127 lines (105 loc) · 4.98 KB
/
ReplayerForReplayableLocalProcessModelTest.java
File metadata and controls
127 lines (105 loc) · 4.98 KB
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
package src.org.processmining.placebasedlpmdiscovery.replayer;
import com.google.gson.Gson;
import org.junit.Assert;
import org.junit.Test;
import org.processmining.placebasedlpmdiscovery.model.LocalProcessModel;
import org.processmining.placebasedlpmdiscovery.model.Place;
import org.processmining.placebasedlpmdiscovery.model.exporting.importers.JsonImporter;
import org.processmining.placebasedlpmdiscovery.model.serializable.LPMResult;
import org.processmining.placebasedlpmdiscovery.replayer.ReplayableLocalProcessModelReplayer;
import org.python.google.common.reflect.TypeToken;
import src.org.processmining.mockobjects.MockLPMs;
import src.org.processmining.mockobjects.MockPlaces;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
public class ReplayerForReplayableLocalProcessModelTest {
@Test
public void givenSequencePlace_whenFindAllPaths_thenAllInputOutputTransitionPairs() {
// set input
Place p = MockPlaces.getSequencePlace_ab();
// act
Set<List<String>> actualPaths = ReplayableLocalProcessModelReplayer.findAllPaths(10, new LocalProcessModel(p));
// set expected result
Set<List<String>> expectedPaths = new HashSet<>(Collections.singletonList(Arrays.asList("a", "b")));
// test
Assert.assertEquals(expectedPaths, actualPaths);
}
@Test
public void givenSequencePlaceAndPathLimit1_whenFindAllPaths_thenAllInputOutputTransitionPairs() {
// set input
Place p = MockPlaces.getSequencePlace_ab();
// act
Set<List<String>> actualPaths = ReplayableLocalProcessModelReplayer.findAllPaths(1, new LocalProcessModel(p));
// set expected result
Set<List<String>> expectedPaths = new HashSet<>();
// test
Assert.assertEquals(expectedPaths, actualPaths);
}
@Test
public void givenSequence_whenFindAllPaths_thenOnePath() {
// set input
LocalProcessModel lpm = MockLPMs.getSequenceLPM_abc();
// act
Set<List<String>> actualPaths = ReplayableLocalProcessModelReplayer.findAllPaths(10, lpm);
// set expected result
Set<List<String>> expectedPaths = new HashSet<>(Collections.singletonList(Arrays.asList("a", "b", "c")));
// test
Assert.assertEquals(expectedPaths, actualPaths);
}
@Test
public void givenPredefinedLPMs_whenFindAllPaths_thenSameWithPredefinedLanguage() throws IOException {
// read models
JsonImporter<LPMResult> lpmsImporter = new JsonImporter<>();
LPMResult lpmResult = lpmsImporter.read(
LPMResult.class,
Files.newInputStream(Paths.get(
new File("").getAbsolutePath(),
"/data/test/replayer/predefined/models.json")));
// act
Map<String, Set<List<String>>> actualPaths = new HashMap<>();
for (LocalProcessModel lpm : lpmResult.getAllLPMs()) {
actualPaths.put(lpm.getId(), ReplayableLocalProcessModelReplayer.findAllPaths(10, lpm));
}
// read expected paths
Gson gson = new Gson();
Map<String, List<List<String>>> paths = gson.fromJson(
new FileReader(Paths.get(
new File("").getAbsolutePath(),
"/data/test/replayer/predefined/paths.json").toFile()),
new TypeToken<Map<String, List<List<String>>>>() {
}.getType());
Map<String, Set<List<String>>> expectedPaths = paths.keySet().stream().collect(Collectors.toMap(
key -> key, key -> new HashSet<>(paths.get(key))));
// test
for (String id : expectedPaths.keySet()) {
Assert.assertEquals(expectedPaths.get(id), actualPaths.get(id));
}
}
@Test
public void givenPredefinedLPMs2_whenFindAllPaths_thenSameWithPredefinedLanguage() throws IOException {
// read models and paths
Gson gson = new Gson();
Map<String, List<List<String>>> modelsWithPaths = gson.fromJson(
new FileReader(Paths.get(
new File("").getAbsolutePath(),
"/data/test/replayer/predefined/models_with_paths.json").toFile()),
new TypeToken<Map<String, List<List<String>>>>() {
}.getType());
Map<String, Set<List<String>>> expectedPaths = modelsWithPaths.keySet().stream().collect(Collectors.toMap(
key -> key, key -> new HashSet<>(modelsWithPaths.get(key))));
// act
Map<String, Set<List<String>>> actualPaths = new HashMap<>();
for (String lpmKey : modelsWithPaths.keySet()) {
actualPaths.put(lpmKey, ReplayableLocalProcessModelReplayer.findAllPaths(10, LocalProcessModel.from(lpmKey)));
}
// test
for (String id : expectedPaths.keySet()) {
Assert.assertEquals(expectedPaths.get(id), actualPaths.get(id));
}
}
}