Hello,
I'm facing some problems with my injected properties in my TestNG tests.
Probably this is very easy to solve, but I currently don't have the "right" idea.
The class to be tested is as follows:
@Name("entityManager")
@Scope(ScopeType.CONVERSATION)
@SuppressWarnings("unchecked")
public class EntityManager implements Serializable, PagedEntityManager {
/**
* The injected entity class name.
*/
@In(value = "#{entityClassName}", create=true)
private String m_overrideEntityClassName;
public void showEntity(){
...
//access the injected field
print(m_overrideEntityClassName);
}
}
public class EntityManagerTest
extends SeamTest {
@Test
public void testPersistEntity() throws Exception {
assert !super.isSessionInvalid();
new FacesRequest() {
@Override
protected void updateModelValues() throws Exception
{
//try to set the entityClassName
setValue("#{entityClassName}",
"Client");
}
@Override
protected void invokeApplication() throws Exception
{
//Invoke method that uses previously set entityClassName
invokeMethod("#{entityManager.showEntity()}");
}
}.run();
}
OK, I got it.
Instead of using setValue(..) it is necessary to write the desired value into a context, e.g. the SessionContext.
Contexts.getSessionContext()
.set("entityClassName",
"Client");