//
// Copyright (c) 2016-2017 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

= Running the Microprofile Metrics TCK

Any implementation claiming Microprofile Metrics 2.0 compatibility must pass this test suite.
The TCK uses `junit`.

== Dependencies

To enable the tests in your Arquillian based test project you need to add the following dependencies:

[source, xml]
----
<dependencies>
    <dependency>
        <groupId>org.eclipse.microprofile.metrics</groupId>
        <artifactId>microprofile-metrics-api</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.microprofile.metrics</groupId>
        <artifactId>microprofile-metrics-rest-tck</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.microprofile.metrics</groupId>
        <artifactId>microprofile-metrics-api-tck</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <version>1.1.8.Final</version>
        <scope>test</scope>
    </dependency>

    <!-- You can replace this with your choice of container -->
    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-wlp-managed-8.5</artifactId>
        <version>1.0.0.Final-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>
</dependencies>

----

== Declaring the Tests to run in Apache Maven pom.xml

If you use Apache Maven, then the tests are run via the `maven-surefire-plugin` by adding the following in your pom.xml.
[source, xml]
----
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <dependenciesToScan>
                    <dependency>org.eclipse.microprofile.metrics:microprofile-metrics-api-tck</dependency>
                    <dependency>org.eclipse.microprofile.metrics:microprofile-metrics-rest-tck</dependency>
                </dependenciesToScan>
                <environmentVariables>
                    <MP_METRICS_TAGS>tier=integration</MP_METRICS_TAGS>
                </environmentVariables>
            </configuration>
        </plugin>
    </plugins>
</build>
----
Note: Be sure to set up your Arquillian.xml as required for your server under test.

If the implementation does not support all base metrics as described in the specification because
they are not available in the used JVM, it is possible to skip the tests related to base metrics
by adding the system property `skip.base.metric.tests=true` to the surefire process.

== Running the TCK

To run the TCK, ensure that the above dependencies are installed, and run the following command:
----
# Modify the test.url variable to point to your server under test
mvn test -Dtest.url=http://localhost:9080
----

If your server under test has basic authentication enabled, run the following command:
----
# Modify the test.url variable to point to your server under test.  Modify the test.user and test.pwd variables to appropriate values for your server under test.
mvn test -Dtest.url=https://localhost:9443 -Dtest.user=someUser -Dtest.pwd=somePassword 
----

