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

    Dataimport in Seam tests

    hispeedsurfer

      Hi,

      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
      @Entity
      @Name("user")
      @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;
      
       @Id
       @GeneratedValue(strategy = IDENTITY)
       @Column(name = "id", unique = true, nullable = false)
       public Long getId() {return this.id;}
       public void setId(Long id) {this.id = id;}
      
       @Version
       @Column(name = "version")
       public Long getVersion() {return this.version;}
       public void setVersion(Long version) {this.version = version;}
      
       @Column(name = "userName", nullable = false)
       @NotNull
       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
      @Test
       public void testLoginComponent() throws Exception
       {
       new ComponentTest() {
      
       @Override
       protected void testComponents() throws Exception
       {
       assert getValue("#{identity.loggedIn}").equals(false);
       setValue("#{identity.username}", "00022");
       setValue("#{identity.password}", "");
       invokeMethod("#{identity.login}");
       assert getValue("#{identity.loggedIn}").equals(true);
       invokeMethod("#{identity.logout}");
       assert getValue("#{identity.loggedIn}").equals(false);
       setValue("#{identity.username}", "gavin");
       setValue("#{identity.password}", "tiger");
       invokeMethod("#{identity.login}");
       assert getValue("#{identity.loggedIn}").equals(false);
       }
      
       }.run();
       }




      @Stateless
      @Name("authenticator")
      public class AuthenticatorBean implements Authenticator
      {
       @Logger
       private Log log;
      
       @PersistenceContext
       private EntityManager entityManager;
      
       @In
       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;
       }
       else
       {
       currentUser = (User) results.get(0);
       }
       } catch (PersistenceException e) {
       e.printStackTrace();
       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"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0">
      
       <persistence-unit name="datenvisualisierung">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/DefaultDS</jta-data-source>
       <properties>
       <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"/>
       </properties>
       </persistence-unit>
      
      </persistence>