<commit_before>package com.redhat.victims;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.redhat.victims.database.VictimsDB;
import com.redhat.victims.database.VictimsDBInterface;
import com.redhat.victims.mock.MockEnvironment;

public class VictimsDatabaseTest {
	private static final String TEST_SHA512 = "testdata/service/test.sha512";
	private static final String TEST_CVE = "testdata/service/test.cve";

	@BeforeClass
	public static void setUp() throws IOException {
		MockEnvironment.setUp();
	}

	@AfterClass
	public static void tearDown() {
		MockEnvironment.tearDown();
	}

	@Test
	public void testSynchronize() throws VictimsException, IOException {
		VictimsDBInterface vdb = VictimsDB.db();
		vdb.synchronize();
		String sha512 = FileUtils.readFileToString(new File(TEST_SHA512))
				.trim();
		String cve = FileUtils.readFileToString(new File(TEST_CVE)).trim();
		assertTrue("Synchronized DB does not contain expected hash.", vdb
				.getVulnerabilities(sha512).contains(cve));
	}
}<commit_msg>Added test case validating embedded hashes check.<commit_after>package com.redhat.victims;

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

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashSet;

import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.redhat.victims.VictimsService.RecordStream;
import com.redhat.victims.database.VictimsDB;
import com.redhat.victims.database.VictimsDBInterface;
import com.redhat.victims.fingerprint.Algorithms;
import com.redhat.victims.mock.MockEnvironment;

public class VictimsDatabaseTest {
	private static final String TEST_RESPONSE = "testdata/service/test.response";
	private static final String TEST_SHA512 = "testdata/service/test.sha512";
	private static final String TEST_CVE = "testdata/service/test.cve";

	private VictimsDBInterface vdb;

	@BeforeClass
	public static void setUp() throws IOException {
		MockEnvironment.setUp();
	}

	@AfterClass
	public static void tearDown() {
		MockEnvironment.tearDown();
	}

	@Before
	public void setVDB() throws VictimsException {
		vdb = VictimsDB.db();
		vdb.synchronize();
	}

	@Test
	public void testSynchronize() throws VictimsException, IOException {
		String sha512 = FileUtils.readFileToString(new File(TEST_SHA512))
				.trim();
		String cve = FileUtils.readFileToString(new File(TEST_CVE)).trim();
		assertTrue("Synchronized DB does not contain expected hash.", vdb
				.getVulnerabilities(sha512).contains(cve));
	}

	private HashSet<String> getVulnerabilities(VictimsRecord vr)
			throws VictimsException {
		return vdb.getVulnerabilities(vr);
	}

	@Test
	public void testVulnerabilities() throws IOException, VictimsException {
		FileInputStream fin = new FileInputStream(TEST_RESPONSE);
		RecordStream rs = new RecordStream(fin);
		VictimsRecord vr;
		while (rs.hasNext()) {
			vr = rs.getNext();
			HashSet<String> cves = getVulnerabilities(vr);
			vr.hash = "0";
			if (vr.getHashes(Algorithms.SHA512).size() > 0) {
				HashSet<String> result = getVulnerabilities(vr);
				assertEquals("Unexpected number of CVEs", cves.size(),
						result.size());
				for (String cve : cves) {
					assertTrue(String.format(
							"%s was expected, but was not found in result.",
							cve), result.contains(cve));
				}
				break;
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.10874377421140011, 'fraction_numerical': 0.009684560044272275, 'mean_word_length': 4.985099337748345, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '3312411', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1152, 'n_words': 258}