Skip to content

Commit

Permalink
fix: Kafka tests hardcodes and non-alphabetic symbols (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenischev authored Jun 17, 2020
1 parent 3587643 commit ae94bd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions template/src/test/java/com/asyncapi/SimpleKafkaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
@SpringBootTest
public class SimpleKafkaTest {
{% for channelName, channel in asyncapi.channels() %} {% if channel.hasSubscribe() %}
private static final String {{channelName | upper}}_TOPIC = "{{channelName}}";
private static final String {{channel.subscribe().id() | upper-}}_TOPIC = "{{channelName}}";
{% endif %} {% if channel.hasPublish() %}
private static final String {{channelName | upper}}_TOPIC = "{{channelName}}";
private static final String {{channel.publish().id() | upper-}}_TOPIC = "{{channelName}}";
{% endif %} {% endfor %}
@ClassRule
public static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, false, 1{% for channelName, channel in asyncapi.channels() %}{% if channel.hasSubscribe() %}, {{channelName | upper}}_TOPIC{% endif %}{% endfor %});
public static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, false, 1{% for channelName, channel in asyncapi.channels() %}{% if channel.hasSubscribe() %}, {{channel.subscribe().id() | upper-}}_TOPIC{% endif %}{% endfor %});

private static EmbeddedKafkaBroker embeddedKafkaBroker = embeddedKafka.getEmbeddedKafka();

Expand All @@ -84,7 +84,7 @@ public void init() {
consumerConfigs.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
{% for channelName, channel in asyncapi.channels() %} {% if channel.hasSubscribe() %}
consumer{{ channelName | camelCase | upperFirst}} = new DefaultKafkaConsumerFactory<>(consumerConfigs, new IntegerDeserializer(), new JsonDeserializer<>({{channel.subscribe().message().payload().uid() | camelCase | upperFirst}}.class)).createConsumer();
consumer{{ channelName | camelCase | upperFirst}}.subscribe(Collections.singleton({{channelName | upper}}_TOPIC));
consumer{{ channelName | camelCase | upperFirst}}.subscribe(Collections.singleton({{channel.subscribe().id() | upper-}}_TOPIC));
consumer{{ channelName | camelCase | upperFirst}}.poll(Duration.ZERO);
{% endif %} {% endfor %} {% endif %} {% if hasPublish %}
Map<String, Object> producerConfigs = new HashMap<>(KafkaTestUtils.producerProps(embeddedKafkaBroker));
Expand All @@ -93,25 +93,25 @@ public void init() {
}
{% for channelName, channel in asyncapi.channels() %} {% if channel.hasSubscribe() %}
@Test
public void {{channelName}}ProducerTest() {
public void {{channel.subscribe().id() | camelCase}}ProducerTest() {
{{channel.subscribe().message().payload().uid() | camelCase | upperFirst}} payload = new {{channel.subscribe().message().payload().uid() | camelCase | upperFirst}}();
Integer key = 1;

KafkaTestUtils.getRecords(consumer{{ channelName | camelCase | upperFirst}});

publisherService.notifyHouseChanges(key, payload);
publisherService.{{channel.subscribe().id() | camelCase}}(key, payload);

ConsumerRecord<Integer, {{channel.subscribe().message().payload().uid() | camelCase | upperFirst}}> singleRecord = KafkaTestUtils.getSingleRecord(consumer{{ channelName | camelCase | upperFirst}}, {{channelName | upper}}_TOPIC);
ConsumerRecord<Integer, {{channel.subscribe().message().payload().uid() | camelCase | upperFirst}}> singleRecord = KafkaTestUtils.getSingleRecord(consumer{{ channelName | camelCase | upperFirst}}, {{channel.subscribe().id() | upper-}}_TOPIC);

assertEquals("Key is wrong", key, singleRecord.key());
}
{% endif %} {% if channel.hasPublish() %}
@Test
public void {{channelName}}ConsumerTest() throws InterruptedException {
public void {{channel.publish().id() | camelCase}}ConsumerTest() throws InterruptedException {
Integer key = 1;
{{channel.publish().message().payload().uid() | camelCase | upperFirst}} payload = new {{channel.publish().message().payload().uid() | camelCase | upperFirst}}();

ProducerRecord<Integer, Object> producerRecord = new ProducerRecord<>({{channelName | upper}}_TOPIC, key, payload);
ProducerRecord<Integer, Object> producerRecord = new ProducerRecord<>({{channel.publish().id() | upper-}}_TOPIC, key, payload);
producer.send(producerRecord);
producer.flush();
Thread.sleep(1_000);
Expand Down
16 changes: 8 additions & 8 deletions template/src/test/java/com/asyncapi/TestcontainerKafkaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
public class TestcontainerKafkaTest {

{% for channelName, channel in asyncapi.channels() %} {% if channel.hasSubscribe() %}
private static final String {{channelName | upper}}_TOPIC = "{{channelName}}";
private static final String {{channel.subscribe().id() | upper-}}_TOPIC = "{{channelName}}";
{% endif %} {% if channel.hasPublish() %}
private static final String {{channelName | upper}}_TOPIC = "{{channelName}}";
private static final String {{channel.publish().id() | upper-}}_TOPIC = "{{channelName}}";
{% endif %} {% endfor %}
@ClassRule
public static KafkaContainer kafka = new KafkaContainer();
Expand All @@ -72,27 +72,27 @@ public static void kafkaProperties(DynamicPropertyRegistry registry) {
}
{% for channelName, channel in asyncapi.channels() %} {% if channel.hasSubscribe() %}
@Test
public void {{channelName}}ProducerTestcontainers() {
public void {{channel.subscribe().id() | camelCase}}ProducerTestcontainers() {
{{channel.subscribe().message().payload().uid() | camelCase | upperFirst}} payload = new {{channel.subscribe().message().payload().uid() | camelCase | upperFirst}}();
Integer key = 1;
Integer wrongKey = key + 1;

consumeMessages({{channelName | upper}}_TOPIC);
consumeMessages({{channel.subscribe().id() | upper-}}_TOPIC);

publisherService.notifyHouseChanges(key, payload);
publisherService.{{channel.subscribe().id() | camelCase}}(key, payload);

ConsumerRecord<Integer, Object> consumedMessage = consumeMessage({{channelName | upper}}_TOPIC);
ConsumerRecord<Integer, Object> consumedMessage = consumeMessage({{channel.subscribe().id() | upper-}}_TOPIC);

assertEquals("Key is wrong", key, consumedMessage.key());
assertNotEquals("Key is wrong", wrongKey, consumedMessage.key());
}
{% endif %} {% if channel.hasPublish() %}
@Test
public void {{channelName}}ConsumerTestcontainers() throws Exception {
public void {{channel.publish().id() | camelCase}}ConsumerTestcontainers() throws Exception {
Integer key = 1;
{{channel.publish().message().payload().uid() | camelCase | upperFirst}} payload = new {{channel.publish().message().payload().uid() | camelCase | upperFirst}}();

ProducerRecord<Integer, Object> producerRecord = new ProducerRecord<>({{channelName | upper}}_TOPIC, key, payload);
ProducerRecord<Integer, Object> producerRecord = new ProducerRecord<>({{channel.publish().id() | upper-}}_TOPIC, key, payload);

sendMessage(producerRecord);

Expand Down

0 comments on commit ae94bd4

Please sign in to comment.