arquillian在测试之前创建数据库模式

时间:2013-04-14 12:15:25

标签: java-ee testing integration-testing glassfish-3 jboss-arquillian

您好我尝试在测试之前创建我的数据库schem但它失败了:/ 这是我的剧本:

CREATE TABLE OFCONVERSATION
(
  CONVERSATIONID integer NOT NULL,
  ROOM character varying(1024),
  ISEXTERNAL smallint NOT NULL,
  STARTDATE bigint NOT NULL,
  LASTACTIVITY bigint NOT NULL,
  MESSAGECOUNT integer NOT NULL,
  CONSTRAINT OFCONVERSATION_PK PRIMARY KEY (CONVERSATIONID)
);

当我尝试使用squirell和嵌入式derby运行该脚本时,它正在工作。

  1. 首先我尝试使用注释@CreateSchema(“scripts / import.sql”)     课前测试:
  2. 接下来尝试使用@ApplyScriptBefore
  3. 第二次我尝试使用脚本:
  4.   

    property name =“scriptsToExecuteBeforeTest”scripts / import.sql property

    但都失败了......

    Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 9.816 sec <<< FAILURE!
    getPairChat(com.test.ejb.im.service.impl.PairChatTest)  Time elapsed: 0.451 sec  <<< ERROR!
    org.jboss.arquillian.persistence.dbunit.exception.DBUnitDataSetHandlingException: Unable to execute statement: CREATE TABLE OFCONVERSATION
    (
    CONVERSATIONID integer NOT NULL,
    ROOM character varying(1024),
    ISEXTERNAL smallint NOT NULL,
    STARTDATE bigint NOT NULL,
    LASTACTIVITY bigint NOT NULL,
    MESSAGECOUNT integer NOT NULL,
    CONSTRAINT OFCONVERSATION_PK PRIMARY KEY (CONVERSATIONID)
    );
        at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
        at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
        at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
        at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
        at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source
    

    这是我的arquillian pom import:

        <dependency>
          <groupId>org.glassfish.main.extras</groupId>
          <artifactId>glassfish-embedded-all</artifactId>
          <version>${glassfish-embedded-all.version}</version>
          <type>jar</type>
          <scope>test</scope>
        </dependency>
    
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>  
    
        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
            <version>1.0.0.CR3</version>
            <scope>test</scope>
        </dependency>
    
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-persistence-impl</artifactId>
            <version>1.0.0.Alpha6</version>
            <scope>test</scope>
        </dependency>
    

    和我的test-persistence.xml:

     <persistence-unit name="test-ejb" transaction-type="JTA">
      <jta-data-source>test-ds</jta-data-source>
      <exclude-unlisted-classes>false</exclude-unlisted-classes>      
      <properties>
          <property name="eclipselink.target-database" value="DERBY"/>
          <property name="eclipselink.platform.class.name" value="org.eclipse.persistence.platform.database.DerbyPlatform"/>
           <!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> --> 
          <property name="eclipselink.logging.level" value="ALL"/>
          <property name="eclipselink.jpa.uppercase-column-names" value="true" />
      </properties>
      </persistence-unit>
    

    和glassfish-resources.xml:

    <resources>
        <jdbc-connection-pool name="test-pool"
            res-type="javax.sql.DataSource" datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource"
            ping="true">
            <property name="ConnectionAttributes" value="create=true" />
            <property name="DatabaseName" value="./target/derbydb" />
            <property name="Password" value="" />
            <property name="User" value="" />
        </jdbc-connection-pool>
        <jdbc-resource jndi-name="test-ds" pool-name="test-pool" />
    </resources>
    

    那个sql脚本或我的配置有什么问题?

2 个答案:

答案 0 :(得分:0)

如果你得到(或类似于你使用Derby的东西):

Caused by: java.sql.SQLException: ORA-00911: invalid character

在你的堆栈跟踪中进一步向下,你可能偶然发现broken feature in Alpha6

答案 1 :(得分:0)

这会对你有帮助,因为我删除了特殊字符(回车,换行...)

CREATE TABLE OFCONVERSATION(  CONVERSATIONID integer NOT NULL,  ROOM character varying(1024),  ISEXTERNAL smallint NOT NULL,  STARTDATE bigint NOT NULL,  LASTACTIVITY bigint NOT NULL,  MESSAGECOUNT integer NOT NULL,  CONSTRAINT OFCONVERSATION_PK PRIMARY KEY (CONVERSATIONID))
相关问题