-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from jupiter-tools/assert-silence-for-kafka
assert silence for expected messages in Kafka
- Loading branch information
Showing
13 changed files
with
183 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...n/java/com/jupiter/tools/spring/test/core/expected/list/messages/DataSetPreProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.jupiter.tools.spring.test.core.expected.list.messages; | ||
|
||
|
||
import com.jupitertools.datasetroll.DataSet; | ||
|
||
/** | ||
* Pre-processing the DataSet from one state to another | ||
* | ||
* @author Korovin Anatoliy | ||
*/ | ||
public interface DataSetPreProcessor { | ||
|
||
/** | ||
* transform the source dataset | ||
* | ||
* @param source input dataset | ||
* @return transformed version of the dataset | ||
*/ | ||
DataSet run(DataSet source); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
.../main/java/com/jupiter/tools/spring/test/core/expected/list/messages/MessagesDataSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.jupiter.tools.spring.test.core.expected.list.messages; | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.jupitertools.datasetroll.DataSet; | ||
|
||
/** | ||
* DataSet to represent a list of messages. | ||
* Matches canonical class name of a message object to the list of messages converted to Map. | ||
* | ||
* @author Korovin Anatoliy | ||
*/ | ||
public class MessagesDataSet implements DataSet { | ||
|
||
private final List<Object> messages; | ||
private final ObjectMapper objectMapper; | ||
|
||
/** | ||
* Make the DataSet from a list of received messages. | ||
* | ||
* @param messages the list of messages objects | ||
*/ | ||
public MessagesDataSet(List<Object> messages) { | ||
this.messages = messages; | ||
this.objectMapper = new ObjectMapper(); | ||
} | ||
|
||
@Override | ||
public Map<String, List<Map<String, Object>>> read() { | ||
|
||
Map<String, List<Map<String, Object>>> result = new HashMap<>(); | ||
|
||
for (Object message : messages) { | ||
|
||
String className = message.getClass().getCanonicalName(); | ||
Map<String, Object> messageFields = objectMapper.convertValue(message, Map.class); | ||
|
||
List<Map<String, Object>> entry = result.get(className); | ||
if (entry == null) { | ||
result.put(className, new ArrayList<>(Arrays.asList(messageFields))); | ||
} else { | ||
entry.add(messageFields); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...t/java/com/jupiter/tools/spring/test/core/expected/list/messages/MessagesDataSetTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.jupiter.tools.spring.test.core.expected.list.messages; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class MessagesDataSetTest { | ||
|
||
@Test | ||
void singleTypeOfMessages() { | ||
Foo foo1 = new Foo("111"); | ||
Foo foo2 = new Foo("222"); | ||
List<Object> messages = Arrays.asList(foo1, foo2); | ||
MessagesDataSet dataSet = new MessagesDataSet(messages); | ||
// Act | ||
Map<String, List<Map<String, Object>>> map = dataSet.read(); | ||
// Assert | ||
assertThat(map).containsKeys(Foo.class.getCanonicalName()); | ||
assertThat(map.get(Foo.class.getCanonicalName())).contains(ImmutableMap.of("name", "111"), | ||
ImmutableMap.of("name", "222")); | ||
} | ||
|
||
@Test | ||
void multipleTypes() { | ||
Foo foo1 = new Foo("111"); | ||
Foo foo2 = new Foo("222"); | ||
Bar bar = new Bar("AAA"); | ||
List<Object> messages = Arrays.asList(foo1, foo2, bar); | ||
MessagesDataSet dataSet = new MessagesDataSet(messages); | ||
// Act | ||
Map<String, List<Map<String, Object>>> map = dataSet.read(); | ||
// Assert | ||
assertThat(map).containsKeys(Foo.class.getCanonicalName()); | ||
assertThat(map.get(Foo.class.getCanonicalName())).contains(ImmutableMap.of("name", "111"), | ||
ImmutableMap.of("name", "222")); | ||
assertThat(map).containsKeys(Bar.class.getCanonicalName()); | ||
assertThat(map.get(Bar.class.getCanonicalName())).contains(ImmutableMap.of("value", "AAA")); | ||
} | ||
|
||
@Data | ||
@AllArgsConstructor | ||
static class Foo { | ||
private String name; | ||
} | ||
|
||
@Data | ||
@AllArgsConstructor | ||
static class Bar { | ||
private String value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters