<commit_before>package org.opencb.opencga.catalog.db;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;
import com.mongodb.MongoCredential;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.opencb.commons.test.GenericTest;
import org.opencb.datastore.core.ObjectMap;
import org.opencb.datastore.core.QueryResult;
import org.opencb.datastore.core.config.DataStoreServerAddress;
import org.opencb.datastore.mongodb.MongoDataStore;
import org.opencb.datastore.mongodb.MongoDataStoreManager;
import org.opencb.opencga.catalog.beans.*;
import org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBAdaptor;
import org.opencb.opencga.lib.common.StringUtils;
import org.opencb.opencga.lib.common.TimeUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import static org.junit.Assert.*;

@FixMethodOrder(MethodSorters.JVM)
public class CatalogMongoDBAdaptorTest extends GenericTest {

    private static CatalogDBAdaptor catalog;

    @BeforeClass
    public static void before() throws IOException, CatalogManagerException {
        InputStream is = CatalogMongoDBAdaptorTest.class.getClassLoader().getResourceAsStream("catalog.properties");
        Properties properties = new Properties();
        properties.load(is);
        MongoCredential mongoCredentials = MongoCredential.createMongoCRCredential(
                properties.getProperty("CATALOG.USER", ""),
                properties.getProperty("CATALOG.DATABASE")+"_catalog_test",
                properties.getProperty("CATALOG.PASSWORD", "").toCharArray());
        DataStoreServerAddress dataStoreServerAddress = new DataStoreServerAddress(
                properties.getProperty("CATALOG.HOST"),
                Integer.parseInt(properties.getProperty("CATALOG.PORT")));

        clearDB(dataStoreServerAddress, mongoCredentials);

        catalog = new CatalogMongoDBAdaptor(dataStoreServerAddress, mongoCredentials);
    }


    @AfterClass
    public static void after() {
        catalog.disconnect();<commit_msg>catalog: two JUnit rules added<commit_after>package org.opencb.opencga.catalog.db;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;
import com.mongodb.MongoCredential;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;
import org.junit.runners.MethodSorters;
import org.opencb.commons.test.GenericTest;
import org.opencb.datastore.core.ObjectMap;
import org.opencb.datastore.core.QueryResult;
import org.opencb.datastore.core.config.DataStoreServerAddress;
import org.opencb.datastore.mongodb.MongoDataStore;
import org.opencb.datastore.mongodb.MongoDataStoreManager;
import org.opencb.opencga.catalog.beans.*;
import org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBAdaptor;
import org.opencb.opencga.lib.common.StringUtils;
import org.opencb.opencga.lib.common.TimeUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import static org.junit.Assert.*;

@FixMethodOrder(MethodSorters.JVM)
public class CatalogMongoDBAdaptorTest extends GenericTest {

    private static CatalogDBAdaptor catalog;

    @Rule
    public Timeout globalTimeout = new Timeout(200); // 200 ms max per method tested

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @BeforeClass
    public static void before() throws IOException, CatalogManagerException {
        InputStream is = CatalogMongoDBAdaptorTest.class.getClassLoader().getResourceAsStream("catalog.properties");
        Properties properties = new Properties();
        properties.load(is);
        MongoCredential mongoCredentials = MongoCredential.createMongoCRCredential(
                properties.getProperty("CATALOG.USER", ""),
                properties.getProperty("CATALOG.DATABASE")+"_catalog_test",
                properties.getProperty("CATALOG.PASSWORD", "").toCharArray());
        DataStoreServerAddress dataStoreServerAddress = new DataStoreServerAddress(
                properties.getProperty("CATALOG.HOST"),
                Integer.parseInt(properties.getProperty("CATALOG.PORT")));

        clearDB(dataStoreServerAddress, mongoCredentials);

        catalog = new CatalogMongoDBAdaptor(dataStoreServerAddress, mongoCredentials);
    }


    @AfterClass
    public static void after() {
        catalog.disconnect();
{'fraction_non_alphanumeric': 0.09751887810140238, 'fraction_numerical': 0.0012944983818770227, 'mean_word_length': 4.612590799031477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4560069', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1350, 'n_words': 222}