4

我使用Maven Cargo (1.2.1) 配置和启动 Glassfish 3.1.2 进行集成测试。我能够配置数据源并启动服务器。但我还需要配置 JDBC 安全领域以及 Java 邮件会话。

但是我不知道如何使用 maven cargo 配置安全领域和 Java 邮件会话,有人知道吗?

一种方法可能是使用asadmin,但我不知道如何从货物中使用它。

到目前为止我所拥有的:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>start-container</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-container</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <container>
            <type>installed</type>
            <containerId>glassfish3x</containerId>
            <artifactInstaller>
                <groupId>org.glassfish.main.distributions</groupId>
                <artifactId>glassfish</artifactId>
                <version>3.1.2</version>
                <type>zip</type>
            </artifactInstaller>
            <output>${project.build.directory}/glassfish/container.log</output>
            <log>${project.build.directory}/glassfish/cargo.log</log>
            <append>false</append>
            <dependencies>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc</artifactId>
                </dependency>
            </dependencies>
        </container>
        <configuration>
            <home>${project.build.directory}/cargo/configurations/glassfish</home>
            <properties>
                <cargo.servlet.port>8082</cargo.servlet.port>
                <cargo.datasource.datasource>
                    cargo.datasource.jndi=jdbc/tecisplus|
                    cargo.datasource.type=javax.sql.DataSource|
                    cargo.datasource.driver=oracle.jdbc.OracleDriver|
                    cargo.datasource.url=${it-database.url}|
                    cargo.datasource.username=$[it-database.username}|
                    cargo.datasource.password=${it-database.password}
                </cargo.datasource.datasource>
            </properties>
            <deployables>
                <deployable>
                    <groupId>de.test</groupId>
                    <artifactId>test-ear</artifactId>
                    <type>ear</type>
                </deployable>
            </deployables>
        </configuration>
    </configuration>
</plugin>
4

1 回答 1

2

我目前使用的解决方法是有一个手写domain.xml文件,其中已经包含所有配置(JDBC、Realm 和 JavaMail 会话)。

然后我指示 cargo 使用它domain.xml而不是进行自己的配置:

<configuration>
    <home>${project.build.directory}/cargo/configurations/glassfish</home>
    <configfiles>
        <configfile>
            <file>${project.build.directory}/filtered-serverresources/domain.xml</file>
            <todir>cargo-domain/config</todir>
        </configfile>
    </configfiles>
    <deployables>
        <deployable>
            <groupId>de.tecis.tecisplus</groupId>
            <artifactId>tecisplus-ear</artifactId>
            <type>ear</type>
        </deployable>
    </deployables>
</configuration>

${project.build.directory}/filtered-serverresources/domain.xml是配置文件的一个小技巧(cargo也可以替换一些属性,但是我无法替换cargo不知道的属性。)所以我使用maven-resource-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <!-- because maven test-resource does not support filter! -->
    <version>2.5</version>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
    <executions>
        <execution>
            <id>filter-glassfish-configuration-domain-file</id>
            <!-- <phase>pre-integration-test</phase> -->
            <phase>process-test-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/filtered-serverresources</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/test/serverresources</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*.xml</include>
                        </includes>
                    </resource>
                </resources>
                <delimiters>
                    <delimiter>~{*}</delimiter>
                </delimiters>
            </configuration>
        </execution>
    </executions>
</plugin>

修改后的分隔符~{...}是必要的,因为它domain.xml包含很多看起来像默认分隔符的序列${...}

于 2012-04-27T10:35:06.730 回答