<commit_before>package eu.choreos.gmond;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import eu.choreos.gmond.reloader.GmondReloader;

public class GmondConfTest {

	private GmondConf gmondConf;
	private File exampleFile;
	private File testFile;
	private File testMultipleFile;
	private File exampleMultipleFile;

	@Before
	public void setUp() throws IOException {
		gmondConf = new GmondConf();
		exampleFile = new File(ClassLoader.getSystemResource(
				"gmond.conf.template").getFile());
		testFile = new File("gmond.conf");

		FileUtils.copyFile(exampleFile, testFile);

		exampleMultipleFile = new File(ClassLoader.getSystemResource(
				"gmondmultipleudp.conf.template").getFile());
		testMultipleFile = new File("gmondMultiple.conf");

		FileUtils.copyFile(exampleMultipleFile, testMultipleFile);
		GmondReloader mockedReloader = mock(GmondReloader.class);
		when(mockedReloader.reload()).thenReturn(true);
		gmondConf.setReloader(mockedReloader);
	}

	@After
	public void tearDown() {
		FileUtils.deleteQuietly(testFile);
	}

	@Test
	public void shouldAddUdpSendChannel() throws IOException {
		String fileContents = FileUtils.readFileToString(testFile);
		assertFalse(fileContents.contains("host = 127.0.0.1"));

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.addUdpSendChannel("127.0.0.1", "8649");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertTrue(fileContents.contains("host = 127.0.0.1"));
	}

	@Test
	public void shouldRemoveUdpSendChannel() throws IOException {
		String fileContents = FileUtils.readFileToString(testFile);
		assertTrue(fileContents.contains("host = eclipse.ime.usp.br"));

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.removeUdpSendChannel("eclipse.ime.usp.br");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertFalse(fileContents.contains("host = eclipse.ime.usp.br"));
	}

	@Test
	public void shouldChangeChannelHost() throws IOException {

		String fileContents = FileUtils.readFileToString(testFile);
		assertTrue(fileContents.contains("host = eclipse.ime.usp.br"));
		assertFalse(fileContents.contains("host = localhost"));

		int location = fileContents.indexOf("host = eclipse.ime.usp.br");

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.updateUdpSendChannelHost("eclipse.ime.usp.br", "localhost");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertFalse("Original line was found!",
				fileContents.contains("host = eclipse.ime.usp.br"));
		assertTrue("Altered line not located!",
				fileContents.contains("host = localhost"));

		assertEquals(location, fileContents.indexOf("host = localhost"));
	}

	@Test
	public void shouldChangeChannelPort() throws IOException {

		String fileContents = FileUtils.readFileToString(testFile);
		assertFalse(fileContents.contains("port = 1234"));

		int location = fileContents.indexOf("port = 8649");

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.updateUdpSendChannelPort("eclipse.ime.usp.br", "1234");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertTrue("Altered line not located!",
				fileContents.contains("port = 1234"));

		assertEquals(location, fileContents.indexOf("port = 1234"));
	}
	@Test
	public void shouldChangeChannelHostAndPort() throws IOException {

		String fileContents = FileUtils.readFileToString(testFile);
		assertFalse(fileContents.contains("port = 1234"));

		int location = fileContents.indexOf("port = 8649");

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.updateUdpSendChannel("eclipse.ime.usp.br", "localhost", "1234");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertTrue("Altered port not located!",
				fileContents.contains("port = 1234"));
		assertFalse("Previous port not removed!",
				fileContents.contains("port = 8649"));
		assertTrue("Altered host not located!",
				fileContents.contains("host = localhost"));
		assertFalse("Previous host not removed!",
				fileContents.contains("host = eclipse.ime.usp.br"));

		assertEquals(location, fileContents.indexOf("port = 1234"));
	}<commit_msg>testing to check github hook<commit_after>package eu.choreos.gmond;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import eu.choreos.gmond.reloader.GmondReloader;

public class GmondConfTest {

	private GmondConf gmondConf;
	private File exampleFile;
	private File testFile;
	private File testMultipleFile;
	private File exampleMultipleFile;

	@Before
	public void setUp() throws IOException {
		gmondConf = new GmondConf();
		exampleFile = new File(ClassLoader.getSystemResource(
				"gmond.conf.template").getFile());
		testFile = new File("gmond.conf");

		FileUtils.copyFile(exampleFile, testFile);

		exampleMultipleFile = new File(ClassLoader.getSystemResource(
				"gmondmultipleudp.conf.template").getFile());
		testMultipleFile = new File("gmondMultiple.conf");

		FileUtils.copyFile(exampleMultipleFile, testMultipleFile);
		GmondReloader mockedReloader = mock(GmondReloader.class);
		when(mockedReloader.reload()).thenReturn(true);
		gmondConf.setReloader(mockedReloader);
	}

	@After
	public void tearDown() {
		FileUtils.deleteQuietly(testFile);
	}

	@Test
	public void shouldAddUdpSendChannel() throws IOException {
		String fileContents = FileUtils.readFileToString(testFile);
		assertFalse(fileContents.contains("host = 127.0.0.1"));

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.addUdpSendChannel("127.0.0.1", "8649");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertTrue(fileContents.contains("host = 127.0.0.1"));
	}

	@Test
	public void shouldRemoveUdpSendChannel() throws IOException {
		String fileContents = FileUtils.readFileToString(testFile);
		assertTrue(fileContents.contains("host = eclipse.ime.usp.br"));

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.removeUdpSendChannel("eclipse.ime.usp.br");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertFalse(fileContents.contains("host = eclipse.ime.usp.br"));
	}

	@Test
	public void shouldChangeChannelHost() throws IOException {

		String fileContents = FileUtils.readFileToString(testFile);
		assertTrue(fileContents.contains("host = eclipse.ime.usp.br"));
		assertFalse(fileContents.contains("host = localhost"));

		int location = fileContents.indexOf("host = eclipse.ime.usp.br");

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.updateUdpSendChannelHost("eclipse.ime.usp.br", "localhost");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertFalse("Original line was found!",
				fileContents.contains("host = eclipse.ime.usp.br"));
		assertTrue("Altered line not located!",
				fileContents.contains("host = localhost"));

		assertEquals(location, fileContents.indexOf("host = localhost"));
	}

	@Test
	public void shouldChangeChannelPort() throws IOException {

		String fileContents = FileUtils.readFileToString(testFile);
		assertFalse(fileContents.contains("port = 1234"));

		int location = fileContents.indexOf("port = 8649");

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.updateUdpSendChannelPort("eclipse.ime.usp.br", "1234");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertTrue("Altered line not located!",
				fileContents.contains("port = 1234"));

		assertEquals(location, fileContents.indexOf("port = 1234"));
	}
	
	@Test
	public void shouldChangeChannelHostAndPort() throws IOException {

		String fileContents = FileUtils.readFileToString(testFile);
		assertFalse(fileContents.contains("port = 1234"));

		int location = fileContents.indexOf("port = 8649");

		gmondConf.load(testFile.getAbsolutePath());
		gmondConf.updateUdpSendChannel("eclipse.ime.usp.br", "localhost", "1234");
		gmondConf.save();

		fileContents = FileUtils.readFileToString(testFile);

		assertTrue("Altered port not located!",
				fileContents.contains("port = 1234"));
		assertFalse("Previous port not removed!",
				fileContents.contains("port = 8649"));
		assertTrue("Altered host not located!",
				fileContents.contains("host = localhost"));
		assertFalse("Previous host not removed!",
				fileContents.contains("host = eclipse.ime.usp.br"));

		assertEquals(location, fileContents.indexOf("port = 1234"));
	}
{'fraction_non_alphanumeric': 0.12848108288028404, 'fraction_numerical': 0.014645512038167092, 'mean_word_length': 5.865194211728865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '6437658', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2683, 'n_words': 486}