package com.iqser.red.service.peristence.v1.server.integration.tests;

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

import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.iqser.red.service.persistence.management.v1.processor.mapper.EntityLogResponseMapper;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLogResponse;

import lombok.SneakyThrows;

public class EntityLogResponseMapperTest {

    private final EntityLogResponseMapper mapper = EntityLogResponseMapper.INSTANCE;

    private final String ENTITY_LOG = "files/entity-log/b2cbdd4dca0aa1aa0ebbfc5cc1462df0.ENTITY_LOG.json";

    @Test
    @SneakyThrows
    public void testEntityLogMapper() {

        var file = new ClassPathResource(String.format(ENTITY_LOG));
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());

        EntityLog entityLogBefore = objectMapper.readValue(file.getInputStream(), EntityLog.class);

        EntityLogResponse entityLogResponseBefore = mapper.toLogResponse(entityLogBefore);

        EntityLog entityLogAfter = mapper.fromLogResponse(entityLogResponseBefore);

        assertEquals(entityLogBefore, entityLogAfter);

        EntityLogResponse entityLogResponseAfter = mapper.toLogResponse(entityLogAfter);

        assertEquals(entityLogResponseBefore, entityLogResponseAfter);

    }

}
