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

<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>com.bazaarvoice.emodb</groupId>
        <artifactId>emodb-parent</artifactId>
        <version>6.5.144</version>
        <relativePath>../../parent/pom.xml</relativePath>
    </parent>

    <artifactId>emodb-quality</artifactId>

    <name>EmoDB Integration Tests</name>

    <properties>
        <skipTests>false</skipTests>
        <skipITs>false</skipITs>
        <integration.suiteXmlFile>src/test/resources/integration-testng.xml</integration.suiteXmlFile>
        <emodb.pause>false</emodb.pause>
        <config-all-role-yaml>${project.basedir}/src/test/resources/config-all-role.yaml</config-all-role-yaml>
        <config-stash-role-yaml>${project.basedir}/src/test/resources/config-stash-role.yaml</config-stash-role-yaml>
        <runAdaptiveCqlIntegrationTests>false</runAdaptiveCqlIntegrationTests>

        <emodb.version>${project.version}</emodb.version>
        <zkConnection>localhost:2181</zkConnection>
        <zkNamespace />
        <clusterName>local_default</clusterName>
        <placement>ugc_global:ugc</placement>
        <remotePlacement>app_remote:default</remotePlacement>
        <mediaPlacement>media_global:ugc</mediaPlacement>
        <apiKey>local_admin</apiKey>
        <clientHttpKeepAlive>1</clientHttpKeepAlive>
        <clientHttpTimeout>10</clientHttpTimeout>
    </properties>

    <dependencies>
        <!-- Bazaarvoice dependencies -->
        <dependency>
            <groupId>com.bazaarvoice.curator</groupId>
            <artifactId>dropwizard</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.curator</groupId>
            <artifactId>test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.astyanax</groupId>
            <artifactId>astyanax-cassandra</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.codehaus.jackson</groupId>
                    <artifactId>jackson-mapper-asl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.codehaus.jackson</groupId>
                    <artifactId>jackson-core-asl</artifactId>
                </exclusion>
            </exclusions>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-auth-client</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-auth-core</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-auth-store</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-blob</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-blob-api</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-blob-client</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-blob-client-common</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-cachemgr</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-api</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-astyanax</artifactId>
            <version>${project.version}</version>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-astyanax</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-client</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-dropwizard</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-stash</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-jersey-client</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-json</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-uuid</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-common-zookeeper</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-databus-api</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-databus-client</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-databus-client-common</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-datacenter</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-event</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-sor-api</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-sor-client</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-sor-client-common</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-table</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-uac-api</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-uac-client</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.emodb</groupId>
            <artifactId>emodb-web-local</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.ostrich</groupId>
            <artifactId>ostrich-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.bazaarvoice.ostrich.zookeeper</groupId>
            <artifactId>ostrich-zookeeper-discovery</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Test dependencies -->
        <dependency>
            <groupId>com.boundary</groupId>
            <artifactId>high-scale-lib</artifactId>
            <version>1.0.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.codahale.metrics</groupId>
            <artifactId>metrics-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.codahale.metrics</groupId>
            <artifactId>metrics-healthchecks</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.datastax.cassandra</groupId>
            <artifactId>cassandra-driver-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</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.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-apache-client4</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-client</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-configuration</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-jackson</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-logging</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-jetty</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-testing</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-util</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cassandra</groupId>
            <artifactId>cassandra-all</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-client</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty.orbit</groupId>
            <artifactId>javax.servlet</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-http</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <!-- Prevent tests from running until emodb-sdk servers are started -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/*Test.java</exclude>
                    </excludes>
                </configuration>
            </plugin>

            <!-- Run the tests -->
            <!-- Debugging: attach on port 5005 after running mvn -Dmaven.failsafe.debug verify -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/*Test.java</include>
                            </includes>
                            <skip>${skipTests}</skip>
                            <suiteXmlFiles>
                                <suiteXmlFile>${integration.suiteXmlFile}</suiteXmlFile>
                            </suiteXmlFiles>
                            <systemPropertyVariables>
                                <runAdaptiveCqlIntegrationTests>${runAdaptiveCqlIntegrationTests}</runAdaptiveCqlIntegrationTests>

                                <emoVersion>${emodb.version}</emoVersion>

                                <apiKey>${apiKey}</apiKey>
                                <zkConnection>${zkConnection}</zkConnection>
                                <zkNamespace>${zkNamespace}</zkNamespace>
                                <clusterName>${clusterName}</clusterName>
                                <placement>${placement}</placement>
                                <remotePlacement>${remotePlacement}</remotePlacement>
                                <mediaPlacement>${mediaPlacement}</mediaPlacement>

                                <clientHttpKeepAlive>${clientHttpKeepAlive}</clientHttpKeepAlive>
                                <clientHttpTimeout>${clientHttpTimeout}</clientHttpTimeout>

                                <testng.dtd.http>true</testng.dtd.http>
                                <resources>${project.basedir}/src/test/resources/</resources>
                            </systemPropertyVariables>
                        </configuration>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <id>start-emodb</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <!-- Start/stop a local zookeeper, one cassandra and 2 emodb servers, one per role. -->
                    <!-- Runs inside the Maven launcher's JVM. -->
                    <!-- Ports specified below must match config yaml entries -->
                    <plugin>
                        <groupId>com.bazaarvoice.emodb</groupId>
                        <artifactId>emodb-sdk</artifactId>
                        <version>${project.version}</version>
                        <executions>
                            <execution>
                                <id>start-emodb-all</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <healthCheckPort>8481</healthCheckPort>
                                    <cassandraRpcPort>9160</cassandraRpcPort>
                                    <emoConfigurationFile>${config-all-role-yaml}</emoConfigurationFile>
                                    <cassandraDir>${project.build.directory}/cassandra</cassandraDir>
                                    <emoDir>emodb-all</emoDir>
                                    <autoStartCassandra>true</autoStartCassandra>
                                    <autoStartZookeeper>true</autoStartZookeeper>
                                    <autoStartEmo>true</autoStartEmo>
                                    <skip>${skipTests}</skip>
                                    <emoLogFile>${basedir}/target/emodb-all.log</emoLogFile>
                                    <roles>
                                        <role>
                                            <name>anonymous</name>
                                            <permissions>
                                                <permission>sor|if(or("read","create_table"))|*</permission>
                                                <permission>blob|read|*</permission>
                                                <permission>databus|*</permission>
                                                <permission>queue|*</permission>
                                                <permission>stash|*</permission>
                                            </permissions>
                                        </role>
                                    </roles>
                                </configuration>
                            </execution>

                            <execution>
                                <id>start-emodb-stash</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <healthCheckPort>8681</healthCheckPort>
                                    <cassandraRpcPort>9160</cassandraRpcPort>
                                    <emoConfigurationFile>${config-stash-role-yaml}</emoConfigurationFile>
                                    <cassandraDir>${project.build.directory}/cassandra</cassandraDir>
                                    <emoDir>emodb-stash</emoDir>
                                    <autoStartCassandra>false</autoStartCassandra>
                                    <autoStartZookeeper>false</autoStartZookeeper>
                                    <autoStartEmo>true</autoStartEmo>
                                    <emoLogFile>${basedir}/target/emodb-stash.log</emoLogFile>
                                    <skip>${skipTests}</skip>
                                </configuration>
                            </execution>

                            <execution>
                                <id>stop-all-emodbs</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <autoStartEmo>true</autoStartEmo>
                            <skip>${skipTests}</skip>
                            <waitForInterrupt>${emodb.pause}</waitForInterrupt>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
