Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The current development branch targets **Java 17**, **Maven 4**, and the **Mongo
- **Java 17** (Temurin) — enforced in `.sdkmanrc` and `pom.xml`
- **Maven 4** (wrapper at `./mvnw`) — use the wrapper, not a system Maven
- **Kotlin** — compiled alongside Java in the `kotlin/` subproject
- **TestNG** — test framework (not JUnit)
- **JUnit** — test framework
- **Testcontainers** — spins up a real `mongo:<major>` Docker container for tests
- **SmallRye Config** — drives `MorphiaConfig` via `morphia-config.properties` on the classpath

Expand Down Expand Up @@ -65,7 +65,7 @@ Use `test-all.sh` for an interactive matrix test across multiple server / driver

### Framework and conventions

- **TestNG** is used; no JUnit.
- **JUnit** is used
- Tests that need a running MongoDB instance extend `TestBase` (in `core/src/test/java/dev/morphia/test/`).
- `MorphiaTestSetup` (parent of `TestBase`) starts a Testcontainers `MongoDBContainer` in `@BeforeSuite`; tests share a single container per suite run.
- Pass `-Dmongodb=local` to point at a local `mongod` on `27017` instead of a container.
Expand Down
93 changes: 0 additions & 93 deletions .github/upgrade-test-pom.xml

This file was deleted.

10 changes: 5 additions & 5 deletions audits/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>com.antwerkz.super-expressive</groupId>
<artifactId>super-expressive</artifactId>
<version>0.3.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
29 changes: 16 additions & 13 deletions audits/src/main/kotlin/dev/morphia/audits/RstAuditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.jboss.forge.roaster.model.Visibility.PUBLIC
import org.jboss.forge.roaster.model.source.JavaClassSource
import org.jboss.forge.roaster.model.source.MethodSource
import org.jboss.forge.roaster.model.source.ParameterSource
import org.junit.jupiter.api.Test

class RstAuditor(val type: OperatorType) {
companion object {
Expand Down Expand Up @@ -116,11 +117,11 @@ class RstAuditor(val type: OperatorType) {
val docRoot = File(DOC_ROOT, "modules/ROOT/pages/${type.docsName()}.adoc")
docRoot.writeText(
"""
[%header,cols="1,2,3"]
|===
|Operator|Docs|Test Examples
[%header,cols="1,2,3"]
|===
|Operator|Docs|Test Examples


"""
.trimIndent()
)
Expand Down Expand Up @@ -240,7 +241,7 @@ class RstAuditor(val type: OperatorType) {
method: MethodSource<JavaClassSource>,
example: OperatorExample,
) {
val annotation = method.getAnnotation("org.testng.annotations.Test")
val annotation = method.getAnnotation(Test::class.java)
if (annotation.getStringValue("testName") == null) {
annotation.setStringValue("testName", example.name)
}
Expand All @@ -252,22 +253,24 @@ class RstAuditor(val type: OperatorType) {
val text = "test data: ${example.folder.relativeTo(coreTestRoot)}\n\n"
method.javaDoc.text = text + example.actionBlock?.lines?.joinToString("\n")

method.addAnnotation("org.testng.annotations.Test").setStringValue("testName", example.name)
method.addAnnotation(Test::class.java).setStringValue("testName", example.name)

if (!example.folder.path.contains("aggregation")) {
method.setBody(
"""
|testQuery((query) -> query.filter( ));
| """
|testQuery((query) -> query.filter( ));
|
"""
.trimMargin()
)
} else {
method.setBody(
"""
|testPipeline(aggregation -> aggregation
| .pipeline(
|
|)); """
|testPipeline(aggregation -> aggregation
| .pipeline(
|
|));
"""
.trimMargin()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dev.morphia.audits.model.Operator
import dev.morphia.audits.model.OperatorType.EXPRESSION
import dev.morphia.audits.model.OperatorType.STAGE
import java.io.File
import org.testng.annotations.Test
import org.junit.jupiter.api.Test

class AggregationAuditTest : BaseAuditTest() {

Expand Down
19 changes: 10 additions & 9 deletions audits/src/test/kotlin/dev/morphia/audits/BaseAuditTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@ package dev.morphia.audits

import dev.morphia.audits.model.Results
import java.io.File
import org.testng.Assert.assertEquals
import org.testng.Assert.assertTrue
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue

open class BaseAuditTest {
protected fun validate(results: Results) {
assertEquals(
results.created.size,
Assertions.assertEquals(
0,
results.created.size,
"All existing operators should be represented: " +
results.created.joinToString("\n\t", prefix = "\n\t") { it.operator },
)
assertEquals(
results.noExamples.size,
Assertions.assertEquals(
0,
results.noExamples.size,
"All existing operators should have examples: " +
results.noExamples.joinToString("\n\t", prefix = "\n\t") {
"${it.operator.name}: ${it.name}"
},
)
assertEquals(
results.noTest.size,
Assertions.assertEquals(
0,
results.noTest.size,
"All existing operators should have test cases: " +
results.noTest.joinToString("\n\t", prefix = "\n\t") {
"${it.operator}: ${it.testSource.relativeTo(File("../").absoluteFile)}"
},
)
val noTags = results.noServerRelease.joinToString("\n", "\n")
assertTrue(
Assertions.assertTrue(
noTags.trim().isEmpty(),
"Some operators are missing server release tags: ${noTags}",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.morphia.audits

import org.testng.annotations.Test
import org.junit.jupiter.api.Test

class OperationAuditTest {
@Test
Expand Down Expand Up @@ -33,6 +33,6 @@ class OperationAuditTest {
}

println("$remaining items to handle")
// assertEquals(created, 0)
// assertEquals(0, created)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dev.morphia.audits.model.Operator
import dev.morphia.audits.model.OperatorType.FILTER
import dev.morphia.audits.model.OperatorType.UPDATE
import java.io.File
import org.testng.annotations.Test
import org.junit.jupiter.api.Test

class QueryAuditTest : BaseAuditTest() {
@Test
Expand Down
6 changes: 3 additions & 3 deletions audits/src/test/kotlin/dev/morphia/audits/SinceAuditTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.morphia.audits
import dev.morphia.audits.model.MorphiaMethod
import dev.morphia.audits.model.State
import dev.morphia.audits.model.Version
import org.testng.Assert
import org.junit.jupiter.api.Assertions

class SinceAuditTest {
fun deprecations() {
Expand All @@ -15,7 +15,7 @@ class SinceAuditTest {
"dev.morphia.query.LegacyQuery#execute()Ldev/morphia/query/internal/MorphiaCursor;"]

method as MorphiaMethod
Assert.assertEquals(State.DEPRECATED, method.versions[Version.v2_1_0_SNAPSHOT])
Assert.assertEquals(State.ABSENT, method.versions[Version.v1_6_0_SNAPSHOT])
Assertions.assertEquals(method.versions[Version.v2_1_0_SNAPSHOT], State.DEPRECATED)
Assertions.assertEquals(method.versions[Version.v1_6_0_SNAPSHOT], State.ABSENT)
}
}
26 changes: 16 additions & 10 deletions audits/src/test/kotlin/dev/morphia/audits/rst/ExampleValidator.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.morphia.audits.rst

import org.testng.Assert
import org.junit.jupiter.api.Assertions

data class ExampleValidator(
val data: Boolean = true,
Expand All @@ -12,12 +12,12 @@ data class ExampleValidator(

fun action(example: OperatorExample) {
if (action) {
Assert.assertNotNull(
Assertions.assertNotNull(
example.actionBlock,
"Should have an action block for ${example.name}",
)
} else {
Assert.assertNull(
Assertions.assertNull(
example.actionBlock,
"Should not have an action block for ${example.name}",
)
Expand All @@ -26,20 +26,26 @@ data class ExampleValidator(

fun data(example: OperatorExample) {
if (data) {
Assert.assertNotNull(example.dataBlock, "Should have a data block for ${example.name}")
Assertions.assertNotNull(
example.dataBlock,
"Should have a data block for ${example.name}",
)
} else {
Assert.assertNull(example.dataBlock, "Should not have a data block for ${example.name}")
Assertions.assertNull(
example.dataBlock,
"Should not have a data block for ${example.name}",
)
}
}

fun expected(example: OperatorExample) {
if (expected) {
Assert.assertNotNull(
Assertions.assertNotNull(
example.expectedBlock,
"Should have an expected block for ${example.name}",
)
} else {
Assert.assertNull(
Assertions.assertNull(
example.expectedBlock,
"Should not have an expected block for ${example.name}",
)
Expand All @@ -48,19 +54,19 @@ data class ExampleValidator(

fun index(example: OperatorExample) {
if (index) {
Assert.assertNotNull(
Assertions.assertNotNull(
example.indexBlock,
"Should have a index block for ${example.name}",
)
} else {
Assert.assertNull(
Assertions.assertNull(
example.indexBlock,
"Should not have a index block for ${example.name}",
)
}
}

fun name(example: OperatorExample, name: String) {
Assert.assertEquals(example.name, name, "Should have the correct name")
Assertions.assertEquals(name, example.name, "Should have the correct name")
}
}
6 changes: 1 addition & 5 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<configuration>
<systemPropertyVariables>
<morphia.mapper>${morphia.mapper}</morphia.mapper>
<junit.jupiter.testinstance.lifecycle.default>per_class</junit.jupiter.testinstance.lifecycle.default>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down Expand Up @@ -178,11 +179,6 @@
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
Expand Down
Loading