1 Reply Latest reply on Dec 4, 2007 1:49 AM by Andreas Franke

    Dataimport in Seam tests

    Andreas Franke Apprentice


      project is created with seam-gen v.2.0.0.GA
      Production DB is MySQL

      For testing purpose I filled import-test.sql with values

      INSERT INTO Customer (id, version, userName, hashedPassword, email, memberName) VALUES
      (1, 1, 'feivel', 'd41d8cd98f00b204e9800998ecf8427e', 'a.franke@email.de', '00022')

      Here the corresponding entity
      @Table(name = "Customer")
      public class User implements java.io.Serializable {
       private Long id;
       private Long version;
       private String userName;
       private String memberName;
       private String email;
       private String hashedPassword;
       @GeneratedValue(strategy = IDENTITY)
       @Column(name = "id", unique = true, nullable = false)
       public Long getId() {return this.id;}
       public void setId(Long id) {this.id = id;}
       @Column(name = "version")
       public Long getVersion() {return this.version;}
       public void setVersion(Long version) {this.version = version;}
       @Column(name = "userName", nullable = false)
       public String getUserName() {return this.userName;}
       public void setUserName(String username) {this.userName = username;}

      But when I run a login-test the values not in HSQLDB
       public void testLoginComponent() throws Exception
       new ComponentTest() {
       protected void testComponents() throws Exception
       assert getValue("#{identity.loggedIn}").equals(false);
       setValue("#{identity.username}", "00022");
       setValue("#{identity.password}", "");
       assert getValue("#{identity.loggedIn}").equals(true);
       assert getValue("#{identity.loggedIn}").equals(false);
       setValue("#{identity.username}", "gavin");
       setValue("#{identity.password}", "tiger");
       assert getValue("#{identity.loggedIn}").equals(false);

      public class AuthenticatorBean implements Authenticator
       private Log log;
       private EntityManager entityManager;
       private Identity identity;
       @Out(required=false, scope=ScopeType.SESSION)
       private User currentUser;
       public boolean authenticate(){
       log.info("authenticating #0", identity.getUsername());
       try {
       List results = entityManager.createQuery("select u from User u where u.memberName =:username").setParameter("username", identity.getUsername()).getResultList();
       if ( results.size()==0 )
       return false;
       currentUser = (User) results.get(0);
       } catch (PersistenceException e) {
       return false;

      In debug-modus I can see that the returned list from entityManager is empty, also I call "from User u" in sql statement.

      I found nothing in docu or forum what I have done wrong. The persistence-test.xml is that one created automatically from Seam
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for tests -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       <persistence-unit name="datenvisualisierung">
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.cache.use_second_level_cache" value="false"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/datenvisualisierungEntityManagerFactory"/>