[[sigtest]]
== Running the Signature Test

One of the requirements of an implementation passing the TCK is for it
to pass the Bean Validation signature test. This section describes how to run
it against your implementation as a part of a Maven build.

=== Executing the signature check

The signature file bundled inside this TCK is created using the http://wiki.netbeans.org/SigTest[SigTest Maven plugin].
The same plugin can be used to run a signature test to check for any incompatibilities.
Let's take a look how it can be done as a part of a Maven build.
Note that there must be no dependency declared for this project besides the API artifact you wish to test.

Before running an actual test you need to obtain the signature file first. It is packaged inside the
_beanvalidation-tck-tests_ artifact, so we can get it using the `unpack` goal of the `maven-dependency-plugin`
as shown below:

```xml
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>copy-tck-bv-api-signature-file</id>
            <phase>generate-test-sources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>org.hibernate.beanvalidation.tck</groupId>
                        <artifactId>beanvalidation-tck-tests</artifactId>
                        <version>${beanvalidation-tck-tests.version}</version>
                        <type>jar</type>
                        <overWrite>false</overWrite>
                    </artifactItem>
                </artifactItems>
                <!-- We just need the signature file and nothing else -->
                <includes>**/*.sig</includes>
                <outputDirectory>${project.build.directory}/api-signature</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
```

To actually run a signature test, the `check` goal of the `sigtest-maven-plugin` can be used.
The plugin configuration above puts the signature file to the _api-signature_ subdirectory of your project's
build directory. Having the file there, it can be referenced via the `sigfile`
parameter of the `sigtest-maven-plugin` plugin like this:

```xml
<plugin>
    <groupId>org.netbeans.tools</groupId>
    <artifactId>sigtest-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <packages>javax.validation,javax.validation.bootstrap,javax.validation.constraints,
            javax.validation.constraintvalidation,javax.validation.executable,javax.validation.groups,
            javax.validation.metadata,javax.validation.spi,javax.validation.valueextraction
        </packages>
        <sigfile>${project.build.directory}/api-signature/validation-api-java8.sig</sigfile>
    </configuration>
</plugin>
```

=== Forcing a signature test failure

If you would like to verify that the signature test is running correctly, make a copy of the
signature file somewhere on your local file system and modify it. For example let us change the
`value()` of `javax.validation.constraints.Max` to `val()` which should make SigTest fail.

After modifying the signature file, update the `sigfile` parameter of the `sigtest-maven-plugin` to point to the modified file:

```
<sigfile>${path_to_folder_containing_your_modified_signature_file}/validation-api-java8.sig</sigfile>
```

If all is done correctly, while running `mvn sigtest:check` on your project, you should see
an error similar to next:

```
[INFO] SignatureTest report
Base version: 2.0.0-SNAPSHOT
Tested version: 2.0.0-SNAPSHOT
Check mode: bin [throws removed]
Constant checking: on


Class javax.validation.constraints.Max
  "E2.7 - Removing member from annotation type" : method public abstract long javax.validation.constraints.Max.val()
```
