<commit_before>package com.socrata.datasync.job;

import com.socrata.datasync.Main;
import com.socrata.datasync.config.CommandLineOptions;
import com.socrata.datasync.config.userpreferences.UserPreferences;
import com.socrata.datasync.config.userpreferences.UserPreferencesJava;
import junit.framework.TestCase;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.junit.Before;
import org.junit.Test;

import java.util.prefs.BackingStoreException;

public class LoadPreferencesJobTest {

    private LoadPreferencesJob job;
    CommandLineParser parser;
    CommandLineOptions cmd = new CommandLineOptions();

    @Before
    public void initialize() {
        job = new LoadPreferencesJob();
        parser = new PosixParser();
    }

    @Test
    public void testValidationOfArgs() throws ParseException {

        String[] goodArgs = {"-c", "myConfig.json"};
        String[] incompleteArgs = {"-t", "LoadPreferences"};

        TestCase.assertTrue(job.validateArgs(parser.parse(cmd.options, goodArgs)));
        TestCase.assertFalse(job.validateArgs(parser.parse(cmd.options, incompleteArgs)));
    }

    @Test
    public void testLoadCompletePreferencesWithClearStart() throws ParseException, BackingStoreException {
        UserPreferencesJava userPrefs = new UserPreferencesJava();
        userPrefs.clear();

        String[] args = {"-t", "LoadPreferences", "-c", "src/test/resources/basic_test_config.json"};
        Main.main(args);
        TestCase.assertEquals("https://sandbox.demo.socrata.com", userPrefs.getDomain());
        TestCase.assertEquals("<EMAIL>", userPrefs.getUsername());
        TestCase.assertEquals("OpenData", userPrefs.getPassword());
        TestCase.assertEquals("D8Atrg62F2j017ZTdkMpuZ9vY", userPrefs.getAPIKey());
        TestCase.assertEquals("<EMAIL>", userPrefs.getAdminEmail());
        TestCase.assertEquals(false, userPrefs.emailUponError());
        TestCase.assertEquals("", userPrefs.getLogDatasetID());
        TestCase.assertEquals("smtp.something.com", userPrefs.getOutgoingMailServer());
        TestCase.assertEquals("21", userPrefs.getSmtpPort());
        TestCase.assertEquals("47", userPrefs.getSslPort());
        TestCase.assertEquals("<EMAIL>", userPrefs.getSmtpUsername());
        TestCase.assertEquals("smtppass", userPrefs.getSmtpPassword());
        TestCase.assertEquals("10", userPrefs.getFilesizeChunkingCutoffMB());
        TestCase.assertEquals("10000", userPrefs.getNumRowsPerChunk());
    }

    @Test
    public void testLoadIncompletePreferencesWithClearStart() throws ParseException, BackingStoreException {
        UserPreferencesJava userPrefs = new UserPreferencesJava();
        userPrefs.clear();

        String[] args = {"-t", "LoadPreferences", "-c", "src/test/resources/simple_config.json"};
        Main.main(args);
        TestCase.assertEquals("https://someDomain.com", userPrefs.getDomain());
        TestCase.assertEquals("<EMAIL>", userPrefs.getUsername());
        TestCase.assertEquals("<PASSWORD>Password", userPrefs.getPassword());
        TestCase.assertEquals("5oMeTokEN", userPrefs.getAPIKey());
        TestCase.assertEquals("https://someDomain.com", userPrefs.getProxyHost());
        TestCase.assertEquals("8080", userPrefs.getProxyPort());
    }

    @Test
    public void testLoadIncompletePreferencesWithMessyStart() throws ParseException, BackingStoreException {
        // fill up java preference node with old junk
        UserPreferencesJava userPrefs = new UserPreferencesJava();
        String[] argsOld = {"-t", "LoadPreferences", "-c", "src/test/resources/basic_test_config.json"};
        Main.main(argsOld);

        // run new load job
        String[] argsNew = {"-t", "LoadPreferences", "-c", "src/test/resources/simple_config.json"};
        Main.main(argsNew);

        TestCase.assertEquals("https://someDomain.com", userPrefs.getDomain());
        TestCase.assertEquals("<EMAIL>", userPrefs.getUsername());
        TestCase.assertEquals("<PASSWORD>Password", userPrefs.getPassword());
        TestCase.assertEquals("5oMeTokEN", userPrefs.getAPIKey());
        TestCase.assertEquals("https://someDomain.com", userPrefs.getProxyHost());
        TestCase.assertEquals("8080", userPrefs.getProxyPort());
        TestCase.assertEquals("", userPrefs.getAdminEmail());
        TestCase.assertFalse(userPrefs.emailUponError());    // has default
        TestCase.assertEquals("", userPrefs.getLogDatasetID());
        TestCase.assertEquals("", userPrefs.getOutgoingMailServer());
        TestCase.assertEquals("", userPrefs.getSmtpPort());
        TestCase.assertEquals("465", userPrefs.getSslPort());    // has default
        TestCase.assertEquals("", userPrefs.getSmtpUsername());
        TestCase.assertEquals("", userPrefs.getSmtpPassword());
        TestCase.assertEquals("10", userPrefs.getFilesizeChunkingCutoffMB());     // has default
        TestCase.assertEquals("10000", userPrefs.getNumRowsPerChunk());     // has default
    }

    @Test
    public void testConfiguration() throws ParseException {
        String[] args = {"-c", "src/test/resources/basic_test_config.json"};
        job.configure(parser.parse(cmd.options, args));

        UserPreferences userPrefs = job.getUserPrefs();

        TestCase.assertEquals("https://sandbox.demo.socrata.com", userPrefs.getDomain());
        TestCase.assertEquals("<EMAIL>", userPrefs.getUsername());
        TestCase.assertEquals("OpenData", userPrefs.getPassword());
        TestCase.assertEquals("D8Atrg62F2j017ZTdkMpuZ9vY", userPrefs.getAPIKey());
        TestCase.assertEquals("<EMAIL>", userPrefs.getAdminEmail());
        TestCase.assertFalse(userPrefs.emailUponError());
        TestCase.assertEquals("smtp.something.com", userPrefs.getOutgoingMailServer());
        TestCase.assertEquals("21", userPrefs.getSmtpPort());
        TestCase.assertEquals("47", userPrefs.getSslPort());
        TestCase.assertEquals("<EMAIL>", userPrefs.getSmtpUsername());
        TestCase.assertEquals("smtppass", userPrefs.getSmtpPassword());
        TestCase.assertEquals("10", userPrefs.getFilesizeChunkingCutoffMB());
        TestCase.assertEquals("10000", userPrefs.getNumRowsPerChunk());
    }
}<commit_msg>Clearing out userPrefrences after test runs that load proxy information.<commit_after>package com.socrata.datasync.job;

import com.socrata.datasync.Main;
import com.socrata.datasync.config.CommandLineOptions;
import com.socrata.datasync.config.userpreferences.UserPreferences;
import com.socrata.datasync.config.userpreferences.UserPreferencesJava;
import junit.framework.TestCase;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.junit.Before;
import org.junit.Test;

import java.util.prefs.BackingStoreException;

public class LoadPreferencesJobTest {

    private LoadPreferencesJob job;
    CommandLineParser parser;
    CommandLineOptions cmd = new CommandLineOptions();

    @Before
    public void initialize() {
        job = new LoadPreferencesJob();
        parser = new PosixParser();
    }

    @Test
    public void testValidationOfArgs() throws ParseException {

        String[] goodArgs = {"-c", "myConfig.json"};
        String[] incompleteArgs = {"-t", "LoadPreferences"};

        TestCase.assertTrue(job.validateArgs(parser.parse(cmd.options, goodArgs)));
        TestCase.assertFalse(job.validateArgs(parser.parse(cmd.options, incompleteArgs)));
    }

    @Test
    public void testLoadCompletePreferencesWithClearStart() throws ParseException, BackingStoreException {
        UserPreferencesJava userPrefs = new UserPreferencesJava();
        userPrefs.clear();

        String[] args = {"-t", "LoadPreferences", "-c", "src/test/resources/basic_test_config.json"};
        Main.main(args);
        TestCase.assertEquals("https://sandbox.demo.socrata.com", userPrefs.getDomain());
        TestCase.assertEquals("<EMAIL>", userPrefs.getUsername());
        TestCase.assertEquals("OpenData", userPrefs.getPassword());
        TestCase.assertEquals("D8Atrg62F2j017ZTdkMpuZ9vY", userPrefs.getAPIKey());
        TestCase.assertEquals("<EMAIL>", userPrefs.getAdminEmail());
        TestCase.assertEquals(false, userPrefs.emailUponError());
        TestCase.assertEquals("", userPrefs.getLogDatasetID());
        TestCase.assertEquals("smtp.something.com", userPrefs.getOutgoingMailServer());
        TestCase.assertEquals("21", userPrefs.getSmtpPort());
        TestCase.assertEquals("47", userPrefs.getSslPort());
        TestCase.assertEquals("<EMAIL>", userPrefs.getSmtpUsername());
        TestCase.assertEquals("smtppass", userPrefs.getSmtpPassword());
        TestCase.assertEquals("10", userPrefs.getFilesizeChunkingCutoffMB());
        TestCase.assertEquals("10000", userPrefs.getNumRowsPerChunk());
    }

    @Test
    public void testLoadIncompletePreferencesWithClearStart() throws ParseException, BackingStoreException {
        UserPreferencesJava userPrefs = new UserPreferencesJava();
        userPrefs.clear();

        String[] args = {"-t", "LoadPreferences", "-c", "src/test/resources/simple_config.json"};
        Main.main(args);
        TestCase.assertEquals("https://someDomain.com", userPrefs.getDomain());
        TestCase.assertEquals("<EMAIL>", userPrefs.getUsername());
        TestCase.assertEquals("<PASSWORD>", userPrefs.getPassword());
        TestCase.assertEquals("5oMeTokEN", userPrefs.getAPIKey());
        TestCase.assertEquals("https://someDomain.com", userPrefs.getProxyHost());
        TestCase.assertEquals("8080", userPrefs.getProxyPort());
        userPrefs.clear();
    }

    @Test
    public void testLoadIncompletePreferencesWithMessyStart() throws ParseException, BackingStoreException {
        // fill up java preference node with old junk
        UserPreferencesJava userPrefs = new UserPreferencesJava();
        String[] argsOld = {"-t", "LoadPreferences", "-c", "src/test/resources/basic_test_config.json"};
        Main.main(argsOld);

        // run new load job
        String[] argsNew = {"-t", "LoadPreferences", "-c", "src/test/resources/simple_config.json"};
        Main.main(argsNew);

        TestCase.assertEquals("https://someDomain.com", userPrefs.getDomain());
        TestCase.assertEquals("<EMAIL>", userPrefs.getUsername());
        TestCase.assertEquals("<PASSWORD>", userPrefs.getPassword());
        TestCase.assertEquals("5oMeTokEN", userPrefs.getAPIKey());
        TestCase.assertEquals("https://someDomain.com", userPrefs.getProxyHost());
        TestCase.assertEquals("8080", userPrefs.getProxyPort());
        TestCase.assertEquals("", userPrefs.getAdminEmail());
        TestCase.assertFalse(userPrefs.emailUponError());    // has default
        TestCase.assertEquals("", userPrefs.getLogDatasetID());
        TestCase.assertEquals("", userPrefs.getOutgoingMailServer());
        TestCase.assertEquals("", userPrefs.getSmtpPort());
        TestCase.assertEquals("465", userPrefs.getSslPort());    // has default
        TestCase.assertEquals("", userPrefs.getSmtpUsername());
        TestCase.assertEquals("", userPrefs.getSmtpPassword());
        TestCase.assertEquals("10", userPrefs.getFilesizeChunkingCutoffMB());     // has default
        TestCase.assertEquals("10000", userPrefs.getNumRowsPerChunk());     // has default
        userPrefs.clear();
    }

    @Test
    public void testConfiguration() throws ParseException {
        String[] args = {"-c", "src/test/resources/basic_test_config.json"};
        job.configure(parser.parse(cmd.options, args));

        UserPreferences userPrefs = job.getUserPrefs();

        TestCase.assertEquals("https://sandbox.demo.socrata.com", userPrefs.getDomain());
        TestCase.assertEquals("<EMAIL>", userPrefs.getUsername());
        TestCase.assertEquals("OpenData", userPrefs.getPassword());
        TestCase.assertEquals("D8Atrg62F2j017ZTdkMpuZ9vY", userPrefs.getAPIKey());
        TestCase.assertEquals("<EMAIL>", userPrefs.getAdminEmail());
        TestCase.assertFalse(userPrefs.emailUponError());
        TestCase.assertEquals("smtp.something.com", userPrefs.getOutgoingMailServer());
        TestCase.assertEquals("21", userPrefs.getSmtpPort());
        TestCase.assertEquals("47", userPrefs.getSslPort());
        TestCase.assertEquals("<EMAIL>", userPrefs.getSmtpUsername());
        TestCase.assertEquals("smtppass", userPrefs.getSmtpPassword());
        TestCase.assertEquals("10", userPrefs.getFilesizeChunkingCutoffMB());
        TestCase.assertEquals("10000", userPrefs.getNumRowsPerChunk());
    }
}
{'fraction_non_alphanumeric': 0.13648231663897462, 'fraction_numerical': 0.0091779412928238, 'mean_word_length': 4.12363194162951, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 12, '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': '6647705', 'n_tokens_mistral': 3627, 'n_tokens_neox': 3397, 'n_words': 527}