<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright 2024 gematik GmbH

    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.

-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>tiger</artifactId>
        <groupId>de.gematik.test</groupId>
        <version>3.4.7</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <properties>
        <version.frontend-maven-plugin>1.15.1</version.frontend-maven-plugin>
        <version.node>v20.11.1</version.node>
        <version.npm>10.2.4</version.npm>
        <version.httpbin>1.4.0</version.httpbin>
        <version.mapstruct>1.6.0</version.mapstruct>
        <version.lombok-mapstruct-binding>0.2.0</version.lombok-mapstruct-binding>
        <version.swagger-parser>2.1.22</version.swagger-parser>
        <version.jackson-databind-nullable>0.2.6</version.jackson-databind-nullable>
    </properties>
    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok-mapstruct-binding -->


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>${version.spring-boot}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-client</artifactId>
                <version>11.0.15</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-util</artifactId>
                <version>11.0.15</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-alpn-client</artifactId>
                <version>11.0.15</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-io</artifactId>
                <version>11.0.15</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-http</artifactId>
                <version>11.0.15</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-server</artifactId>
                <version>11.0.15</version>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <artifactId>tiger-testenv-mgr</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- spring boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>${version.spring-boot}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${version.spring-boot}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <version>${version.spring-boot}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>de.gematik.test</groupId>
            <artifactId>tiger-proxy</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.gaul</groupId>
            <artifactId>httpbin</artifactId>
            <version>${version.httpbin}</version>
        </dependency>
        <!-- for TigerExtension and TigerTest annotation which are in src so scope is not only test -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit-platform-engine</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-cucumber</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
        </dependency>
        <!--  frontend -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator-core</artifactId>
            <version>${version.webjars-locator-core}</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>sockjs-client</artifactId>
            <version>${version.sockjs-client}</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>stomp-websocket</artifactId>
            <version>${version.stomp-websocket}</version>
        </dependency>

        <!-- test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${version.spring-boot}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>junit</artifactId>
                    <groupId>junit</groupId>
                </exclusion>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>uk.org.webcompere</groupId>
            <artifactId>system-stubs-core</artifactId>
            <version>${version.system-stubs}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.wiremock</groupId>
            <artifactId>wiremock-standalone</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>25.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>de.gematik.test</groupId>
            <artifactId>tiger-test-utils</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.konghq</groupId>
            <artifactId>unirest-java</artifactId>
        </dependency>
        <dependency>
            <groupId>com.konghq</groupId>
            <artifactId>unirest-objectmapper-jackson</artifactId>
            <version>${version.unirest}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>uk.org.webcompere</groupId>
            <artifactId>system-stubs-jupiter</artifactId>
            <version>${version.system-stubs}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>${version.cucumber}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>net.jcip</groupId>
            <artifactId>jcip-annotations</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>io.swagger.parser.v3</groupId>
            <artifactId>swagger-parser</artifactId>
            <version>${version.swagger-parser}</version>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${version.mapstruct}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-mapstruct-binding</artifactId>
            <version>${version.lombok-mapstruct-binding}</version>
        </dependency>
        <dependency>
            <groupId>org.openapitools</groupId>
            <artifactId>jackson-databind-nullable</artifactId>
            <version>${version.jackson-databind-nullable}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.8.0</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>org.jenkins-ci</groupId>
                            <artifactId>winstone</artifactId>
                            <version>${version.winstone}</version>
                            <type>jar</type>
                            <overWrite>false</overWrite>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                            <destFileName>winstone.jar</destFileName>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>${version.frontend-maven-plugin}</version>

                <executions>
                    <execution>
                        <id>Install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <!-- https://github.com/eirslett/frontend-maven-plugin#proxy-settings -->
                            <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
                            <nodeVersion>${version.node}</nodeVersion>
                            <npmVersion>${version.npm}</npmVersion>
                        </configuration>
                    </execution>

                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>

                    <execution>
                        <id>npm build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                    <!-- Run Unit tests with Jest -->
                    <execution>
                        <id>npm-unit-test</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <arguments>run test</arguments>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <nodeVersion>${version.node}</nodeVersion>
                    <workingDirectory>${project.basedir}/src/frontend</workingDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>Copy Vue frontend into Spring Boot target static folder</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/classes/static</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/frontend/dist</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>jacoco-maven-plugin</artifactId>
                <groupId>org.jacoco</groupId>
            </plugin>
            <plugin>
                <artifactId>sonar-maven-plugin</artifactId>
                <groupId>org.sonarsource.scanner.maven</groupId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${version.spring-boot}</version>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>build-info</id>
                        <goals>
                            <goal>build-info</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>de.gematik.test.tiger.testenvmgr.TigerTestEnvMgrApplication</mainClass>
                    <skip>false</skip>
                    <classifier>springboot</classifier>
                </configuration>
            </plugin>


            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${version.maven.surefire}</version>
                <configuration>
                    <!-- very pessimistic value for slow environment. Default is 30. Rare errors observed. -->
                    <forkedProcessExitTimeoutInSeconds>1000</forkedProcessExitTimeoutInSeconds>
                    <forkCount>3</forkCount>
                    <threadCount>1</threadCount>
                    <reuseForks>true</reuseForks>
                    <parallel>suitesAndClasses</parallel>
                    <rerunFailingTestsCount>2</rerunFailingTestsCount>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.10.0</version>
                <executions>
                    <execution>
                        <id>generate java code</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <!-- TODO: the most correct way would be to refer the project.basedir, but a bug in the
                            swagger-parser can't handle the 'C:' present in windows paths.
                            Using ${project.baseUri} works in resolving the file, but the generated code creates duplicated
                            classes for $refs even though they refer to the same class
                            The direct path tiger-testenv-mgr should work but requires the generation always to be started from the
                            root project.

                            Follow up on one of these tickets to see if the issue is resolved:
                            https://github.com/swagger-api/swagger-parser/issues/2136
                            https://github.com/swagger-api/swagger-parser/pull/2105

                            -->
                            <!--<inputSpec>${project.baseUri}/src/main/resources/tiger-management-api.yaml</inputSpec>-->
                            <inputSpec>tiger-testenv-mgr/src/main/resources/tiger-management-api.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <modelNameSuffix>Dto</modelNameSuffix>
                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                                <useSpringBoot3>true</useSpringBoot3>
                                <interfaceOnly>true</interfaceOnly>
                                <apiPackage>de.gematik.test.tiger.testenvmgr.api</apiPackage>
                                <modelPackage>de.gematik.test.tiger.testenvmgr.api.model</modelPackage>
                                <useBeanValidation>true</useBeanValidation>
                                <performBeanValidation>true</performBeanValidation>
                                <skipDefaultInterface>true</skipDefaultInterface>
                                <openApiNullable>false</openApiNullable>
                            </configOptions>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate ascii docs</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <!--<inputSpec>${project.baseUri}/src/main/resources/tiger-management-api.yaml</inputSpec>-->
                            <inputSpec>tiger-testenv-mgr/src/main/resources/tiger-management-api.yaml</inputSpec>
                            <generatorName>asciidoc</generatorName>
                            <output>${project.parent.basedir}/doc/user_manual/rest_api</output>
                            <configOptions>
                                <headerAttributes>false</headerAttributes>
                                <useIntroduction>true</useIntroduction>
                                <!-- I don't know why the option is default to false, since examples are not supported by the asciidoc generator.
                                 see https://openapi-generator.tech/docs/generators/asciidoc/#global-feature -->
                                <skipExamples>true</skipExamples>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${version.maven-compiler-plugin}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${version.mapstruct}</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${version.lombok}</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <version>${version.lombok-mapstruct-binding}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
