Skip to content

Test PR #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4d5001e
Support `@Struct` aggregate embeddable mapping
stIncMale Apr 22, 2025
5ea5108
Merge branch 'main' into HIBERNATE-59
stIncMale Apr 23, 2025
eba5762
Replace `AbstractMqlTranslator.toBsonValue` with `ValueConversions.to…
stIncMale Apr 23, 2025
2e98c98
Replace `Session.get` calls with `Session.find` calls, because Hibern…
stIncMale Apr 24, 2025
d9caa01
Add `nestedEmptyValue` test, fix a bug in `ModelMutationMqlTranslator`
stIncMale Apr 25, 2025
aff8089
Add the polymorphism check
stIncMale Apr 25, 2025
b6c9fdf
Test `@Parent` mapping
stIncMale Apr 25, 2025
1da9b20
Replace the formula check with an assertion
stIncMale Apr 25, 2025
a0e0ecf
Add the "test" prefix
stIncMale Apr 25, 2025
f36cf37
Remove stray `public` access modifiers
stIncMale Apr 25, 2025
63702d6
Fix the format string
stIncMale Apr 25, 2025
9330d1e
Add `testFlattenedEmptyValue` similar to `testNestedEmptyValue`
stIncMale Apr 25, 2025
c3c024c
Fix `@Nullable` placement
stIncMale Apr 25, 2025
fe6190f
Improve the code comments in `EmbeddableIntegrationTests`
stIncMale Apr 29, 2025
e138a81
Use equality that ignores the omitted field instead of asserting that…
stIncMale May 1, 2025
12f3bf6
Split tests
stIncMale May 2, 2025
f4e5391
Use JSON instead of `BsonDocument` when specifying expectations
stIncMale May 2, 2025
7091bb4
Rename types used in tests
stIncMale May 2, 2025
293f882
Minor change to the new tests
stIncMale May 7, 2025
3d203c1
Merge branch 'main' into HIBERNATE-59
stIncMale May 9, 2025
a84a20c
Automatic formatting changes
stIncMale May 9, 2025
f89c344
Throw `SQLFeatureNotSupportedException` from methods in `ValueConvers…
stIncMale May 9, 2025
e72228b
Minor changes
stIncMale May 9, 2025
09d4921
Rename `assertEquals` to `assertEq`
stIncMale May 16, 2025
166e517
Introduce constructors for test entity/value types
stIncMale May 20, 2025
956cc1a
Rename test value types
stIncMale May 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

package com.mongodb.hibernate;

import static com.mongodb.hibernate.MongoTestAssertions.assertEquals;
import static com.mongodb.hibernate.MongoTestAssertions.assertEq;
import static org.assertj.core.api.Assertions.assertThat;

import com.mongodb.client.MongoCollection;
import com.mongodb.hibernate.junit.InjectMongoCollection;
import com.mongodb.hibernate.junit.MongoExtension;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
Expand All @@ -39,10 +37,7 @@

@SessionFactory(exportSchema = false)
@DomainModel(
annotatedClasses = {
BasicCrudIntegrationTests.Book.class,
BasicCrudIntegrationTests.BookWithEmbeddedField.class,
BasicCrudIntegrationTests.BookDynamicallyUpdated.class
annotatedClasses = {BasicCrudIntegrationTests.Book.class, BasicCrudIntegrationTests.BookDynamicallyUpdated.class
})
@ExtendWith(MongoExtension.class)
class BasicCrudIntegrationTests implements SessionFactoryScopeAware {
Expand Down Expand Up @@ -106,31 +101,6 @@ void testEntityWithNullFieldValueInsertion() {
.formatted(author));
assertCollectionContainsExactly(expectedDocument);
}

@Test
void testEntityWithEmbeddedFieldInsertion() {
sessionFactoryScope.inTransaction(session -> {
var book = new BookWithEmbeddedField();
book.id = 1;
book.title = "War and Peace";
var author = new Author();
author.firstName = "Leo";
author.lastName = "Tolstoy";
book.author = author;
book.publishYear = 1867;
session.persist(book);
});
var expectedDocument = BsonDocument.parse(
"""
{
_id: 1,
title: "War and Peace",
authorFirstName: "Leo",
authorLastName: "Tolstoy",
publishYear: 1867
}""");
assertCollectionContainsExactly(expectedDocument);
}
}

@Nested
Expand Down Expand Up @@ -219,7 +189,7 @@ void testFindByPrimaryKeyWithoutNullValueField() {

sessionFactoryScope.inTransaction(session -> session.persist(book));
var loadedBook = sessionFactoryScope.fromTransaction(session -> session.find(Book.class, 1));
assertEquals(book, loadedBook);
assertEq(book, loadedBook);
}

@Test
Expand All @@ -236,7 +206,7 @@ void testFindByPrimaryKeyWithNullValueField() {

sessionFactoryScope.inTransaction(session -> session.persist(book));
var loadedBook = sessionFactoryScope.fromTransaction(session -> session.find(Book.class, 1));
assertEquals(book, loadedBook);
assertEq(book, loadedBook);
}
}

Expand Down Expand Up @@ -270,27 +240,4 @@ static class BookDynamicallyUpdated {

int publishYear;
}

@Entity
@Table(name = "books")
static class BookWithEmbeddedField {
@Id
int id;

String title;

Author author;

int publishYear;
}

@Embeddable
static class Author {

@Column(name = "authorFirstName")
String firstName;

@Column(name = "authorLastName")
String lastName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

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

import java.util.function.BiConsumer;
import org.assertj.core.api.RecursiveComparisonAssert;
import org.jspecify.annotations.Nullable;

public final class MongoTestAssertions {
Expand All @@ -28,11 +30,19 @@ private MongoTestAssertions() {}
* {@link org.junit.jupiter.api.Assertions#assertEquals(Object, Object)}. It should work even if
* {@code expected}/{@code actual} does not override {@link Object#equals(Object)}.
*/
public static void assertEquals(@Nullable Object expected, @Nullable Object actual) {
assertThat(actual)
.usingRecursiveComparison()
.usingOverriddenEquals()
.withStrictTypeChecking()
.isEqualTo(expected);
public static void assertEq(@Nullable Object expected, @Nullable Object actual) {
assertUsingRecursiveComparison(expected, actual, RecursiveComparisonAssert::isEqualTo);
}

public static void assertUsingRecursiveComparison(
@Nullable Object expected,
@Nullable Object actual,
BiConsumer<RecursiveComparisonAssert<?>, Object> assertion) {
assertion.accept(
assertThat(expected)
.usingRecursiveComparison()
.usingOverriddenEquals()
.withStrictTypeChecking(),
actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.mongodb.hibernate.junit.MongoExtension;
import org.bson.BsonDocument;
import org.bson.BsonString;
import org.hibernate.cfg.Configuration;
import org.hibernate.boot.MetadataSources;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

Expand All @@ -50,7 +50,7 @@ void couldNotInstantiateDialect() {
}
}
"""))) {
new Configuration().buildSessionFactory().close();
new MetadataSources().buildMetadata();
}
})
.hasRootCause(
Expand Down
Loading