Skip to content

Commit f3de532

Browse files
committed
moved test helper to own jar
1 parent f9172b3 commit f3de532

File tree

8 files changed

+97
-87
lines changed

8 files changed

+97
-87
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Added Re-Queue / Re-Run trigger to history page
1010
- Correlation Id is shown in the UI
1111
- ID search includes also Correlation Id
12+
- Moved helper classes to own test jar
1213

1314
## v1.5.6 - (2025-03-06)
1415

core/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
<version>${project.version}</version>
5252
<scope>test</scope>
5353
</dependency>
54+
<dependency>
55+
<groupId>${project.groupId}</groupId>
56+
<artifactId>spring-persistent-tasks-test</artifactId>
57+
<version>${project.version}</version>
58+
<scope>test</scope>
59+
</dependency>
5460

5561
<dependency>
5662
<groupId>org.liquibase</groupId>
@@ -83,6 +89,12 @@
8389
<artifactId>mssql-jdbc</artifactId>
8490
<scope>test</scope>
8591
</dependency>
92+
<dependency>
93+
<groupId>org.sterl.test</groupId>
94+
<artifactId>hibernate-asserts</artifactId>
95+
<version>1.0.0</version>
96+
<scope>test</scope>
97+
</dependency>
8698
<dependency>
8799
<groupId>org.postgresql</groupId>
88100
<artifactId>postgresql</artifactId>

core/src/test/java/org/sterl/spring/persistent_tasks/AbstractSpringTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.sterl.spring.persistent_tasks.trigger.model.TriggerEntity;
3333
import org.sterl.spring.sample_app.SampleApp;
3434
import org.sterl.test.AsyncAsserts;
35-
import org.sterl.test.HibernateAsserts;
35+
import org.sterl.test.hibernate_asserts.HibernateAsserts;
3636

3737
import jakarta.persistence.EntityManager;
3838
import lombok.RequiredArgsConstructor;

core/src/test/java/org/sterl/test/HibernateAsserts.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<module>db</module>
6565
<module>ui</module>
6666
<module>core</module>
67+
<module>test</module>
6768
</modules>
6869

6970
<dependencyManagement>

test/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.sterl.spring</groupId>
8+
<artifactId>spring-persistent-tasks-root</artifactId>
9+
<version>1.6.0-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>spring-persistent-tasks-test</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.projectlombok</groupId>
18+
<artifactId>lombok</artifactId>
19+
<optional>true</optional>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-test</artifactId>
24+
</dependency>
25+
</dependencies>
26+
</project>
Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.sterl.test;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.junit.jupiter.api.Assertions.fail;
4+
import static org.assertj.core.api.Assertions.fail;
55

66
import java.time.Duration;
77
import java.time.Instant;
@@ -13,30 +13,33 @@
1313

1414
import org.assertj.core.api.ListAssert;
1515

16+
import lombok.Getter;
1617
import lombok.Setter;
1718

1819
public class AsyncAsserts {
1920

2021
private final List<String> values = Collections.synchronizedList(new ArrayList<String>());
2122
private final Map<String, Integer> counts = new ConcurrentHashMap<>();
22-
@Setter
23-
private Duration defaultTimeout = Duration.ofSeconds(3);
2423

24+
@Getter @Setter
25+
private int maxStepCount = 100;
26+
27+
@Getter @Setter
28+
private Duration defaultTimeout = Duration.ofSeconds(3);
29+
2530
public synchronized void clear() {
2631
values.clear();
2732
counts.clear();
2833
}
29-
30-
public int add(String value) {
34+
public synchronized int add(String value) {
3135
values.add(value);
3236
final int count = getCount(value) + 1;
3337
counts.put(value, count);
34-
if (values.size() > 100) {
35-
throw new IllegalStateException("Workflow has already more than 100 steps, assuming error!");
38+
if (values.size() > maxStepCount) {
39+
throw new IllegalStateException("Flow has already more than " + maxStepCount + " steps, assuming error!");
3640
}
3741
return count;
3842
}
39-
4043
/**
4144
* @return how often this value has been already added ...
4245
*/
@@ -53,53 +56,55 @@ public int info(String value) {
5356
System.err.println(size + ". " + value);
5457
return count;
5558
}
56-
57-
public int getCount(String value) {
58-
return counts.getOrDefault(value, 0);
59-
}
6059
public int getCount() {
6160
return counts.size();
6261
}
63-
62+
63+
public int getCount(String value) {
64+
return counts.getOrDefault(value, 0);
65+
}
6466
public void awaitValue(String value) {
65-
final var start = Instant.now();
67+
awaitValue(null, value);
68+
}
69+
/**
70+
* Wait for the given value, if not found call the given method
71+
* @param fn the optional function to call after each wait
72+
* @param value the value to wait for
73+
*/
74+
public void awaitValue(Runnable fn, String value) {
75+
final var start = System.currentTimeMillis();
6676
while (!values.contains(value)
67-
&& (System.currentTimeMillis() - start.toEpochMilli() <= defaultTimeout.toMillis())) {
77+
&& (System.currentTimeMillis() - start <= defaultTimeout.toMillis())) {
6878
try {
69-
Thread.sleep(100);
79+
Thread.sleep(50);
80+
if (fn != null) fn.run();
7081
} catch (InterruptedException e) {
71-
if (Thread.interrupted()) {
72-
break;
73-
}
82+
if (Thread.interrupted()) break;
7483
}
7584
}
7685
assertValue(value);
7786
}
78-
79-
public ListAssert<String> assertValue(String value) {
80-
return assertThat(new ArrayList<>(values)).contains(value);
81-
}
82-
83-
public void awaitValue(String value, String... values) {
84-
awaitValue(value);
87+
/**
88+
* Wait for the given value, if not found call the given method
89+
* @param fn the optional function to call after each wait
90+
* @param value the value to wait for
91+
*/
92+
public void awaitValue(Runnable fn, String value, String... values) {
93+
awaitValue(fn, value);
8594
if (values != null && values.length > 0) {
8695
for (String v : values) {
87-
awaitValue(v);
96+
awaitValue(fn, v);
8897
}
8998
}
9099
}
91-
92-
public void awaitValueOnce(String value) {
93-
awaitValue(value);
94-
assertThat(values).contains(value);
95-
var occurrences = values.stream().filter(e -> value.equals(e)).count();
96-
if (occurrences > 1) {
97-
fail("Expected " + value + " to be present once but was present " + occurrences + " times.");
98-
}
100+
public void awaitValue(String value, String... values) {
101+
awaitValue(null, value, values);
99102
}
100-
101103
public void awaitOrdered(String value, String... values) {
102-
awaitValue(value, values);
104+
awaitOrdered(null, value, values);
105+
}
106+
public void awaitOrdered(Runnable fn, String value, String... values) {
107+
awaitValue(fn, value, values);
103108

104109
assertThat(this.values.indexOf(value)).isEqualTo(0);
105110
if (values != null && values.length > 0) {
@@ -108,7 +113,11 @@ public void awaitOrdered(String value, String... values) {
108113
}
109114
}
110115
}
111-
116+
117+
public ListAssert<String> assertValue(String value) {
118+
return assertThat(new ArrayList<>(values)).contains(value);
119+
}
120+
112121
public void assertMissing(String value) {
113122
assertThat(values).doesNotContain(value);
114123
}
@@ -118,4 +127,13 @@ public void assertMissing(String value, String... inValues) {
118127
assertThat(values).doesNotContain(s);
119128
}
120129
}
130+
131+
public void awaitValueOnce(String value) {
132+
awaitValue(null, value);
133+
assertThat(values).contains(value);
134+
var occurrences = values.stream().filter(e -> value.equals(e)).count();
135+
if (occurrences > 1) {
136+
fail("Expected " + value + " to be present once but was present " + occurrences + " times.");
137+
}
138+
}
121139
}

0 commit comments

Comments
 (0)