<commit_before>package fr.synchrotron.soleil.ica.ci.lib.mongodb.pomexporter.service;

import com.github.fakemongo.Fongo;
import com.mongodb.DB;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomexporter.repository.POMDocumentRepository;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomimporter.repository.POMImportRepository;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomimporter.service.POMImportService;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomimporter.service.PomReaderService;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.util.MongoDBDataSource;
import org.apache.maven.model.Model;
import org.jongo.Jongo;
import org.jongo.MongoCollection;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xml.sax.SAXException;

import java.io.*;
import java.net.URISyntaxException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * @author <NAME>
 */
public class POMExportServiceTest {

    private static DB mongoDB;
    private static Jongo jongo;

    private static POMImportService pomImportService;
    private static POMExportService pomExportService;

    @BeforeClass
    public static void setupMongoDB() throws IOException {
        final Fongo fongo = new Fongo("testMongoServer");
        mongoDB = fongo.getDB("repo");
        jongo = new Jongo(mongoDB);
        final InMemoryMongoDBDataSource mongoDBDataSource = new InMemoryMongoDBDataSource();
        pomImportService = new POMImportService(new POMImportRepository(mongoDBDataSource));
        pomExportService = new POMExportService(new POMDocumentRepository(mongoDBDataSource));
    }

    @After
    public void cleanupProjectsCollection() {
        MongoCollection projectsCollection = jongo.getCollection("projects");
        projectsCollection.remove();

        MongoCollection artifactsCollection = jongo.getCollection("artifacts");
        artifactsCollection.remove();
    }

    static private class InMemoryMongoDBDataSource implements MongoDBDataSource {
        @Override
        public DB getMongoDB() {
            return mongoDB;
        }
    }


    @Test
    public void test() throws IOException, URISyntaxException, SAXException {

        //TEST DATA
        StringWriter writer = new StringWriter();
        String org = "fr.synchrotron.soleil.ica.ci.lib";
        String name = "maven-versionresolver";
        String version = "1.0.0";
        String status = "RELEASE";
        File inputPomFile = new File(this.getClass().getResource("pom-1.xml").toURI());

        pomImportService.importPomFile(inputPomFile);
        pomExportService.exportPomFile(writer, org, name, status, version);

        PomReaderService pomReaderService = new PomReaderService();
        FileReader inputPomFileReader = new FileReader(inputPomFile);
        Model inputPomFileModel = pomReaderService.getModel(inputPomFileReader);<commit_msg>Rename test method<commit_after>package fr.synchrotron.soleil.ica.ci.lib.mongodb.pomexporter.service;

import com.github.fakemongo.Fongo;
import com.mongodb.DB;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomexporter.repository.POMDocumentRepository;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomimporter.repository.POMImportRepository;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomimporter.service.POMImportService;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomimporter.service.PomReaderService;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.util.MongoDBDataSource;
import org.apache.maven.model.Model;
import org.jongo.Jongo;
import org.jongo.MongoCollection;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xml.sax.SAXException;

import java.io.*;
import java.net.URISyntaxException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * @author <NAME>
 */
public class POMExportServiceTest {

    private static DB mongoDB;
    private static Jongo jongo;

    private static POMImportService pomImportService;
    private static POMExportService pomExportService;

    @BeforeClass
    public static void setupMongoDB() throws IOException {
        final Fongo fongo = new Fongo("testMongoServer");
        mongoDB = fongo.getDB("repo");
        jongo = new Jongo(mongoDB);
        final InMemoryMongoDBDataSource mongoDBDataSource = new InMemoryMongoDBDataSource();
        pomImportService = new POMImportService(new POMImportRepository(mongoDBDataSource));
        pomExportService = new POMExportService(new POMDocumentRepository(mongoDBDataSource));
    }

    @After
    public void cleanupProjectsCollection() {
        MongoCollection projectsCollection = jongo.getCollection("projects");
        projectsCollection.remove();

        MongoCollection artifactsCollection = jongo.getCollection("artifacts");
        artifactsCollection.remove();
    }

    static private class InMemoryMongoDBDataSource implements MongoDBDataSource {
        @Override
        public DB getMongoDB() {
            return mongoDB;
        }
    }


    @Test
    public void testExport() throws IOException, URISyntaxException, SAXException {

        //TEST DATA
        StringWriter writer = new StringWriter();
        String org = "fr.synchrotron.soleil.ica.ci.lib";
        String name = "maven-versionresolver";
        String version = "1.0.0";
        String status = "RELEASE";
        File inputPomFile = new File(this.getClass().getResource("pom-1.xml").toURI());

        pomImportService.importPomFile(inputPomFile);
        pomExportService.exportPomFile(writer, org, name, status, version);

        PomReaderService pomReaderService = new PomReaderService();
        FileReader inputPomFileReader = new FileReader(inputPomFile);
        Model inputPomFileModel = pomReaderService.getModel(inputPomFileReader);
{'fraction_non_alphanumeric': 0.09300735168404856, 'fraction_numerical': 0.0013677551718242434, 'mean_word_length': 3.9872122762148337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3529707', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1686, 'n_words': 325}