package cz.moneta.test.system.messaging.kafka;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;

import java.util.concurrent.TimeUnit;

@TestScenario(name = "Test Kafka pruducent and consumer functions")
public class KafkaTestsProducerConsumer {

    @TestCase(name = "Send message with additional headers")
    public void sendToDev(Harness harness) {
        harness.withKafka()
                .toTopic("TP_CVM_CARD-AUTHORIZATION-NOTIFICATION_STREAM_APP")
                .withKey("happyday")
                .withPayloadFromFile("system/kafka/test.json")
                .withHeader("requestId", "c3e2d840d4c4d6f14040404040404040e254359aa23fad11")
                .withHeader("activityId", "FSVc3e2d840d4c4d6f14040404040404040e254359aa23fad11")
                .withHeader("traceparent", "00-c3e2d840d4c4d6f14040404040404040-e254359aa23fad11-01")
                .withHeader("sourceCodebookId", "KOD_ODS")
                .send();
    }

    @TestCase(name = "Filtering by key")
    public void filteringByKey(Harness harness) {
        harness.withKafka()
                .fromTopic("TP_CVM_CARD-AUTHORIZATION-NOTIFICATION_STREAM_APP")
                .startFromBeginning()
                .receiveWhere(msg -> msg.getKey().equals("happyda"))
                .withTimeout(10, TimeUnit.SECONDS);
    }
}
