<commit_before>package no.uio.ifi.trackfind.backend.data.providers;

import com.google.common.collect.Multimap;
import no.uio.ifi.trackfind.TestTrackFindApplication;
import no.uio.ifi.trackfind.backend.converters.DocumentToMapConverter;
import org.apache.lucene.document.Document;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.*;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestTrackFindApplication.class)
public class DataProviderTests {

    @Autowired
    private DataProvider dataProvider;

    @Autowired
    private DocumentToMapConverter documentToMapConverter;

    @Test
    public void getNameTest() {
        assertThat(dataProvider.getName()).isEqualTo("Test");
    }

    @Test
    public void getPathTest() {
        assertThat(dataProvider.getPath()).isEqualTo("indices/Test/");
    }

    @Test
    public void saveLoadConfigurationTest() {
        DataProvider.Configuration oldConfiguration = new DataProvider.Configuration();
        oldConfiguration.setAttributesMapping(new HashMap<String, String>() {{
            put("1", "2");
        }});
        dataProvider.saveConfiguration(oldConfiguration);
        DataProvider.Configuration newConfiguration = dataProvider.loadConfiguration();
        assertThat(newConfiguration).isNotNull();
        Map<String, String> attributesMapping = newConfiguration.getAttributesMapping();
        assertThat(attributesMapping).isNotNull().isNotEmpty();
        assertThat(attributesMapping).containsOnlyKeys("1");
        assertThat(attributesMapping).containsEntry("1", "2");
    }

    @Test
    public void applyMappingsTest() {
        DataProvider.Configuration oldConfiguration = new DataProvider.Configuration();
        oldConfiguration.setAttributesMapping(new HashMap<String, String>() {{
            put("Advanced>key1", "BasicKey");
        }});
        dataProvider.saveConfiguration(oldConfiguration);
        dataProvider.applyMappings();
        Map<String, Collection<String>> metamodel = dataProvider.getMetamodelFlat().asMap();
        assertThat(metamodel).containsKeys("Basic>BasicKey");
        assertThat(metamodel.get("Basic>BasicKey")).hasSize(2);
    }

    @SuppressWarnings("unchecked")
    @Test
    public void metamodelTreeTest() {
        Map<String, Object> metamodel = dataProvider.getMetamodelTree();
        assertThat(metamodel).isNotNull().isNotEmpty();
        assertThat(metamodel).containsOnlyKeys("Advanced");
        metamodel = (Map<String, Object>) metamodel.get("Advanced");
        assertThat(metamodel).containsKeys("key1", "key2", "data_type");
        Object value = metamodel.get("key1");
        assertThat(value).isInstanceOf(Collection.class);
        assertThat((Collection) value).containsOnly("value1", "value2");
        value = metamodel.get("key2");
        assertThat(value).isInstanceOf(Collection.class);<commit_msg>Fix tests.<commit_after>package no.uio.ifi.trackfind.backend.data.providers;

import com.google.common.collect.Multimap;
import no.uio.ifi.trackfind.TestTrackFindApplication;
import no.uio.ifi.trackfind.backend.converters.DocumentToMapConverter;
import org.apache.lucene.document.Document;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.*;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestTrackFindApplication.class)
public class DataProviderTests {

    @Autowired
    private DataProvider dataProvider;

    @Autowired
    private DocumentToMapConverter documentToMapConverter;

    @Test
    public void getNameTest() {
        assertThat(dataProvider.getName()).isEqualTo("Test");
    }

    @Test
    public void getPathTest() {
        assertThat(dataProvider.getPath()).isEqualTo("indices/Test/");
    }

    @Test
    public void saveLoadConfigurationTest() {
        DataProvider.Configuration oldConfiguration = new DataProvider.Configuration();
        oldConfiguration.setAttributesMapping(new HashMap<String, String>() {{
            put("1", "2");
        }});
        dataProvider.saveConfiguration(oldConfiguration);
        DataProvider.Configuration newConfiguration = dataProvider.loadConfiguration();
        assertThat(newConfiguration).isNotNull();
        Map<String, String> attributesMapping = newConfiguration.getAttributesMapping();
        assertThat(attributesMapping).isNotNull().isNotEmpty();
        assertThat(attributesMapping).containsOnlyKeys("1");
        assertThat(attributesMapping).containsEntry("1", "2");
    }

    @Test
    public void applyMappingsTest() {
        DataProvider.Configuration oldConfiguration = new DataProvider.Configuration();
        oldConfiguration.setAttributesMapping(new HashMap<String, String>() {{
            put("Advanced>key1", "BasicKey");
        }});
        dataProvider.saveConfiguration(oldConfiguration);
        dataProvider.applyMappings();
        Map<String, Collection<String>> metamodel = dataProvider.getMetamodelFlat().asMap();
        assertThat(metamodel).containsKeys("Basic>BasicKey");
        assertThat(metamodel.get("Basic>BasicKey")).hasSize(2);
    }

    @SuppressWarnings("unchecked")
    @Test
    public void metamodelTreeTest() {
        Map<String, Object> metamodel = dataProvider.getMetamodelTree();
        assertThat(metamodel).isNotNull().isNotEmpty();
        assertThat(metamodel).containsOnlyKeys("Advanced");
        metamodel = (Map<String, Object>) metamodel.get("Advanced");
        assertThat(metamodel).containsKeys("key1", "key2");
        Object value = metamodel.get("key1");
        assertThat(value).isInstanceOf(Collection.class);
        assertThat((Collection) value).containsOnly("value1", "value2");
        value = metamodel.get("key2");
        assertThat(value).isInstanceOf(Collection.class);
{'fraction_non_alphanumeric': 0.12006420545746388, 'fraction_numerical': 0.0044943820224719105, 'mean_word_length': 4.253794266441822, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '422339', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1650, 'n_words': 247}