<?xml version="1.0"?>
<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>
    <groupId>org.eclipse.pass</groupId>
    <artifactId>pass-nihms-submission-etl</artifactId>
    <version>0.1.0</version>
  </parent>

  <artifactId>nihms-etl-integration</artifactId>
  <version>0.1.0</version>

  <name>NIHMS ELT Integration Tests</name>

  <properties>
    <FCREPO_HOST>${docker.host.address}</FCREPO_HOST>
    <ES_HOST>${docker.host.address}</ES_HOST>
  </properties>

  <dependencies>

    <dependency>
      <groupId>org.eclipse.pass</groupId>
      <artifactId>nihms-data-transform-load-cli</artifactId>
      <version>${project.parent.version}</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>

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

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-all</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>reserve-port</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>reserve-network-port</goal>
            </goals>
            <configuration>
              <portNames>
                <portName>FCREPO_PORT</portName>
                <portName>ES_PORT</portName>
                <portName>FCREPO_JMS_PORT</portName>
                <portName>FCREPO_STOMP_PORT</portName>
              </portNames>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <configuration>
          <autoCreateCustomNetworks>true</autoCreateCustomNetworks>
          <images>
            <image>
              <alias>fcrepo</alias>
              <name>oapass/fcrepo:4.7.5-3.5</name>
              <run>
                <hostname>fcrepo</hostname>
                <namingStrategy>alias</namingStrategy>
                <env>
                  <FCREPO_HOST>fcrepo</FCREPO_HOST>
                  <FCREPO_PORT>${FCREPO_PORT}</FCREPO_PORT>
                  <FCREPO_JMS_PORT>${FCREPO_JMS_PORT}</FCREPO_JMS_PORT>
                  <FCREPO_STOMP_PORT>${FCREPO_STOMP_PORT}</FCREPO_STOMP_PORT>
                  <FCREPO_JMS_BASEURL>http://${FCREPO_HOST}:${FCREPO_PORT}/fcrepo/rest</FCREPO_JMS_BASEURL>
                  <FCREPO_ACTIVEMQ_CONFIGURATION>classpath:/activemq-queue.xml</FCREPO_ACTIVEMQ_CONFIGURATION>
                  <COMPACTION_URI>https://oa-pass.github.io/pass-data-model/src/main/resources/context-3.5.jsonld
                  </COMPACTION_URI>
                  <COMPACTION_PRELOAD_URI_PASS_STATIC>
                    https://oa-pass.github.io/pass-data-model/src/main/resources/context-3.5.jsonld
                  </COMPACTION_PRELOAD_URI_PASS_STATIC>
                  <COMPACTION_PRELOAD_FILE_PASS_STATIC>/usr/local/tomcat/lib/context-3.5.jsonld
                  </COMPACTION_PRELOAD_FILE_PASS_STATIC>
                </env>
                <ports>
                  <port>${FCREPO_PORT}:${FCREPO_PORT}</port>
                </ports>
                <network>
                  <mode>custom</mode>
                  <name>pass</name>
                  <alias>fcrepo</alias>
                  <alias>localhost</alias>
                </network>
                <volumes>
                  <bind>./src/test/resources/docker/mnt:/mnt</bind>
                </volumes>
                <wait>
                  <http>
                    <url>http://fedoraAdmin:moo@${FCREPO_HOST}:${FCREPO_PORT}/fcrepo/rest</url>
                  </http>
                  <time>120000</time>
                </wait>
              </run>
            </image>
            <image>
              <alias>elasticsearch</alias>
              <name>docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3</name>
              <run>
                <namingStrategy>alias</namingStrategy>
                <env>
                  <discovery.type>single-node</discovery.type>
                  <bootstrap.memory_lock>true</bootstrap.memory_lock>
                  <ES_JAVA_OPTS>-Xms512m -Xmx512m</ES_JAVA_OPTS>
                </env>
                <ports>
                  <port>${ES_PORT}:9200</port>
                </ports>
                <network>
                  <mode>custom</mode>
                  <name>pass</name>
                  <alias>elasticsearch</alias>
                </network>
                <wait>
                  <http>
                    <url>http://${ES_HOST}:${ES_PORT}/</url>
                  </http>
                  <time>120000</time>
                </wait>
              </run>
            </image>
            <image>
              <alias>indexer</alias>
              <name>oapass/indexer:0.0.18-3.4-1</name>
              <run>
                <namingStrategy>alias</namingStrategy>
                <env>
                  <PI_FEDORA_USER>fedoraAdmin</PI_FEDORA_USER>
                  <PI_FEDORA_PASS>moo</PI_FEDORA_PASS>
                  <PI_FEDORA_INTERNAL_BASE>http://fcrepo:${FCREPO_PORT}/fcrepo/rest/</PI_FEDORA_INTERNAL_BASE>
                  <PI_ES_BASE>http://elasticsearch:9200/</PI_ES_BASE>
                  <PI_ES_INDEX>http://elasticsearch:9200/pass/</PI_ES_INDEX>
                  <PI_FEDORA_JMS_BROKER>tcp://fcrepo:${FCREPO_JMS_PORT}</PI_FEDORA_JMS_BROKER>
                  <PI_FEDORA_JMS_QUEUE>fedora</PI_FEDORA_JMS_QUEUE>
                  <PI_TYPE_PREFIX>http://oapass.org/ns/pass#</PI_TYPE_PREFIX>
                  <PI_LOG_LEVEL>debug</PI_LOG_LEVEL>
                  <PI_ES_CONFIG>/app/esconfig-3.4.json</PI_ES_CONFIG>
                </env>
                <links>
                  <link>fcrepo:localhost</link>
                  <link>elasticsearch</link>
                </links>
                <volumes>
                  <bind>./src/test/resources/docker/hosts:/etc/hosts</bind>
                </volumes>
                <network>
                  <mode>custom</mode>
                  <name>pass</name>
                  <alias>indexer</alias>
                </network>
                <wait>
                  <http>
                    <url>http://${ES_HOST}:${ES_PORT}/pass</url>
                  </http>
                  <time>120000</time>
                </wait>
              </run>
            </image>
          </images>
        </configuration>
        <executions>
          <execution>
            <id>start-docker-its</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
          </execution>
          <execution>
            <id>stop-docker-its</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <systemProperties>
            <pass.fedora.baseurl>http://${FCREPO_HOST}:${FCREPO_PORT}/fcrepo/rest/</pass.fedora.baseurl>
            <pass.elasticsearch.url>http://${ES_HOST}:${ES_PORT}</pass.elasticsearch.url>
          </systemProperties>
          <trimStackTrace>false</trimStackTrace>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>standard</id>
      <properties>
        <FCREPO_PORT>8080</FCREPO_PORT>
        <FCREPO_JMX_PORT>1099</FCREPO_JMX_PORT>
        <FCREPO_JMS_PORT>61616</FCREPO_JMS_PORT>
        <FCREPO_STOMP_PORT>61613</FCREPO_STOMP_PORT>
        <ES_PORT>9200</ES_PORT>
      </properties>
    </profile>
    <profile>
      <id>local-context</id>
      <properties>
        <COMPACTION_PRELOAD_FILE_PASS_STATIC>/mnt/context.jsonld</COMPACTION_PRELOAD_FILE_PASS_STATIC>
      </properties>
    </profile>
  </profiles>
</project>
