import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
import org.apache.kafka.common.utils.Bytes;
+import org.springframework.beans.factory.annotation.Autowired;
+import java.util.*;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class ApplicationTests extends GenericApplicationTests<String, String>
{
+ @Autowired
+ AdderResults results;
+
+
public ApplicationTests()
{
super(new ApplicationTestRecrodGenerator());
+ ((ApplicationTestRecrodGenerator)recordGenerator).tests = this;
}
static class ApplicationTestRecrodGenerator implements RecordGenerator
{
+ ApplicationTests tests;
+
final int[] numbers = {1, 7, 3, 2, 33, 6, 11};
final String[] dieWilden13 =
IntStream
int counter = 0;
+ Map<String, List<AdderResult>> state;
+
@Override
public int generate(
boolean poisonPills,
Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
{
counter = 0;
+ state =
+ Arrays
+ .stream(dieWilden13)
+ .collect(Collectors.toMap(
+ seeräuber -> seeräuber,
+ seeräuber -> new LinkedList()));
for (int i = 0; i < 33; i++)
{
send(key, value, logicErrors, messageSender);
}
send(key, calculateMessage, logicErrors, messageSender);
+
+ state.get(seeräuber).add(new AdderResult(number, (number + 1) * number / 2));
}
return counter;
{
return false;
}
+
+ @Override
+ public void assertBusinessLogic()
+ {
+ tests.results
+ .getState()
+ .values()
+ .stream()
+ .flatMap(map -> map.entrySet().stream())
+ .forEach(entry ->
+ {
+ String user = entry.getKey();
+ List<AdderResult> resultsForUser = entry.getValue();
+
+ assertThat(state.get(user))
+ .describedAs("Unexpected results for user {}", user)
+ .containsExactlyElementsOf(resultsForUser);
+ });
+ }
}
}