Skip to content

Commit

Permalink
Restoring Neo4j unit tests via docker-maven-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Aug 27, 2024
1 parent bc6ef28 commit cfa03cd
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 90 deletions.
109 changes: 98 additions & 11 deletions core/persistence-neo4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ under the License.
<artifactId>bcprov-jdk18on</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>neo4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -99,14 +94,10 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<syncope.connid.location>${syncope.connid.location}</syncope.connid.location>
<CORE_PROPERTIES>classpath:core-test.properties</CORE_PROPERTIES>
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
</systemPropertyVariables>
<skip>true</skip>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand All @@ -126,4 +117,100 @@ under the License.
</testResource>
</testResources>
</build>

<profiles>
<profile>
<id>neo4j</id>

<build>
<defaultGoal>clean verify</defaultGoal>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<systemPropertyVariables>
<CORE_PROPERTIES>classpath:core-test.properties</CORE_PROPERTIES>
<NEO4J_CONTAINER_IP>${docker.container.neo4j.ip}</NEO4J_CONTAINER_IP>
<NEO4J_TWO_CONTAINER_IP>${docker.container.neo4jTwo.ip}</NEO4J_TWO_CONTAINER_IP>
<syncope.connid.location>file:${bundles.directory}/</syncope.connid.location>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<alias>neo4j</alias>
<name>neo4j:${docker.neo4j.version}</name>
<run>
<env>
<NEO4J_AUTH>none</NEO4J_AUTH>
<NEO4JLABS_PLUGINS>["apoc"]</NEO4JLABS_PLUGINS>
</env>
<wait>
<log>Started.</log>
<time>30000</time>
</wait>
<tmpfs>
<mount>/data:rw</mount>
<mount>/logs:rw</mount>
<mount>/var/lib/neo4j/data:rw</mount>
<mount>/var/lib/neo4j/logs:rw</mount>
<mount>/var/lib/neo4j/metrics:rw</mount>
</tmpfs>
</run>
</image>
<image>
<alias>neo4jTwo</alias>
<name>neo4j:${docker.neo4j.version}</name>
<run>
<env>
<NEO4J_AUTH>none</NEO4J_AUTH>
<NEO4JLABS_PLUGINS>["apoc"]</NEO4JLABS_PLUGINS>
</env>
<wait>
<log>Started.</log>
<time>30000</time>
</wait>
<tmpfs>
<mount>/data:rw</mount>
<mount>/logs:rw</mount>
<mount>/var/lib/neo4j/data:rw</mount>
<mount>/var/lib/neo4j/logs:rw</mount>
<mount>/var/lib/neo4j/metrics:rw</mount>
</tmpfs>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>start-neo4j</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-neo4j</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>remove</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,75 +18,16 @@
*/
package org.apache.syncope.core.persistence.neo4j;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
import org.apache.syncope.core.persistence.api.entity.EntityFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.testcontainers.containers.Neo4jContainer;

@SpringJUnitConfig(classes = { MasterDomain.class, PersistenceTestContext.class })
@DirtiesContext
public abstract class AbstractTest {

private static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class);

private static final Neo4jContainer<?> MASTER_DOMAIN;

private static final Neo4jContainer<?> TWO_DOMAIN;

static {
String dockerVersion = null;
try (InputStream propStream = AbstractTest.class.getResourceAsStream("/test.properties")) {
Properties props = new Properties();
props.load(propStream);

dockerVersion = props.getProperty("docker.neo4j.version");
} catch (Exception e) {
LOG.error("Could not load /test.properties", e);
}
assertNotNull(dockerVersion);

MASTER_DOMAIN = new Neo4jContainer<>("neo4j:" + dockerVersion).
withTmpFs(Map.of(
"/data", "rw",
"/logs", "rw",
"/var/lib/neo4j/data", "rw",
"/var/lib/neo4j/logs", "rw",
"/var/lib/neo4j/metrics", "rw")).
withoutAuthentication().
withPlugins("apoc").
withReuse(true);
MASTER_DOMAIN.start();
TWO_DOMAIN = new Neo4jContainer<>("neo4j:" + dockerVersion).
withTmpFs(Map.of(
"/data", "rw",
"/logs", "rw",
"/var/lib/neo4j/data", "rw",
"/var/lib/neo4j/logs", "rw",
"/var/lib/neo4j/metrics", "rw")).
withoutAuthentication().
withPlugins("apoc").
withReuse(true);
TWO_DOMAIN.start();
}

@DynamicPropertySource
static void configureProperties(final DynamicPropertyRegistry registry) {
registry.add("BOLT_URL", MASTER_DOMAIN::getBoltUrl);

registry.add("BOLT2_URL", TWO_DOMAIN::getBoltUrl);
}

@Autowired
protected EntityFactory entityFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ security.jwsKey=${jwsKey}
security.secretKey=${secretKey}

persistence.domain[0].key=Master
persistence.domain[0].uri=${BOLT_URL}
persistence.domain[0].uri=bolt://${NEO4J_CONTAINER_IP}:7687/
persistence.domain[0].username=neo4j
persistence.domain[0].password=null

persistence.domain[1].key=Two
persistence.domain[1].uri=${BOLT2_URL}
persistence.domain[1].uri=bolt://${NEO4J_TWO_CONTAINER_IP}:7687/
persistence.domain[1].username=neo4j
persistence.domain[1].password=null
persistence.domain[1].adminPassword=2AA60A8FF7FCD473D321E0146AFD9E26DF395147
Expand Down
17 changes: 0 additions & 17 deletions core/persistence-neo4j/src/test/resources/test.properties

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ under the License.
<docker.mysql.version>9.0</docker.mysql.version>
<docker.mariadb.version>11</docker.mariadb.version>
<docker.oracle.version>23-slim-faststart</docker.oracle.version>
<docker.neo4j.version>5.22.0</docker.neo4j.version>
<docker.neo4j.version>5.23.0</docker.neo4j.version>

<jdbc.postgresql.version>42.7.4</jdbc.postgresql.version>
<jdbc.mysql.version>9.0.0</jdbc.mysql.version>
Expand Down

0 comments on commit cfa03cd

Please sign in to comment.