Skip to content

Commit

Permalink
Merge branch 'feature/add-redis-embedded-module' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Marthym committed Feb 3, 2024
2 parents 009617b + 31f36d3 commit ceafdf5
Show file tree
Hide file tree
Showing 19 changed files with 389 additions and 13 deletions.
26 changes: 21 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?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">
<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>

<groupId>fr.ght1pc9kc</groupId>
<artifactId>testy-box</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Testy Box</name>
Expand All @@ -30,6 +31,7 @@
<module>testy-mongo-box</module>
<module>testy-beat-box</module>
<module>testy-params-box</module>
<module>testy-redis-box</module>
</modules>

<properties>
Expand All @@ -47,17 +49,19 @@

<amqp-client.version>5.20.0</amqp-client.version>
<embed-mongo.version>4.10.0</embed-mongo.version>
<embedded-redis.version>1.3.0</embedded-redis.version>
<flyway.version>9.22.3</flyway.version>
<h2.version>2.2.220</h2.version>
<jackson.version>2.15.3</jackson.version>
<jakarta-xml-bind.version>4.0.1</jakarta-xml-bind.version>
<jooq.version>3.18.7</jooq.version>
<lettuce.version>6.3.0.RELEASE</lettuce.version>
<mongodb-driver.version>4.9.1</mongodb-driver.version>
<qbit.version>9.1.0</qbit.version>
<reactor-rabbitmq.version>1.5.6</reactor-rabbitmq.version>
<reactor.version>3.5.11</reactor.version>
<slf4j.version>2.0.9</slf4j.version>
<spring-mongo.version>4.1.5</spring-mongo.version>
<jakarta-xml-bind.version>4.0.1</jakarta-xml-bind.version>

<assertj.version>3.24.2</assertj.version>
<logback.version>1.4.11</logback.version>
Expand All @@ -80,7 +84,7 @@
<maven-surefire-plugin.version>3.2.1</maven-surefire-plugin.version>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>

<surefire.argline.opens />
<surefire.argline.opens/>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -191,6 +195,18 @@
<version>${java-inject.version}</version>
</dependency>

<!-- REDIS-->
<dependency>
<groupId>com.github.codemonstur</groupId>
<artifactId>embedded-redis</artifactId>
<version>${embedded-redis.version}</version>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>${lettuce.version}</version>
</dependency>

<!-- PROVIDED -->
<dependency>
<groupId>org.jetbrains</groupId>
Expand Down Expand Up @@ -290,7 +306,7 @@
<configuration>
<argLine>${surefire.argline.opens}</argLine>
<excludes>
<exclude />
<exclude/>
</excludes>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion testy-beat-box/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>fr.ght1pc9kc</groupId>
<artifactId>testy-box</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>

<artifactId>testy-beat-box</artifactId>
Expand Down
7 changes: 6 additions & 1 deletion testy-core-box/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
<parent>
<groupId>fr.ght1pc9kc</groupId>
<artifactId>testy-box</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>

<artifactId>testy-core-box</artifactId>

<name>Testy Core Box</name>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fr.ght1pc9kc.testy.core.exceptions;

public class RandomPortException extends RuntimeException {
public RandomPortException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.ght1pc9kc.testy.core.utils;

import fr.ght1pc9kc.testy.core.exceptions.RandomPortException;
import lombok.experimental.UtilityClass;

import java.io.IOException;
import java.net.ServerSocket;

@UtilityClass
public class PortUtils {
/**
* Find a free random port on the local machine
* Use {@link ServerSocket}.
*
* @return the free port as integer
*/
public static int randomFreePort() {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
} catch (IOException e) {
throw new RandomPortException("Unable to found a free port !", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.ght1pc9kc.testy.core.utils;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

class PortUtilsTest {
@Test
void should_find_free_port() {
Assertions.assertThat(PortUtils.randomFreePort()).isPositive();
}
}
2 changes: 1 addition & 1 deletion testy-jooq-box/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>fr.ght1pc9kc</groupId>
<artifactId>testy-box</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>

<artifactId>testy-jooq-box</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion testy-mongo-box/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>fr.ght1pc9kc</groupId>
<artifactId>testy-box</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>

<artifactId>testy-mongo-box</artifactId>
Expand Down Expand Up @@ -62,6 +62,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public interface MongoDataSet<T> {
*/
List<T> documents();

default String identifier() {
return "_id";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
* </pre>
*/
public final class WithMongoData implements BeforeEachCallback {
private static final String MONGO_ID_FIELD = "_id";

private final WithEmbeddedMongo wEmbeddedMongo;
private final @Nullable WithObjectMapper wObjectMapper;
Expand Down Expand Up @@ -119,9 +120,14 @@ private void fillCollection(ReactiveMongoTemplate mongoDb, ObjectMapper objectMa
if (o instanceof Document document) {
return document;
}
return objectMapper.convertValue(o, Document.class);
})
.toList();
Document doc = objectMapper.convertValue(o, Document.class);
Object identifier = doc.get(dataSet.identifier());
if (identifier != null) {
doc.remove(dataSet.identifier());
doc.put(MONGO_ID_FIELD, identifier);
}
return doc;
}).toList();

mongoDb.insertAll(Mono.just(toInsert), collectionName).blockLast();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@

import fr.ght1pc9kc.testy.core.extensions.ChainedExtension;
import fr.ght1pc9kc.testy.core.extensions.WithObjectMapper;
import fr.ght1pc9kc.testy.mongo.sample.ClazzDataSet;
import fr.ght1pc9kc.testy.mongo.sample.DocumentDataSet;
import org.bson.Document;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;

import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

class WithMongoDataTest {

private static final String COLLECTION_0 = "firstCollection";
private static final String COLLECTION_1 = "secondCollection";
private static final String COLLECTION_2 = "dummyCollection";

private static final WithEmbeddedMongo WITH_EMBEDDED_MONGO = WithEmbeddedMongo.builder()
.build();
Expand All @@ -28,6 +32,7 @@ class WithMongoDataTest {
.withObjectMapper(WITH_OBJECT_MAPPER)
.addDataset(COLLECTION_0, new DocumentDataSet())
.addDataset(COLLECTION_1, new DocumentDataSet())
.addDataset(COLLECTION_2, new ClazzDataSet())
.build();

@RegisterExtension
Expand Down Expand Up @@ -60,4 +65,14 @@ void should_have_inserted_data(String collectionName) {
DocumentDataSet.DOCUMENT_WITH_MONGO_ID);
}

@Test
void should_have_inserted_clazz_data() {
final List<Document> actual = mongoTemplate.findAll(Document.class, COLLECTION_2)
.collectList()
.block();

assertThat(actual).containsExactly(
new Document(Map.of("_id", "Luke", "bar", "Skywalker")),
new Document(Map.of("_id", "Obiwan", "bar", "Kenobi")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.ght1pc9kc.testy.mongo.sample;

import fr.ght1pc9kc.testy.dummy.Dummy;
import fr.ght1pc9kc.testy.mongo.MongoDataSet;

import java.util.List;

public class ClazzDataSet implements MongoDataSet<Dummy> {
@Override
public List<Dummy> documents() {
return List.of(
new Dummy("Luke", "Skywalker"),
new Dummy("Obiwan", "Kenobi"));
}

@Override
public String identifier() {
return "foo";
}
}
2 changes: 1 addition & 1 deletion testy-params-box/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>fr.ght1pc9kc</groupId>
<artifactId>testy-box</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>

<artifactId>testy-params-box</artifactId>
Expand Down
58 changes: 58 additions & 0 deletions testy-redis-box/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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>fr.ght1pc9kc</groupId>
<artifactId>testy-box</artifactId>
<version>1.7.0-SNAPSHOT</version>
</parent>

<artifactId>testy-redis-box</artifactId>

<dependencies>
<dependency>
<groupId>fr.ght1pc9kc</groupId>
<artifactId>testy-core-box</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>com.github.codemonstur</groupId>
<artifactId>embedded-redis</artifactId>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</dependency>

<!-- PROVIDED-->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<!-- TEST -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.ght1pc9kc.testy.redis;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface RedisPort {
}
Loading

0 comments on commit ceafdf5

Please sign in to comment.