Integration testing identity.login with Maven 2
spagop Jul 29, 2009 5:44 PMHello altogether,
I am trying to run a scripted integration test with 
invokeMethod("#{identity.login}") and it doesn't work because 
assert getValue("#{identity.loggedIn}").equals(Boolean.TRUE); is always false. But all other integrated test work fine. May be you can help me with some tips and tricks. May be I'am missing somthing! I also user 
<security:jpa-identity-store user-class="cam.datamodel.UserAccount" role-class="cam.datamodel.Role"></security:jpa-identity-store>
for my identity mgnt.
First, I'm using Maven 2 as build framework, JDK6, SEAM 2.1.2.
My directory structure looks so:
+ Parent-Project - pom.xml + EJB/SEAM-Components-Project (with ejb-jar.xml, orm.xml, persistence.xml, security-rules.drl in META-INF/ folder and seam.properties and import.sql in resources/ folder) - pom.xml + Web-Project (with seam specific file WEB-INF/components.xml) - pom.xml - src/test/ (jboss embedded bootstrap, and all my integrated tests class)
Here is my persistence.xml (I do not know if you need that
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<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="cam" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/camTestDatasource</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
            <property name="hibernate.transaction.manager_lookup_class"
                      value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
            <!-- Required binding for Seam-managed persistence context in Embeddable JBoss -->
            <property name="jboss.entity.manager.factory.jndi.name" value="java:/entityManagerFactories/cam"/>
            <!-- Automatic schema export and drop -->
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <!-- Logging -->
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.use_sql_comments" value="false"/>
            <property name="hibernate.format_sql" value="false"/>
            <!-- Run the Hibernate bytecode instrumentation at deployment time, for lazy loading of @ToOne and byte[] properties -->
            <!-- TODO: That doesn't work for me, using the enhancer in build.xml manually -->
            <property name="hibernate.ejb.use_class_enhancer" value="true"/>
            <property name="hibernate.max_fetch_depth" value="1"/>
            <property name="hibernate.jdbc.batch_size" value="0"/>
        </properties>
    </persistence-unit>
</persistence>
Here is my components.xml
<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
        xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence"
        xmlns:drools="http://jboss.com/products/seam/drools" xmlns:bpm="http://jboss.com/products/seam/bpm"
        xmlns:security="http://jboss.com/products/seam/security" xmlns:mail="http://jboss.com/products/seam/mail"
        xmlns:web="http://jboss.com/products/seam/web" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                 http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                 http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                 http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                 http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
        <core:init debug="@debug@" jndi-pattern="@jndiPattern@" />
        <!-- Conversation timeout: 20 minuntes -->
        <core:manager concurrent-request-timeout="4000"
                conversation-timeout="1200000" conversation-id-parameter="cid" />
        
         <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
        <security:jpa-identity-store user-class="cam.datamodel.UserAccount"
                role-class="cam.datamodel.Role"></security:jpa-identity-store>
        <security:jpa-permission-store
                user-permission-class="cam.datamodel.UserAccountPermission" />
        <drools:rule-base name="securityRules">
                <drools:rule-files>
                        <value>/META-INF/security-rules.drl</value>
                </drools:rule-files>
        </drools:rule-base>
        <persistence:entity-manager-factory
                name="camEntityManagerFactory" persistence-unit-name="cam" />
        <persistence:managed-persistence-context
                name="entityManager" auto-create="true" entity-manager-factory="#{camEntityManagerFactory}"
                persistence-unit-jndi-name="java:/entityManagerFactories/cam">
        </persistence:managed-persistence-context>
        <web:hot-deploy-filter url-pattern="*.seam" />
        <web:character-encoding-filter encoding="UTF-8"
                override-client="true" url-pattern="*.seam" />
        <!-- Maximum size of file uploads -->
        <!--
                If you are using MySQL, don't forget their magic stuff:
                http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html
        -->
        <web:multipart-filter create-temp-files="true"
                max-request-size="10000000" url-pattern="*.seam" />
        <event type="org.jboss.seam.security.notLoggedIn">
                <action execute="#{redirect.captureCurrentView}" />
        </event>
        <event type="org.jboss.seam.security.loginSuccessful">
                <action execute="#{redirect.returnToCapturedView}" />
        </event>
</components>
Here my integrated test
public class ChangePasswordTest extends DBUnitSeamTest {
     @Override
    protected void prepareDBUnitOperations() {
        beforeTestOperations.add(new DataSetOperation("cam/services/DjangiBaseData.dbunit.xml",
                                                      DatabaseOperation.CLEAN_INSERT));
    }
    @Test
    public void testLogin() throws Exception {
        new FacesRequest() {
            @Override
            protected void processValidations() throws Exception {
                validateValue("#{identity.username}", "demo");
                validateValue("#{identity.password}", "demo");
            }
            @Override
            protected void updateModelValues() throws Exception {
                setValue("#{identity.username}", "demo");
                setValue("#{identity.password}", "demo");
                assert getValue("#{identity.username}").equals("demo");
            }
            @Override
            protected void invokeApplication() {
                Object login = invokeMethod("#{identity.login}");
                assert getValue("#{identity.loggedIn}").equals(Boolean.TRUE);
                invokeMethod("#{identity.logout}");
                assert getValue("#{identity.loggedIn}").equals(Boolean.FALSE);
            }
        }.run();
    }
}I will appreciate any help.
Best regards,
 
    