package com.orchard.models;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kafka.connect.data.Struct;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;


public class StatsTests {
    Stats stats = new Stats();
    String statsJson =
      "{\"followers\":1,\"monthlyListeners\":2,\"popularity\":3,\"views\":4}";

    public StatsTests() {
        stats.followers = 1;
        stats.monthlyListeners = 2;
        stats.popularity = 3;
        stats.views = 4;
    }

    @Test
    public void shouldReturnValidKafkaStruct() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        Stats statsParsed = mapper.readValue(statsJson, Stats.class);
        Struct kafkaStruct = stats.ToKafkaStruct();
        assertEquals(statsParsed.followers, kafkaStruct.getInt64("followers"));
        assertEquals(statsParsed.monthlyListeners, kafkaStruct.getInt64("monthlyListeners"));
        assertEquals(statsParsed.popularity, kafkaStruct.getInt64("popularity"));
        assertEquals(statsParsed.views, kafkaStruct.getInt64("views"));
    }
}
