package com.iqser.red.service.persistence.management.v1.processor.migration;

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

import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

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.EntityLogEntry;

class StorageToMongoCopyServiceTest {

    @Test
    public void testDeDuplication() {

        EntityLog entityLog = new EntityLog();
        List<EntityLogEntry> entityLogEntries = new ArrayList<>();
        entityLogEntries.add(EntityLogEntry.builder().id("1").build());
        entityLogEntries.add(EntityLogEntry.builder().id("1").build());
        entityLogEntries.add(EntityLogEntry.builder().id("1").build());
        entityLogEntries.add(EntityLogEntry.builder().id("2").build());
        entityLogEntries.add(EntityLogEntry.builder().id("3").build());
        entityLogEntries.add(EntityLogEntry.builder().id("4").build());
        entityLog.setEntityLogEntry(entityLogEntries);

        EntityLog cleanedEntityLog = StorageToMongoCopyService.removeDuplicates(entityLog);
        assertEquals(4, cleanedEntityLog.getEntityLogEntry().size());
    }


    @Test
    public void testDeDuplicationWithoutDuplicates() {

        EntityLog entityLog = new EntityLog();
        List<EntityLogEntry> entityLogEntries = new ArrayList<>();
        entityLogEntries.add(EntityLogEntry.builder().id("1").build());
        entityLogEntries.add(EntityLogEntry.builder().id("2").build());
        entityLogEntries.add(EntityLogEntry.builder().id("3").build());
        entityLogEntries.add(EntityLogEntry.builder().id("4").build());
        entityLog.setEntityLogEntry(entityLogEntries);

        EntityLog cleanedEntityLog = StorageToMongoCopyService.removeDuplicates(entityLog);
        assertEquals(4, cleanedEntityLog.getEntityLogEntry().size());
    }

}