<commit_before>package com.blackducksoftware.integration.hub;

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

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import com.blackducksoftware.integration.hub.response.AutoCompleteItem;
import com.blackducksoftware.integration.hub.response.DistributionEnum;
import com.blackducksoftware.integration.hub.response.PhaseEnum;
import com.blackducksoftware.integration.hub.response.ProjectItem;
import com.blackducksoftware.integration.hub.response.ReleaseItem;
import com.blackducksoftware.integration.hub.response.VersionComparison;
import com.blackducksoftware.integration.hub.util.HubIntTestHelper;
import com.blackducksoftware.integration.hub.util.TestLogger;

public class HubIntRestServiceTest {

    private static Properties testProperties;

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

    @BeforeClass
    public static void testInit() {
        testProperties = new Properties();
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream is = classLoader.getResourceAsStream("test.properties");
        try {
            testProperties.load(is);
        } catch (IOException e) {
            System.err.println("reading test.properties failed!");
        }
        // p.load(new FileReader(new File("test.properties")));
        System.out.println(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        System.out.println(testProperties.getProperty("TEST_USERNAME"));
        System.out.println(testProperties.getProperty("TEST_PASSWORD"));

    }

    @Test
    public void testSetCookies() throws Exception {
        TestLogger logger = new TestLogger();

        HubIntRestService restService = new HubIntRestService(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        restService.setLogger(logger);
        restService.setCookies(testProperties.getProperty("TEST_USERNAME"), testProperties.getProperty("TEST_PASSWORD"));

        assertNotNull(restService.getCookies());
        assertTrue(!restService.getCookies().isEmpty());
        assertTrue(logger.getErrorList().isEmpty());
    }

    @Test
    public void testSetTimeoutZero() throws Exception {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("Can not set the timeout to zero.");
        HubIntRestService restService = new HubIntRestService(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        restService.setTimeout(0);
    }

    @Test
    public void testSetTimeout() throws Exception {
        TestLogger logger = new TestLogger();
        HubIntRestService restService = new HubIntRestService(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        restService.setTimeout(120);
        restService.setLogger(logger);
        restService.setCookies(testProperties.getProperty("TEST_USERNAME"), testProperties.getProperty("TEST_PASSWORD"));

        assertNotNull(restService.getCookies());
        assertTrue(!restService.getCookies().isEmpty());
        assertTrue(logger.getErrorList().isEmpty());
    }

    @Test
    public void testGetProjectMatches() throws Exception {
        TestLogger logger = new TestLogger();

        HubIntRestService restService = new HubIntRestService(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        restService.setLogger(logger);
        restService.setCookies(testProperties.getProperty("TEST_USERNAME"), testProperties.getProperty("TEST_PASSWORD"));

        List<AutoCompleteItem> matches = restService.getProjectMatches(testProperties.getProperty("TEST_PROJECT"));

        assertNotNull("matches must be not null", matches);
        // FIXME, why can we expect this project to have matches? assertTrue("matches expected to be not empty",
        // !matches.isEmpty());
        assertTrue("error log expected to be empty", logger.getErrorList().isEmpty());
    }<commit_msg>Fixing unit test, should no longer fail<commit_after>package com.blackducksoftware.integration.hub;

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

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import com.blackducksoftware.integration.hub.response.AutoCompleteItem;
import com.blackducksoftware.integration.hub.response.DistributionEnum;
import com.blackducksoftware.integration.hub.response.PhaseEnum;
import com.blackducksoftware.integration.hub.response.ProjectItem;
import com.blackducksoftware.integration.hub.response.ReleaseItem;
import com.blackducksoftware.integration.hub.response.VersionComparison;
import com.blackducksoftware.integration.hub.util.HubIntTestHelper;
import com.blackducksoftware.integration.hub.util.TestLogger;

public class HubIntRestServiceTest {

    private static Properties testProperties;

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

    @BeforeClass
    public static void testInit() {
        testProperties = new Properties();
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream is = classLoader.getResourceAsStream("test.properties");
        try {
            testProperties.load(is);
        } catch (IOException e) {
            System.err.println("reading test.properties failed!");
        }
        // p.load(new FileReader(new File("test.properties")));
        System.out.println(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        System.out.println(testProperties.getProperty("TEST_USERNAME"));
        System.out.println(testProperties.getProperty("TEST_PASSWORD"));

    }

    @Test
    public void testSetCookies() throws Exception {
        TestLogger logger = new TestLogger();

        HubIntRestService restService = new HubIntRestService(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        restService.setLogger(logger);
        restService.setCookies(testProperties.getProperty("TEST_USERNAME"), testProperties.getProperty("TEST_PASSWORD"));

        assertNotNull(restService.getCookies());
        assertTrue(!restService.getCookies().isEmpty());
        assertTrue(logger.getErrorList().isEmpty());
    }

    @Test
    public void testSetTimeoutZero() throws Exception {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("Can not set the timeout to zero.");
        HubIntRestService restService = new HubIntRestService(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        restService.setTimeout(0);
    }

    @Test
    public void testSetTimeout() throws Exception {
        TestLogger logger = new TestLogger();
        HubIntRestService restService = new HubIntRestService(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        restService.setTimeout(120);
        restService.setLogger(logger);
        restService.setCookies(testProperties.getProperty("TEST_USERNAME"), testProperties.getProperty("TEST_PASSWORD"));

        assertNotNull(restService.getCookies());
        assertTrue(!restService.getCookies().isEmpty());
        assertTrue(logger.getErrorList().isEmpty());
    }

    @Test
    public void testGetProjectMatches() throws Exception {
        TestLogger logger = new TestLogger();

        HubIntRestService restService = new HubIntRestService(testProperties.getProperty("TEST_HUB_SERVER_URL"));
        restService.setLogger(logger);
        restService.setCookies(testProperties.getProperty("TEST_USERNAME"), testProperties.getProperty("TEST_PASSWORD"));
        String testProjectName = "TESTNAME";
        String projectId = null;
        try {

            projectId = restService.createHubProject(testProjectName);

            List<AutoCompleteItem> matches = restService.getProjectMatches(testProjectName);

            assertNotNull("matches must be not null", matches);
            assertTrue(!matches.isEmpty());
            assertTrue("error log expected to be empty", logger.getErrorList().isEmpty());
        } finally {
            if (StringUtils.isNotBlank(projectId)) {
                HubIntTestHelper helper = new HubIntTestHelper(restService);
                helper.deleteHubProject(projectId);
            }
        }
    }
{'fraction_non_alphanumeric': 0.10170454545454545, 'fraction_numerical': 0.0011363636363636363, 'mean_word_length': 4.161876832844575, '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': '4362984', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2245, 'n_words': 405}