<commit_before>package ca.uhnresearch.pughlab.tracker.scripting;

import static org.easymock.EasyMock.*;

import org.junit.Test;
import org.junit.Assert;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

import org.springframework.core.io.Resource;

public class ScriptManagerTest {

	/**
	 * Checks successful instantiation
	 * @throws IOException
	 */
	@Test
	public void testSuccessfulInstantiation() throws IOException {
		
		String inputString = "";
		
		InputStream input = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
		
		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubReturn(input);
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		Assert.assertNotNull(manager);
	}

	/**
	 * Checks that even when the resource open fails, we get a script manager.
	 * @throws IOException
	 */
	@Test
	public void testFailingInstantiation() throws IOException {
		
		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubThrow(new IOException("Failed to open resource"));
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		Assert.assertNotNull(manager);
	}

	/**
	 * Checks that even when the resource open fails, we get a script manager.
	 * @throws IOException
	 */
	@Test
	public void testFailingScript() throws IOException {
		
		String inputString = "function foo() { ";
		
		InputStream input = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));

		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubReturn(input);
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		Assert.assertNotNull(manager);
	}
	
	/**
	 * Checks successful instantiation
	 * @throws IOException
	 */
	@Test
	public void testBindings() throws IOException {
		
		String inputString = "test = test + 1; console.log('Value should be 123:', test);";
		
		InputStream input = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
		
		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubReturn(input);
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		bindings.put("test", 122);
		bindings.put("console", new JSLogger());
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		Assert.assertNotNull(manager);
	}
}<commit_msg>Added a regression test to make sure we call the execute method<commit_after>package ca.uhnresearch.pughlab.tracker.scripting;

import static org.easymock.EasyMock.*;

import org.junit.Test;
import org.junit.Assert;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

import org.quartz.JobExecutionException;
import org.springframework.core.io.Resource;

public class ScriptManagerTest {

	/**
	 * Checks successful instantiation
	 * @throws IOException
	 */
	@Test
	public void testSuccessfulInstantiation() throws IOException {
		
		String inputString = "";
		
		InputStream input = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
		
		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubReturn(input);
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		Assert.assertNotNull(manager);
	}

	/**
	 * Checks that even when the resource open fails, we get a script manager.
	 * @throws IOException
	 */
	@Test
	public void testFailingInstantiation() throws IOException {
		
		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubThrow(new IOException("Failed to open resource"));
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		Assert.assertNotNull(manager);
	}

	/**
	 * Checks that even when the resource open fails, we get a script manager.
	 * @throws IOException
	 */
	@Test
	public void testFailingScript() throws IOException {
		
		String inputString = "function foo() { ";
		
		InputStream input = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));

		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubReturn(input);
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		Assert.assertNotNull(manager);
	}
	
	/**
	 * Checks successful instantiation
	 * @throws IOException
	 */
	@Test
	public void testBindings() throws IOException {
		
		String inputString = "test = test + 1; console.log('Value should be 123:', test);";
		
		InputStream input = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
		
		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubReturn(input);
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		bindings.put("test", 122);
		bindings.put("console", new JSLogger());
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		Assert.assertNotNull(manager);
	}

	/**
	 * Checks successful instantiation
	 * @throws IOException
	 * @throws JobExecutionException 
	 */
	@Test
	public void testExecute() throws IOException, JobExecutionException {
		
		String inputString = "";
		
		InputStream input = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
		
		Resource resource = createMock(Resource.class);
		expect(resource.getInputStream()).andStubReturn(input);
		expect(resource.getURL()).andStubReturn(new URL("file:///"));
		replay(resource);
		
		Map<String, Object> bindings = new HashMap<String, Object>();
		bindings.put("test", 122);
		bindings.put("console", new JSLogger());
		
		ScriptManager manager = new ScriptManager(resource, bindings);
		manager.execute();
	}
}
{'fraction_non_alphanumeric': 0.12407512805919181, 'fraction_numerical': 0.003414911781445646, 'mean_word_length': 5.043852106620808, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '1118996', 'n_tokens_mistral': 2167, 'n_tokens_neox': 1900, 'n_words': 467}