24
Oct

How to automatically test swf modules with maven

Comments Off on How to automatically test swf modules with maven

Problem

Running unit tests with maven, that require runtime resources such as runtime CSS, runtime resource bundles, or other resources throws error because the resources have not been marked as trusted.

To be more detailed, maven has a file within the #Security folder of Flash Player, in which it stores a list with trusted swfs. For example, when maven runs the unit tests, it automatically adds the FlexUnit.swf to be trusted by Flash Player. This file, named maven.cfg is stored into ~/Library/Preferences/Macromedia/Flash\ Player/#Security/FlashPlayerTrust/ folder on a Mac. Other operating systems have a different path, as described in this link .

In my case, the problem was that I was writing some unit-tests that would load modules placed under /src/test/resources folder within my maven project.

Solution

flexmojos:trust

In other words, I had to add this little script to the maven build in order to fix my problem:

<build>
    <plugins>
        <plugin>
            <groupId>org.sonatype.flexmojos</groupId>
            <artifactId>flexmojos-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>trust</goal>
                    </goals>
                    <configuration>
                        <filesToTrust>
                            <file>target/test-classes/test/LoginModule.swf</file>
                            <file>target/test-classes/test/LoginModuleSkin.swf</file>
                        </filesToTrust>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

After updating the pom.xml and running "mvn test" command, I could notice that my files were added to the maven.cfg file.

[INFO] Updating Flash Player Trust directory .../target/test-classes/test/LoginModule.swf
[INFO] Updating Flash Player Trust directory .../target/test-classes/test/LoginModuleSkin.swf