SeamTest with TestNG problem!
vmoa Apr 9, 2008 3:44 PMHi all, my problem is just this: I have this test class:
public class PersonServiceTest extends SeamTest{ @Test public void AddTest() throws Exception{ new ComponentTest(){ @Override protected void testComponents() throws Exception { Person p = (Person) Component.getInstance("br.org.entity.Person", true); p.setName("Name"); Service serv = (Service) Component.getInstance("br.org.service.Service", true); assert serv != null; } }.run(); } }
Well, when I execute the TestNG test, this line works fine:
Person p = (Person) Component.getInstance("br.org.entity.Person", true);
But the line:
Service serv = (Service) Component.getInstance("br.org.service.Service", true);
returns serv as null value (verified by debug mode). Why this?
My classes are:
@Entity @Name("br.org.entity.Person") public class Person implements Serializable{ private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @NotNull private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
and:
@Local public interface Service { public String addPerson(); }
and:
@Stateless @Name("br.org.service.Service") @TransactionAttribute(javax.ejb.TransactionAttributeType.MANDATORY) public class ServiceImpl implements Service{ @In(value = "br.org.repository.PersonRepository", create = true, required = true) private PersonRepository personRepository; public ServiceImpl() { } public PersonRepository getPersonRespository() { return this.personRepository; } public void setPersonRespository(PersonRepository personRepository) { this.personRepository = personRepository; } public String addPerson() { personRepository.persist(); return "ok"; } }
this is the TestNG error:
java.lang.AssertionError at br.org.test.PersonServiceTest$1.testComponents(PersonServiceTest.java:21) at org.jboss.seam.mock.BaseSeamTest$ComponentTest.run(BaseSeamTest.java:169) at br.org.test.PersonServiceTest.AddTest(PersonServiceTest.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580) at org.testng.internal.Invoker.invokeMethod(Invoker.java:478) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:607) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:874) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.runWorkers(TestRunner.java:689) at org.testng.TestRunner.privateRun(TestRunner.java:566) at org.testng.TestRunner.run(TestRunner.java:466) at org.testng.SuiteRunner.runTest(SuiteRunner.java:301) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:296) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:276) at org.testng.SuiteRunner.run(SuiteRunner.java:191) at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808) at org.testng.TestNG.runSuitesLocally(TestNG.java:776) at org.testng.TestNG.run(TestNG.java:701) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)