<commit_before>package com.imcode.imcms.domain.service.api;

import com.imcode.imcms.components.datainitializer.CategoryDataInitializer;
import com.imcode.imcms.components.datainitializer.FileDocumentDataInitializer;
import com.imcode.imcms.config.TestConfig;
import com.imcode.imcms.domain.dto.AuditDTO;
import com.imcode.imcms.domain.dto.DocumentFileDTO;
import com.imcode.imcms.domain.dto.FileDocumentDTO;
import com.imcode.imcms.domain.service.DocumentFileService;
import com.imcode.imcms.domain.service.DocumentService;
import com.imcode.imcms.domain.service.UserService;
import com.imcode.imcms.model.Category;
import com.imcode.imcms.model.CommonContent;
import com.imcode.imcms.model.DocumentFile;
import com.imcode.imcms.model.Roles;
import com.imcode.imcms.persistence.entity.CategoryJPA;
import com.imcode.imcms.persistence.entity.DocumentFileJPA;
import com.imcode.imcms.persistence.entity.Meta;
import com.imcode.imcms.persistence.entity.Version;
import com.imcode.imcms.persistence.repository.MetaRepository;
import imcode.server.Config;
import imcode.server.Imcms;
import imcode.server.user.UserDomainObject;
import imcode.util.io.FileUtility;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

@Transactional
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class FileDocumentServiceTest {

    private static final int userId = 1;

    private static File testSolrFolder;
    private static File testFilesFolder;

    private FileDocumentDTO createdDoc;
    private int createdDocId;

    @Value("classpath:img1.jpg")
    private File testFile;

    @Value("${FilePath}")
    private Resource filesPath;

    @Autowired
    private FileDocumentDataInitializer documentDataInitializer;

    @Autowired
    private Config config;

    @Value("WEB-INF/solr")
    private File defaultSolrFolder;

    @Autowired
    private DocumentService<FileDocumentDTO> fileDocumentService;

    @Autowired
    private DocumentFileService documentFileService;

    @Autowired
    private CategoryDataInitializer categoryDataInitializer;

    @Autowired
    private MetaRepository metaRepository;

    @Autowired
    private UserService userService;

    @BeforeClass
    public static void setUpUser() {
        Imcms.setUser(new UserDomainObject(userId));
    }

    @AfterClass
    public static void shutDownSolr() {
        try {
            FileUtility.forceDelete(testSolrFolder);

        } catch (Exception e) {
            testSolrFolder.deleteOnExit();

        } finally {
            try {
                FileUtility.forceDelete(testFilesFolder);

            } catch (Exception e) {
                testFilesFolder.deleteOnExit();
            }
        }
    }

    @Before
    public void setUp() throws Exception {
        createdDoc = documentDataInitializer.createFileDocument();
        createdDocId = createdDoc.getId();
        filesPath.getFile().mkdirs();
    }

    @PostConstruct
    private void setUpSolrFiles() throws IOException {
        testSolrFolder = new File(config.getSolrHome());
        testFilesFolder = filesPath.getFile();

        if (testSolrFolder.mkdirs()) {
            FileUtils.copyDirectory(defaultSolrFolder, testSolrFolder);
        }
    }

    @Test
    public void createFromParent() {
        final FileDocumentDTO newDoc = fileDocumentService.createFromParent(this.createdDoc.getId());

        assertNull(newDoc.getId());
        assertEquals(newDoc.getType(), Meta.DocumentType.FILE);
        assertNotNull(newDoc.getFiles());<commit_msg>IMCMS-334 New design to super admin page: link validator tab - Update test from junit4 to junit5<commit_after>package com.imcode.imcms.domain.service.api;

import com.imcode.imcms.WebAppSpringTestConfig;
import com.imcode.imcms.components.datainitializer.CategoryDataInitializer;
import com.imcode.imcms.components.datainitializer.FileDocumentDataInitializer;
import com.imcode.imcms.domain.dto.AuditDTO;
import com.imcode.imcms.domain.dto.DocumentFileDTO;
import com.imcode.imcms.domain.dto.FileDocumentDTO;
import com.imcode.imcms.domain.service.DocumentFileService;
import com.imcode.imcms.domain.service.DocumentService;
import com.imcode.imcms.domain.service.UserService;
import com.imcode.imcms.model.Category;
import com.imcode.imcms.model.CommonContent;
import com.imcode.imcms.model.DocumentFile;
import com.imcode.imcms.model.Roles;
import com.imcode.imcms.persistence.entity.CategoryJPA;
import com.imcode.imcms.persistence.entity.DocumentFileJPA;
import com.imcode.imcms.persistence.entity.Meta;
import com.imcode.imcms.persistence.entity.Version;
import com.imcode.imcms.persistence.repository.MetaRepository;
import imcode.server.Config;
import imcode.server.Imcms;
import imcode.server.user.UserDomainObject;
import imcode.util.io.FileUtility;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;

@Transactional
public class FileDocumentServiceTest extends WebAppSpringTestConfig {

    private static final int userId = 1;

    private static File testSolrFolder;
    private static File testFilesFolder;

    private FileDocumentDTO createdDoc;
    private int createdDocId;

    @Value("classpath:img1.jpg")
    private File testFile;

    @Value("${FilePath}")
    private Resource filesPath;

    @Autowired
    private FileDocumentDataInitializer documentDataInitializer;

    @Autowired
    private Config config;

    @Value("WEB-INF/solr")
    private File defaultSolrFolder;

    @Autowired
    private DocumentService<FileDocumentDTO> fileDocumentService;

    @Autowired
    private DocumentFileService documentFileService;

    @Autowired
    private CategoryDataInitializer categoryDataInitializer;

    @Autowired
    private MetaRepository metaRepository;

    @Autowired
    private UserService userService;

    @BeforeAll
    public static void setUpUser() {
        Imcms.setUser(new UserDomainObject(userId));
    }

    @AfterAll
    public static void shutDownSolr() {
        try {
            FileUtility.forceDelete(testSolrFolder);

        } catch (Exception e) {
            testSolrFolder.deleteOnExit();

        } finally {
            try {
                FileUtility.forceDelete(testFilesFolder);

            } catch (Exception e) {
                testFilesFolder.deleteOnExit();
            }
        }
    }

    @BeforeEach
    public void setUp() throws Exception {
        createdDoc = documentDataInitializer.createFileDocument();
        createdDocId = createdDoc.getId();
        filesPath.getFile().mkdirs();
    }

    @PostConstruct
    private void setUpSolrFiles() throws IOException {
        testSolrFolder = new File(config.getSolrHome());
        testFilesFolder = filesPath.getFile();

        if (testSolrFolder.mkdirs()) {
            FileUtils.copyDirectory(defaultSolrFolder, testSolrFolder);
        }
    }

    @Test
    public void createFromParent() {
        final FileDocumentDTO newDoc = fileDocumentService.createFromParent(this.createdDoc.getId());

        assertNull(newDoc.getId());
        assertEquals(newDoc.getType(), Meta.DocumentType.FILE);
        assertNotNull(newDoc.getFiles());
{'fraction_non_alphanumeric': 0.09268621503201888, 'fraction_numerical': 0.0013481631277384564, 'mean_word_length': 4.081050228310502, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1796169', 'n_tokens_mistral': 2613, 'n_tokens_neox': 2563, 'n_words': 465}