<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to you 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 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>3.0.0-beta2</version>
    <relativePath>../log4j-parent</relativePath>
  </parent>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-layout-template-json-test</artifactId>
  <version>3.0.0-beta2</version>
  <name>Tests for the JSON Template Layout of Apache Log4j</name>
  <licenses>
    <license>
      <name>Apache-2.0</name>
      <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <properties>
    <log4jParentDir>${basedir}/..</log4jParentDir>
    <Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>
    <bnd-module-name>org.apache.logging.log4j.layout.template.json.test</bnd-module-name>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-layout-template-json</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-1.2-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-config-properties</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-config-yaml</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.awaitility</groupId>
      <artifactId>awaitility</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-high-level-client</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.code.java-allocation-instrumenter</groupId>
      <artifactId>java-allocation-instrumenter</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>co.elastic.logging</groupId>
      <artifactId>log4j2-ecs-layout</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <executions>
          <execution>
            <id>default-testCompile</id>
            <configuration>
              <compilerArgs combine.children="append">
                <arg>-ApluginPackage=org.apache.logging.log4j.layout.template.json.test</arg>
              </compilerArgs>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <annotationProcessorPaths combine.children="append">
            <path>
              <groupId>org.apache.logging.log4j</groupId>
              <artifactId>log4j-plugin-processor</artifactId>
              <version>${project.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <argLine>-Dfile.encoding=US-ASCII</argLine>
          <systemPropertyVariables>
            <junit.jupiter.execution.parallel.enabled>true</junit.jupiter.execution.parallel.enabled>
            <junit.jupiter.execution.parallel.mode.default>concurrent</junit.jupiter.execution.parallel.mode.default>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>docker</id>
      <activation />
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>start</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <verbose>all</verbose>
              <startParallel>true</startParallel>
              <autoCreateCustomNetworks>true</autoCreateCustomNetworks>
              <images>
                <image>
                  <alias>elasticsearch</alias>
                  <name>docker.elastic.co/elasticsearch/elasticsearch:8.2.2</name>
                  <run>
                    <env>
                      <xpack.security.enabled>false</xpack.security.enabled>
                      <discovery.type>single-node</discovery.type>
                    </env>
                    <memory>1000000000</memory>
                    <ports>
                      <port>9200:9200</port>
                    </ports>
                    <network>
                      <mode>custom</mode>
                      <name>log4j-layout-template-json-network</name>
                      <alias>elasticsearch</alias>
                    </network>
                    <log>
                      <prefix>[ES]</prefix>
                      <color>cyan</color>
                    </log>
                    <wait>
                      <log>recovered \[0\] indices into cluster_state</log>
                      <time>60000</time>
                    </wait>
                  </run>
                </image>
                <image>
                  <alias>logstash</alias>
                  <name>docker.elastic.co/logstash/logstash:8.2.2</name>
                  <run>
                    <dependsOn>
                      <container>elasticsearch</container>
                    </dependsOn>
                    <network>
                      <mode>custom</mode>
                      <name>log4j-layout-template-json-network</name>
                      <alias>logstash</alias>
                    </network>
                    <ports>
                      <port>12222:12222</port>
                      <port>12345:12345</port>
                    </ports>
                    <log>
                      <prefix>[LS]</prefix>
                      <color>green</color>
                    </log>
                    <entrypoint>
                      <exec>
                        <arg>logstash</arg>
                        <arg>--pipeline.batch.size</arg>
                        <arg>1</arg>
                        <arg>-e</arg>
                        <arg>input {
                            gelf {
                              host => "logstash"
                              use_tcp => true
                              use_udp => false
                              port => 12222
                              type => "gelf"
                            }
                            tcp {
                              port => 12345
                              codec => json
                              type => "tcp"
                            }
                          }

                          filter {
                            if [type] == "gelf" {
                              # These are GELF/Syslog logging levels as defined in RFC 3164.
                              # Map the integer level to its human readable format.
                              translate {
                                field => "[level]"
                                destination => "[levelName]"
                                dictionary => {
                                  "0" => "EMERG"
                                  "1" => "ALERT"
                                  "2" => "CRITICAL"
                                  "3" => "ERROR"
                                  "4" => "WARN"
                                  "5" => "NOTICE"
                                  "6" => "INFO"
                                  "7" => "DEBUG"
                                }
                              }
                            }
                          }

                          output {
                            # (Un)comment for debugging purposes
                            # stdout { codec => rubydebug }
                            elasticsearch {
                              hosts => ["http://elasticsearch:9200"]
                              index => "log4j"
                            }
                          }</arg>
                      </exec>
                    </entrypoint>
                    <wait>
                      <log>Successfully started Logstash API endpoint</log>
                      <time>60000</time>
                    </wait>
                  </run>
                </image>
              </images>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <skip>false</skip>
              <includes>
                <include>**/*IT.java</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
