Skip to content
Snippets Groups Projects
Commit 11fe5e6b authored by Andrea Burattin's avatar Andrea Burattin
Browse files

A lot of work on the tests

parent 7a11f5b9
Branches
No related tags found
No related merge requests found
Showing with 270 additions and 77 deletions
......@@ -107,38 +107,4 @@
</plugin>
</plugins>
</build>
<!-- <profiles>
<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles> -->
</project>
\ No newline at end of file
......@@ -98,9 +98,9 @@ public class XesLogSource implements XesSource {
throw new SourceException("XES file format not supported");
}
private void prepareStream() {
if (log == null) {
return;
private void prepareStream() throws SourceException {
if (log.isEmpty()) {
throw new SourceException("The given log is empty");
}
// populate all events
events = new LinkedList<>();
......
......@@ -23,9 +23,7 @@ public class EventUtils {
private static final XFactory xesFactory = new XFactoryNaiveImpl();
private EventUtils() {
throw new IllegalStateException("Utility class");
}
private EventUtils() { }
/**
* Creates a new {@link XTrace} referring to one event
......
package beamline.tests;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItems;
import static org.junit.jupiter.api.Assertions.assertEquals;
......
......@@ -7,24 +7,21 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.deckfour.xes.model.XTrace;
import org.deckfour.xes.model.impl.XAttributeLiteralImpl;
import org.junit.jupiter.api.Test;
import beamline.exceptions.EventException;
import beamline.filters.ExcludeActivitiesFilter;
import beamline.filters.ExcludeOnCaseAttributeEqualityFilter;
import beamline.filters.RetainActivitiesFilter;
import beamline.filters.RetainOnCaseAttributeEqualityFilter;
import beamline.utils.EventUtils;
import io.reactivex.rxjava3.core.Observable;
public class FiltersTest {
@Test
public void test_exclude_activities_on_name_filter() {
List<String> results = new ArrayList<String>();
generateObservableSameCaseId()
Utils.generateObservableSameCaseId()
.filter(new ExcludeActivitiesFilter("A"))
.subscribe((t) -> results.add(EventUtils.getActivityName(t)));
assertEquals(3, results.size());
......@@ -34,7 +31,7 @@ public class FiltersTest {
@Test
public void test_retain_activities_on_name_filter() {
List<String> results = new ArrayList<String>();
generateObservableSameCaseId()
Utils.generateObservableSameCaseId()
.filter(new RetainActivitiesFilter("A","B"))
.subscribe((t) -> results.add(EventUtils.getActivityName(t)));
assertEquals(3, results.size());
......@@ -44,7 +41,7 @@ public class FiltersTest {
@Test
public void test_retain_activities_on_case_attribute_filter_1() {
List<String> results = new ArrayList<String>();
generateObservableSameCaseId()
Utils.generateObservableSameCaseId()
.filter(new RetainOnCaseAttributeEqualityFilter<XAttributeLiteralImpl>(
"a1",
new XAttributeLiteralImpl("a1", "v1")))
......@@ -56,7 +53,7 @@ public class FiltersTest {
@Test
public void test_retain_activities_on_case_attribute_filter_2() {
List<String> results = new ArrayList<String>();
generateObservableSameCaseId()
Utils.generateObservableSameCaseId()
.filter(new RetainOnCaseAttributeEqualityFilter<XAttributeLiteralImpl>(
"a1",
new XAttributeLiteralImpl("a1", "v1"),
......@@ -69,7 +66,7 @@ public class FiltersTest {
@Test
public void test_exclude_activities_on_case_attribute_filter_1() {
List<String> results = new ArrayList<String>();
generateObservableSameCaseId()
Utils.generateObservableSameCaseId()
.filter(new ExcludeOnCaseAttributeEqualityFilter<XAttributeLiteralImpl>(
"a1",
new XAttributeLiteralImpl("a1", "v1")))
......@@ -81,7 +78,7 @@ public class FiltersTest {
@Test
public void test_exclude_activities_on_case_attribute_filter_2() {
List<String> results = new ArrayList<String>();
generateObservableSameCaseId()
Utils.generateObservableSameCaseId()
.filter(new ExcludeOnCaseAttributeEqualityFilter<XAttributeLiteralImpl>(
"a1",
new XAttributeLiteralImpl("a1", "v1"),
......@@ -90,32 +87,4 @@ public class FiltersTest {
assertEquals(3, results.size());
assertThat(results, hasItems("K","B","A"));
}
/*
* Generate a streams with these events:
* - K
* - A / trace attribute: (a1,v1)
* - B
* - A
* - C / trace attribute: (a1,v4)
*/
private Observable<XTrace> generateObservableSameCaseId() {
XTrace[] events = null;
try {
events = new XTrace[] {
EventUtils.create("K", "c"),
EventUtils.create("A", "c"),
EventUtils.create("B", "c"),
EventUtils.create("A", "c"),
EventUtils.create("C", "c")
};
} catch (EventException e) {
e.printStackTrace();
}
events[1].getAttributes().put("a1", new XAttributeLiteralImpl("a1", "v1"));
events[2].get(0).getAttributes().put("a2", new XAttributeLiteralImpl("a2", "v3"));
events[3].get(0).getAttributes().put("a2", new XAttributeLiteralImpl("a2", "v2"));
events[4].getAttributes().put("a1", new XAttributeLiteralImpl("a1", "v4"));
return Observable.fromArray(events);
}
}
package beamline.tests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import beamline.mappers.DirectlyFollowsRelation;
import beamline.mappers.InfiniteSizeDirectlyFollowsMapper;
public class MapperTest {
@Test
public void test_infinite_size_df() {
List<DirectlyFollowsRelation> results = new ArrayList<>();
// <K,A,B,A,C>
Utils.generateObservableSameCaseId()
.flatMap(new InfiniteSizeDirectlyFollowsMapper())
.subscribe((df) -> results.add(df));
assertEquals(4, results.size());
assertTrue(Utils.verifyDirectFollows(results.get(0), "K", "A", "c"));
assertTrue(Utils.verifyDirectFollows(results.get(1), "A", "B", "c"));
assertTrue(Utils.verifyDirectFollows(results.get(2), "B", "A", "c"));
assertTrue(Utils.verifyDirectFollows(results.get(3), "A", "C", "c"));
}
}
package beamline.tests;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItems;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import java.util.LinkedList;
import java.util.List;
import org.junit.jupiter.api.Test;
import com.opencsv.CSVParserBuilder;
import beamline.exceptions.SourceException;
import beamline.sources.CSVLogSource;
import beamline.sources.XesLogSource;
import beamline.utils.EventUtils;
public class SourcesTest {
@Test
public void test_csv_source_1() {
List<String> acts = new LinkedList<>();
List<String> caseIds = new LinkedList<>();
CSVLogSource s = new CSVLogSource("src/test/resources/sources/source.csv", 0, 1);
try {
s.prepare();
} catch (SourceException e) {
e.printStackTrace();
}
s.getObservable().subscribe((t) -> {
acts.add(EventUtils.getActivityName(t));
caseIds.add(EventUtils.getCaseId(t));
});
assertEquals(5, acts.size());
assertEquals(5, caseIds.size());
assertThat(acts, hasItems("a11","a21","a22","a12","a23"));
assertThat(caseIds, hasItems("c1","c2","c2","c1","c2"));
}
@Test
public void test_csv_source_2() {
List<String> acts = new LinkedList<>();
List<String> caseIds = new LinkedList<>();
CSVLogSource s = new CSVLogSource(
"src/test/resources/sources/source_2.csv",
0,
1,
new CSVParserBuilder().withSeparator('|').build());
try {
s.prepare();
} catch (SourceException e) {
e.printStackTrace();
}
s.getObservable().subscribe((t) -> {
acts.add(EventUtils.getActivityName(t));
caseIds.add(EventUtils.getCaseId(t));
});
assertEquals(5, acts.size());
assertEquals(5, caseIds.size());
assertThat(acts, hasItems("a11","a21","a22","a12","a23"));
assertThat(caseIds, hasItems("c1","c2","c2","c1","c2"));
}
@Test
public void test_csv_source_3() {
CSVLogSource s = new CSVLogSource("DOESNT_EXIST", 0, 1);
assertThrowsExactly(SourceException.class, () -> s.prepare());
}
@Test
public void test_xes_source_1() {
XesLogSource s1 = new XesLogSource("src/test/resources/sources/empty.xes");
assertThrowsExactly(SourceException.class, () -> s1.prepare());
XesLogSource s2 = new XesLogSource("src/test/resources/sources/empty_2.xes");
assertThrowsExactly(SourceException.class, () -> s2.prepare());
XesLogSource s3 = new XesLogSource("src/test/resources/sources/empty.csv");
assertThrowsExactly(SourceException.class, () -> s3.prepare());
}
@Test
public void test_xes_source_2() {
List<String> acts = new LinkedList<>();
List<String> caseIds = new LinkedList<>();
XesLogSource s = new XesLogSource(Utils.generteXLog());
try {
s.prepare();
} catch (SourceException e) {
e.printStackTrace();
}
s.getObservable().subscribe((t) -> {
acts.add(EventUtils.getActivityName(t));
caseIds.add(EventUtils.getCaseId(t));
});
assertEquals(9, acts.size());
assertEquals(9, caseIds.size());
assertThat(acts, hasItems("K","C","A","I","B","O","A","A","C"));
assertThat(caseIds, hasItems("c1","c2","c1","c2","c1","c2","c1","c2","c1"));
}
@Test
public void test_xes_source_3() {
List<String> acts = new LinkedList<>();
List<String> caseIds = new LinkedList<>();
XesLogSource s = new XesLogSource("src/test/resources/sources/source.xes.gz");
try {
s.prepare();
} catch (SourceException e) {
e.printStackTrace();
}
s.getObservable().subscribe((t) -> {
acts.add(EventUtils.getActivityName(t));
caseIds.add(EventUtils.getCaseId(t));
});
assertEquals(5, acts.size());
assertEquals(5, caseIds.size());
assertThat(acts, hasItems("a11","a21","a22","a12","a23"));
assertThat(caseIds, hasItems("c1","c2","c2","c1","c2"));
}
}
package beamline.tests;
import org.deckfour.xes.extension.std.XConceptExtension;
import org.deckfour.xes.extension.std.XTimeExtension;
import org.deckfour.xes.factory.XFactory;
import org.deckfour.xes.factory.XFactoryNaiveImpl;
import org.deckfour.xes.model.XLog;
import org.deckfour.xes.model.XTrace;
import org.deckfour.xes.model.impl.XAttributeLiteralImpl;
import beamline.exceptions.EventException;
import beamline.mappers.DirectlyFollowsRelation;
import beamline.utils.EventUtils;
import io.reactivex.rxjava3.core.Observable;
public class Utils {
public static XFactory factory = new XFactoryNaiveImpl();
/*
* Generate a streams with these events:
* - K
* - A / trace attribute: (a1,v1)
* - B
* - A
* - C / trace attribute: (a1,v4)
*/
public static Observable<XTrace> generateObservableSameCaseId() {
XTrace[] events = null;
try {
events = new XTrace[] {
EventUtils.create("K", "c"),
EventUtils.create("A", "c"),
EventUtils.create("B", "c"),
EventUtils.create("A", "c"),
EventUtils.create("C", "c")
};
} catch (EventException e) {
e.printStackTrace();
}
events[1].getAttributes().put("a1", new XAttributeLiteralImpl("a1", "v1"));
events[2].get(0).getAttributes().put("a2", new XAttributeLiteralImpl("a2", "v3"));
events[3].get(0).getAttributes().put("a2", new XAttributeLiteralImpl("a2", "v2"));
events[4].getAttributes().put("a1", new XAttributeLiteralImpl("a1", "v4"));
return Observable.fromArray(events);
}
/*
* c1: <K,A,B,A,C>
* c2: <O,A,I,C>
*
* time order: (K,c1),(C,c2),(A,c1),(I,c2)(B,c1),(A,c2)(A,c1),(O,c2),(C,c1)
*/
public static XLog generteXLog() {
XLog l = factory.createLog();
XTrace c1 = factory.createTrace();
XConceptExtension.instance().assignName(c1, "c1");
c1.add(factory.createEvent()); XConceptExtension.instance().assignName(c1.get(0), "K");
c1.add(factory.createEvent()); XConceptExtension.instance().assignName(c1.get(1), "A"); XTimeExtension.instance().assignTimestamp(c1.get(1), 2);
c1.add(factory.createEvent()); XConceptExtension.instance().assignName(c1.get(2), "B"); XTimeExtension.instance().assignTimestamp(c1.get(2), 4);
c1.add(factory.createEvent()); XConceptExtension.instance().assignName(c1.get(3), "A"); XTimeExtension.instance().assignTimestamp(c1.get(3), 6);
c1.add(factory.createEvent()); XConceptExtension.instance().assignName(c1.get(4), "C"); XTimeExtension.instance().assignTimestamp(c1.get(4), 8);
XTrace c2 = factory.createTrace();
XConceptExtension.instance().assignName(c2, "c2");
c2.add(factory.createEvent());
c2.add(factory.createEvent());
c2.add(factory.createEvent());
c2.add(factory.createEvent());
XConceptExtension.instance().assignName(c2.get(3), "O"); XTimeExtension.instance().assignTimestamp(c2.get(3), 5);
XConceptExtension.instance().assignName(c2.get(2), "A"); XTimeExtension.instance().assignTimestamp(c2.get(2), 7);
XConceptExtension.instance().assignName(c2.get(1), "I"); XTimeExtension.instance().assignTimestamp(c2.get(1), 3);
XConceptExtension.instance().assignName(c2.get(0), "C"); XTimeExtension.instance().assignTimestamp(c2.get(0), 1);
l.add(c1);
l.add(c2);
return l;
}
public static boolean verifyDirectFollows(DirectlyFollowsRelation df, String a1, String a2, String caseId) {
String df_a1 = XConceptExtension.instance().extractName(df.getFirst());
String df_a2 = XConceptExtension.instance().extractName(df.getSecond());
return df_a1.equals(a1) && df_a2.equals(a2) && df.getCaseId().equals(caseId);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<log xes.version="1849.2016" xmlns="http://www.xes-standard.org" xes.creator="Fluxicon Disco">
</log>
\ No newline at end of file
c1,a11
c2,a21
c2,a22
c1,a12
c2,a23
\ No newline at end of file
File added
c1|a11
c2|a21
c2|a22
c1|a12
c2|a23
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment