Could not instantiate Seam component
mpancotti Oct 5, 2005 9:08 PMI'm trying to write an application an, just to avoid problems, I'm writing it as a new package of the booking example, using the same ant and deployment file (booking is running and testNG is working for the booking code).
I wrote an entity bean and an action that should be the same as part of the HotelBookingAction, but when I try to run the testNG it says "could not instantiate Seam Component"
Where am i wrong?
This is the test
package org.tyl.corecomponents.test.business;
import org.jboss.seam.Component;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.example.booking.User;
import org.jboss.seam.mock.SeamTest;
import org.jboss.seam.mock.SeamTest.Script;
import org.testng.annotations.Test;
import org.tyl.corecomponents.business.SystemOfUnitsManager;
public class SystemOfUnitsTest extends SeamTest {
@Test
public void testSystemOfUnitsManager() throws Exception
{
String id = new Script() {
SystemOfUnitsManager systemOfUnitsManager;
@Override
protected void updateModelValues() throws Exception
{
systemOfUnitsManager = (SystemOfUnitsManager) Component.getInstance("systemOfUnitsManager", true);
}
@Override
protected void invokeApplication()
{
String outcome = systemOfUnitsManager.find();
assert "main".equals( outcome );
}
}.run();
}
}Here is the action class
package org.tyl.corecomponents.business.impl;
import static javax.persistence.PersistenceContextType.EXTENDED;
import java.io.Serializable;
import java.util.List;
import javax.ejb.Interceptor;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.jboss.logging.Logger;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Conversational;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelectionIndex;
import org.jboss.seam.ejb.SeamInterceptor;
import org.tyl.corecomponents.business.SystemOfUnitsManager;
import org.tyl.corecomponents.model.SystemOfUnits;
@Stateful
@Name("systemOfUnitsManager")
@Interceptor(SeamInterceptor.class)
@Conversational(ifNotBegunOutcome="main")
public class SystemOfUnitsManagerImpl implements SystemOfUnitsManager, Serializable {
private static final Logger log = Logger.getLogger(SystemOfUnitsManager.class);
private String searchString=null;
@DataModel
private List<SystemOfUnits> systemOfUnitsList;
@DataModelSelectionIndex
private int systemOfUnitsIndex;
@PersistenceContext(type=EXTENDED)
private EntityManager em;
@Begin
public String find() {
systemOfUnitsList = null;
String searchPattern = searchString==null ? "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%';
systemOfUnitsList = em.createQuery("from SystemOfUnits where lower(systemOfUnitsID) like :search or lower(nameOfStandardizationBody) like :search")
.setParameter("search", searchPattern)
.setMaxResults(50)
.getResultList();
log.info(systemOfUnitsList.size() + " system of units found");
return "main";
}
}Here is the interface
package org.tyl.corecomponents.business;
import javax.ejb.Remote;
@Remote
public interface SystemOfUnitsManager {
public String find();
}and here is the entity
package org.tyl.corecomponents.model;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratorType;
import javax.persistence.Id;
import javax.persistence.Version;
@Entity
public class SystemOfUnits
implements Serializable
{
private java.lang.String systemOfUnitsID;
private Integer version;
private java.lang.String nameOfStandardizationBody;
public SystemOfUnits()
{
}
public SystemOfUnits(java.lang.String nameofsystem)
{
this.setSystemOfUnitsID(nameofsystem);
}
@Id(generate=GeneratorType.NONE)
public java.lang.String getSystemOfUnitsID() {
return systemOfUnitsID;
}
public void setSystemOfUnitsID(java.lang.String systemOfUnitsID) {
this.systemOfUnitsID = systemOfUnitsID;
}
@Version
@Column(name="OPTLOCK")
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
Any help?
Thank you
Marco Pancotti