Olá Pessoal!
Mais uma vez venho pedir a ajuda de voces.
Há uma tabela que o campo codEntidade tem um chek de unique … preciso realizar o teste (testNG) para garantir que não haverá codEntidade duplicado (esse campo não é pk)
Fiz conforme abaixo, porém esta dando erro.
Abaixo segue o código e o erro apresentado
[code]public class EntidadeFiliacaoServiceTest extends WebTransactionalSpringTestSupport {
@Autowired
private EntidadeFiliacaoService entidadeFiliacaoService;
@Override
public String getStore() {
return "C:/dev/store";
}
@Test(expectedExceptions = ConstraintViolationException.class)
public void createCodEntidadeDuplicado() throws Exception {
EntidadeFiliacao entidade = new EntidadeFiliacao();
entidade.setCodEntidade(101L);
entidade.setNomeEntidade("Entidade teste 101");
entidade.setIdOperadorInclusao((long) 1);
entidade.setDataInclusao(new Date());
this.entidadeFiliacaoService.create(entidade);
}
}[/code]
Erro:
FAILED: createCodEntidadeDuplicado
org.testng.TestException:
Expected exception org.hibernate.exception.ConstraintViolationException but got org.testng.TestException:
Method EntidadeFiliacaoServiceTest.createCodEntidadeDuplicado()[pri:0, instance:org.spcbrasil.filiacaoweb.model.service.EntidadeFiliacaoServiceTest@1ce6942e] should have thrown an exception of class org.hibernate.exception.ConstraintViolationException
at org.testng.internal.Invoker.handleInvocationResults(Invoker.java:1497)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1245)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.testng.TestException:
Method EntidadeFiliacaoServiceTest.createCodEntidadeDuplicado()[pri:0, instance:org.spcbrasil.filiacaoweb.model.service.EntidadeFiliacaoServiceTest@1ce6942e] should have thrown an exception of class org.hibernate.exception.ConstraintViolationException
at org.testng.internal.Invoker.handleInvocationResults(Invoker.java:1512)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:754)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
... 16 more
Agradeço desde já!