<commit_before>package org.openur.module.persistence.rdbms.repository.userstructure;

import static org.junit.Assert.*;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.PersistenceException;

import org.apache.commons.collections4.CollectionUtils;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openur.module.domain.userstructure.Status;
import org.openur.module.persistence.rdbms.config.RepositoryConfig;
import org.openur.module.persistence.rdbms.entity.PAddress;
import org.openur.module.persistence.rdbms.entity.PApplication;
import org.openur.module.persistence.rdbms.entity.PPerson;
import org.openur.module.persistence.rdbms.repository.PersonRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

@ContextConfiguration(classes = { RepositoryConfig.class })
@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)
public class PersonRepositoryTest
{
	private final String EMPLOYEE_NUMBER = "123abc";
	
	@Inject
	private PersonRepository personRepository;

	@Test
	public void testFindPersonByNumber()
	{		
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "Name of Employee");
		
		persistable = savePerson(persistable);
		
		PPerson p = findPersonByNumber(EMPLOYEE_NUMBER);
		
		assertNotNull(p);
		assertEquals(p, persistable);
	}
	
	@Test
	public void testCreateWithAddressAndApplication()
	{	
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "Name of Employee");
		
		PAddress pAddress = new PAddress("11");		
		persistable.setHomeAddress(pAddress);
		
		PApplication pApp = new PApplication("applicationName");
		persistable.addApplication(pApp);
		
		persistable = savePerson(persistable);
		
		List<PPerson> allPersons = findAllPersons();
		
		assertNotNull(allPersons);
		assertEquals(allPersons.size(), 1);
		PPerson p = allPersons.get(0);
		assertEquals(p, persistable);
		
		assertNotNull(p.getApplications());
		assertTrue(CollectionUtils.isNotEmpty(p.getApplications()));
		PApplication pa = p.getApplications().iterator().next();
		assertEquals(pa, pApp);
		
		assertNotNull(p.getHomeAddress());
		PAddress pAdr = p.getHomeAddress();
		assertEquals(pAdr, pAddress);
	}
	
	@Test
	public void testAddApplicationsToPerson()
	{	
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "<NAME> Employee");		
		persistable = savePerson(persistable);
		PPerson p = findPersonByNumber(EMPLOYEE_NUMBER);
		assertEquals(p.getApplications().size(), 0);
		
		PApplication pApp = new PApplication("applicationName");
		persistable.addApplication(pApp);		
		persistable = savePerson(persistable);
		p = findPersonByNumber(EMPLOYEE_NUMBER);
		assertEquals(p.getApplications().size(), 1);
		
		PApplication pApp2 = new PApplication("applicationName2");
		persistable.addApplication(pApp2);		
		persistable = savePerson(persistable);		
		p = findPersonByNumber(EMPLOYEE_NUMBER);
		assertEquals(p.getApplications().size(), 2);
	}
	
	@Test(expected = PersistenceException.class)
	public void testAddPersonWithSameEmployeeNumber()
	{	
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "Name of Employee");		
		persistable = savePerson(persistable);
		
		persistable = new PPerson(EMPLOYEE_NUMBER, "Name of Employee with same number");		
		persistable = savePerson(persistable);
	}
	
	@Test
	public void testModify()
	{	
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "Name of Employee");
		persistable = savePerson(persistable);
		assertNull(persistable.getLastModifiedDate());
		
		persistable.setStatus(Status.INACTIVE);		
		persistable = savePerson(persistable);		
		assertNotNull(persistable.getLastModifiedDate());
	}
	
	@After
	@Transactional(readOnly = false)
	public void deleteAllEntries()
	{
		personRepository.deleteAll();
	}
	
	@Transactional(readOnly = false)
	private PPerson savePerson(PPerson persistable)
	{
		return personRepository.save(persistable);
	}

	@Transactional(readOnly = true)
	private List<PPerson> findAllPersons()
	{
		return personRepository.findAll();
	}

	@Transactional(readOnly = true)
	private PPerson findPersonByNumber(String employeeNumber)
	{
		return personRepository.findPersonByNumber(employeeNumber);<commit_msg>rename method 'deleteAllEntries' to 'cleanUpDatabase'<commit_after>package org.openur.module.persistence.rdbms.repository.userstructure;

import static org.junit.Assert.*;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.PersistenceException;

import org.apache.commons.collections4.CollectionUtils;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openur.module.domain.userstructure.Status;
import org.openur.module.persistence.rdbms.config.RepositoryConfig;
import org.openur.module.persistence.rdbms.entity.PAddress;
import org.openur.module.persistence.rdbms.entity.PApplication;
import org.openur.module.persistence.rdbms.entity.PPerson;
import org.openur.module.persistence.rdbms.repository.PersonRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

@ContextConfiguration(classes = { RepositoryConfig.class })
@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)
public class PersonRepositoryTest
{
	private final String EMPLOYEE_NUMBER = "123abc";
	
	@Inject
	private PersonRepository personRepository;

	@Test
	public void testFindPersonByNumber()
	{		
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "<NAME>");
		
		persistable = savePerson(persistable);
		
		PPerson p = findPersonByNumber(EMPLOYEE_NUMBER);
		
		assertNotNull(p);
		assertEquals(p, persistable);
	}
	
	@Test
	public void testCreateWithAddressAndApplication()
	{	
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "<NAME>");
		
		PAddress pAddress = new PAddress("11");		
		persistable.setHomeAddress(pAddress);
		
		PApplication pApp = new PApplication("applicationName");
		persistable.addApplication(pApp);
		
		persistable = savePerson(persistable);
		
		List<PPerson> allPersons = findAllPersons();
		
		assertNotNull(allPersons);
		assertEquals(allPersons.size(), 1);
		PPerson p = allPersons.get(0);
		assertEquals(p, persistable);
		
		assertNotNull(p.getApplications());
		assertTrue(CollectionUtils.isNotEmpty(p.getApplications()));
		PApplication pa = p.getApplications().iterator().next();
		assertEquals(pa, pApp);
		
		assertNotNull(p.getHomeAddress());
		PAddress pAdr = p.getHomeAddress();
		assertEquals(pAdr, pAddress);
	}
	
	@Test
	public void testAddApplicationsToPerson()
	{	
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "<NAME>");		
		persistable = savePerson(persistable);
		PPerson p = findPersonByNumber(EMPLOYEE_NUMBER);
		assertEquals(p.getApplications().size(), 0);
		
		PApplication pApp = new PApplication("applicationName");
		persistable.addApplication(pApp);		
		persistable = savePerson(persistable);
		p = findPersonByNumber(EMPLOYEE_NUMBER);
		assertEquals(p.getApplications().size(), 1);
		
		PApplication pApp2 = new PApplication("applicationName2");
		persistable.addApplication(pApp2);		
		persistable = savePerson(persistable);		
		p = findPersonByNumber(EMPLOYEE_NUMBER);
		assertEquals(p.getApplications().size(), 2);
	}
	
	@Test(expected = PersistenceException.class)
	public void testAddPersonWithSameEmployeeNumber()
	{	
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "Name of Employee");		
		persistable = savePerson(persistable);
		
		persistable = new PPerson(EMPLOYEE_NUMBER, "Name of Employee with same number");		
		persistable = savePerson(persistable);
	}
	
	@Test
	public void testModify()
	{	
		PPerson persistable = new PPerson(EMPLOYEE_NUMBER, "<NAME> Employee");
		persistable = savePerson(persistable);
		assertNull(persistable.getLastModifiedDate());
		
		persistable.setStatus(Status.INACTIVE);		
		persistable = savePerson(persistable);		
		assertNotNull(persistable.getLastModifiedDate());
	}
	
	@After
	@Transactional(readOnly = false)
	public void cleanUpDatabase()
	{
		personRepository.deleteAll();
	}
	
	@Transactional(readOnly = false)
	private PPerson savePerson(PPerson persistable)
	{
		return personRepository.save(persistable);
	}

	@Transactional(readOnly = true)
	private List<PPerson> findAllPersons()
	{
		return personRepository.findAll();
	}

	@Transactional(readOnly = true)
	private PPerson findPersonByNumber(String employeeNumber)
	{
		return personRepository.findPersonByNumber(employeeNumber);
{'fraction_non_alphanumeric': 0.1070815696144606, 'fraction_numerical': 0.0038897151355680127, 'mean_word_length': 6.010425020048116, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '383331', 'n_tokens_mistral': 2941, 'n_tokens_neox': 2644, 'n_words': 463}