<commit_before>package br.eti.clairton.uniquevalidator;

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

import java.sql.Connection;
import java.util.Date;

import javax.inject.Inject;
import javax.naming.InitialContext;
import javax.persistence.EntityManager;
import javax.transaction.TransactionManager;
import javax.validation.Validator;

import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(CdiTestRunner.class)
public class UniqueValidatorTest {
	private final String protocol = "lkasdjfkwej" + new Date().getTime();
	private @Inject Validator validator;
	private @Inject EntityManager manager;

	@Before
	public void init() throws Exception {
		final InitialContext context = new InitialContext();
		final TransactionManager tm = (TransactionManager) context.lookup("java:/jboss/TransactionManager");
		tm.begin();
		final Connection connection = manager.unwrap(Connection.class);
		final String sql = "DELETE FROM model;";
		connection.createStatement().execute(sql);
		final Model model = new Model(protocol);
		manager.persist(model);
		manager.flush();
		manager.clear();
		tm.commit();
	}

	@Test
	public void testIsInValid() {
		final Model model = new Model(protocol);
		assertFalse(validator.validateProperty(model, "protocol").isEmpty());
	}

	@Test
	public void testIsValid() {
		final Model model = new Model(protocol + new Date().getTime());
		assertTrue(validator.validateProperty(model, "protocol").isEmpty());
	}
}<commit_msg>Test for unique in update<commit_after>package br.eti.clairton.uniquevalidator;

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

import java.sql.Connection;
import java.util.Date;

import javax.inject.Inject;
import javax.naming.InitialContext;
import javax.persistence.EntityManager;
import javax.transaction.TransactionManager;
import javax.validation.Validator;

import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(CdiTestRunner.class)
public class UniqueValidatorTest {
	private final String protocol = "lkasdjfkwej" + new Date().getTime();
	private @Inject Validator validator;
	private @Inject EntityManager manager;
	private Model model;

	@Before
	public void init() throws Exception {
		final InitialContext context = new InitialContext();
		final TransactionManager tm = (TransactionManager) context.lookup("java:/jboss/TransactionManager");
		tm.begin();
		final Connection connection = manager.unwrap(Connection.class);
		final String sql = "DELETE FROM model;";
		connection.createStatement().execute(sql);
		model = new Model(protocol);
		manager.persist(model);
		manager.flush();
		manager.clear();
		tm.commit();
	}

	@Test
	public void testIsInValid() {
		final Model model = new Model(protocol);
		assertFalse(validator.validateProperty(model, "protocol").isEmpty());
	}

	@Test
	public void testIsValid() {
		final Model model = new Model(protocol + new Date().getTime());
		assertTrue(validator.validateProperty(model, "protocol").isEmpty());
	}

	@Test
	public void testIsValidWhenUpdate() {
		assertTrue(validator.validateProperty(model, "protocol").isEmpty());
	}
}
{'fraction_non_alphanumeric': 0.11609022556390977, 'fraction_numerical': 0.0, 'mean_word_length': 5.829568788501026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3957747', 'n_tokens_mistral': 991, 'n_tokens_neox': 959, 'n_words': 231}