[[sigtest]]
== Running the Signature Test

One of the requirements of an implementation passing the TCK is for it
to pass the Jakarta 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>jakarta.validation</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>jakarta.validation,jakarta.validation.bootstrap,jakarta.validation.constraints,
            jakarta.validation.constraintvalidation,jakarta.validation.executable,jakarta.validation.groups,
            jakarta.validation.metadata,jakarta.validation.spi,jakarta.validation.valueextraction
        </packages>
        <sigfile>${project.build.directory}/api-signature/validation-api-java8.sig</sigfile>
    </configuration>
</plugin>
```

Running a profile with this plugin enabled against that Hibernate Validator 7.0.0.Alpha5 release produces:
```
Scotts-iMac:tck-runner starksm$ mvn -Psigtest test
...
[INFO] --- sigtest-maven-plugin:1.2:check (default) @ hibernate-validator-tck-runner ---
[INFO] Packages: jakarta.validation,jakarta.validation.bootstrap,jakarta.validation.constraints,
                                jakarta.validation.constraintvalidation,jakarta.validation.executable,jakarta.validation.groups,
                                jakarta.validation.metadata,jakarta.validation.spi,jakarta.validation.valueextraction
[INFO] SignatureTest report
Base version: 3.0.0
Tested version: 7.0.0-Alpha5
Check mode: src [throws normalized]
Constant checking: on
```

=== 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 `jakarta.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: 3.0.0
Tested version: 7.0.0-Alpha5
Check mode: bin [throws normalized]
Constant checking: on


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