diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/client/ClientConfigurationTest.java b/src/test/java/io/vanslog/spring/data/meilisearch/client/ClientConfigurationUnitTest.java similarity index 89% rename from src/test/java/io/vanslog/spring/data/meilisearch/client/ClientConfigurationTest.java rename to src/test/java/io/vanslog/spring/data/meilisearch/client/ClientConfigurationUnitTest.java index e9c7cd68..a3ed82a7 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/client/ClientConfigurationTest.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/client/ClientConfigurationUnitTest.java @@ -16,19 +16,17 @@ package io.vanslog.spring.data.meilisearch.client; -import static org.assertj.core.api.AssertionsForClassTypes.*; +import static org.assertj.core.api.Assertions.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.meilisearch.sdk.json.GsonJsonHandler; - /** * Tests for {@link ClientConfiguration}. * * @author Junghoon Ban */ -class ClientConfigurationTest { +class ClientConfigurationUnitTest { ClientConfiguration clientConfiguration; diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchConfigurationTest.java b/src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchConfigurationUnitTests.java similarity index 96% rename from src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchConfigurationTest.java rename to src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchConfigurationUnitTests.java index 2fd6d6bd..224e8fe2 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchConfigurationTest.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchConfigurationUnitTests.java @@ -16,7 +16,7 @@ package io.vanslog.spring.data.meilisearch.config; -import static org.assertj.core.api.AssertionsForClassTypes.*; +import static org.assertj.core.api.Assertions.*; import io.vanslog.spring.data.meilisearch.client.ClientConfiguration; import io.vanslog.spring.data.meilisearch.client.MeilisearchClient; @@ -42,7 +42,7 @@ */ @ExtendWith(SpringExtension.class) @ContextConfiguration -class MeilisearchConfigurationTest { +class MeilisearchConfigurationUnitTests { @Autowired private MeilisearchClient meilisearchClient; @Autowired private MeilisearchOperations meilisearchTemplate; diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchNamespaceHandlerTest.java b/src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchNamespaceHandlerUnitTests.java similarity index 97% rename from src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchNamespaceHandlerTest.java rename to src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchNamespaceHandlerUnitTests.java index c1ed9e99..8fb847a3 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchNamespaceHandlerTest.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/config/MeilisearchNamespaceHandlerUnitTests.java @@ -33,8 +33,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import com.meilisearch.sdk.Client; - /** * Namespace based configuration test. * @@ -42,7 +40,7 @@ */ @ExtendWith(SpringExtension.class) @ContextConfiguration("namespace.xml") -class MeilisearchNamespaceHandlerTest { +class MeilisearchNamespaceHandlerUnitTests { @Autowired private ApplicationContext context; diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/core/MeilisearchTemplateTest.java b/src/test/java/io/vanslog/spring/data/meilisearch/core/MeilisearchTemplateIntegrationTests.java similarity index 67% rename from src/test/java/io/vanslog/spring/data/meilisearch/core/MeilisearchTemplateTest.java rename to src/test/java/io/vanslog/spring/data/meilisearch/core/MeilisearchTemplateIntegrationTests.java index e29a11b4..b702bcb8 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/core/MeilisearchTemplateTest.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/core/MeilisearchTemplateIntegrationTests.java @@ -16,9 +16,10 @@ package io.vanslog.spring.data.meilisearch.core; -import static org.assertj.core.api.AssertionsForClassTypes.*; +import static org.assertj.core.api.Assertions.*; import io.vanslog.spring.data.meilisearch.annotations.Document; +import io.vanslog.spring.data.meilisearch.client.MeilisearchClient; import io.vanslog.spring.data.meilisearch.entities.Movie; import io.vanslog.spring.data.meilisearch.junit.jupiter.MeilisearchTest; import io.vanslog.spring.data.meilisearch.junit.jupiter.MeilisearchTestConfiguration; @@ -31,6 +32,8 @@ import org.springframework.data.annotation.Id; import org.springframework.test.context.ContextConfiguration; +import com.meilisearch.sdk.exceptions.MeilisearchException; + /** * Integration tests for {@link MeilisearchTemplate}. * @@ -38,8 +41,9 @@ */ @MeilisearchTest @ContextConfiguration(classes = { MeilisearchTestConfiguration.class }) -class MeilisearchTemplateTest { +class MeilisearchTemplateIntegrationTests { + @Autowired MeilisearchClient meilisearchClient; @Autowired MeilisearchOperations meilisearchTemplate; Movie movie1 = new Movie(1, "Carol", "A love story", new String[] { "Romance", "Drama" }); @@ -47,13 +51,33 @@ class MeilisearchTemplateTest { Movie movie3 = new Movie(3, "Life of Pi", "A survival film", new String[] { "Adventure", "Drama" }); @BeforeEach - void setUp() { - meilisearchTemplate.deleteAll(Movie.class); + void setUp() throws MeilisearchException { + meilisearchClient.index("movies").deleteAllDocuments(); + } + + @Test + void shouldSaveEntity() { + + Movie saved = meilisearchTemplate.save(movie1); + + assertThat(saved).isEqualTo(movie1); } @Test - void shouldSaveDocument() { + void shouldSaveEntities() { + + List movies = List.of(movie1, movie2); + + List saved = meilisearchTemplate.save(movies); + + assertThat(saved).isEqualTo(movies); + } + + @Test + void shouldGetEntity() { + meilisearchTemplate.save(movie1); + Movie saved = meilisearchTemplate.get("1", Movie.class); assertThat(saved.getId()).isEqualTo(movie1.getId()); @@ -63,76 +87,91 @@ void shouldSaveDocument() { } @Test - void shouldSaveDocuments() { - List movies = List.of(movie1, movie2); + void shouldGetEntities() { + List movies = List.of(movie1, movie2, movie3); meilisearchTemplate.save(movies); - List saved = meilisearchTemplate.multiGet(Movie.class); - assertThat(saved.size()).isEqualTo(movies.size()); + List savedMovies = meilisearchTemplate.multiGet(Movie.class); + + assertThat(savedMovies).containsExactlyInAnyOrder(movie1, movie2, movie3); } @Test - void shouldDeleteDocument() { - meilisearchTemplate.save(movie1); - meilisearchTemplate.delete(movie1); + void shouldGetCertainEntities() { - Movie saved = meilisearchTemplate.get("1", Movie.class); - assertThat(saved).isNull(); + List movies = List.of(movie1, movie2, movie3); + meilisearchTemplate.save(movies); + + List savedMovies = meilisearchTemplate.multiGet(Movie.class, List.of("1", "3")); + + assertThat(savedMovies).containsExactlyInAnyOrder(movie1, movie3); } @Test - void shouldDeleteDocuments() { - meilisearchTemplate.save(List.of(movie1, movie2, movie3)); - meilisearchTemplate.delete(Movie.class, List.of("1", "2")); + void returnTrueWhenDocumentExists() { + + meilisearchTemplate.save(movie1); - List saved = meilisearchTemplate.multiGet(Movie.class); + boolean exists = meilisearchTemplate.exists("1", Movie.class); - assertThat(saved.size()).isEqualTo(1); + assertThat(exists).isTrue(); } @Test - void shouldDeleteAllDocuments() { - meilisearchTemplate.save(List.of(movie1, movie2)); - meilisearchTemplate.deleteAll(Movie.class); + void returnFalseWhenDocumentDoesNotExist() { - List saved = meilisearchTemplate.multiGet(Movie.class); + meilisearchTemplate.save(movie1); + meilisearchTemplate.delete(movie1); + + boolean exists = meilisearchTemplate.exists("1", Movie.class); - assertThat(saved.size()).isZero(); + assertThat(exists).isFalse(); } @Test void shouldCountDocuments() { + meilisearchTemplate.save(List.of(movie1, movie2)); + long count = meilisearchTemplate.count(Movie.class); + assertThat(count).isEqualTo(2); } @Test - void shouldExistsDocument() { + void shouldDeleteDocument() { + meilisearchTemplate.save(movie1); - boolean exists = meilisearchTemplate.exists("1", Movie.class); - boolean nonExists = meilisearchTemplate.exists("2", Movie.class); + meilisearchTemplate.delete(movie1); - assertThat(exists).isTrue(); - assertThat(nonExists).isFalse(); + assertThat(meilisearchTemplate.get("1", Movie.class)).isNull(); } @Test - void shouldGetCertainDocuments() { - List movies = List.of(movie1, movie2, movie3); + void shouldDeleteDocuments() { - meilisearchTemplate.save(movies); - List saved = meilisearchTemplate.multiGet(Movie.class, List.of("1", "3", "4")); + meilisearchTemplate.save(List.of(movie1, movie2, movie3)); + + boolean result = meilisearchTemplate.delete(Movie.class, List.of("1", "2")); - assertThat(saved.size()).isEqualTo(2); - assertThat(saved.get(0).getTitle()).isEqualTo(movie1.getTitle()); - assertThat(saved.get(1).getTitle()).isEqualTo(movie3.getTitle()); + assertThat(result).isTrue(); } @Test - void shouldSaveDocumentWithAnnotatedIdField() { + void shouldDeleteAllDocuments() { + + meilisearchTemplate.save(List.of(movie1, movie2)); + + boolean result = meilisearchTemplate.deleteAll(Movie.class); + + assertThat(result).isTrue(); + } + + @Test + void shouldSaveEntityWithAnnotatedIdField() { + AnnotatedIdField annotatedIdField = new AnnotatedIdField(); String documentId = "idField"; annotatedIdField.setName(documentId); diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MappingMeilisearchConverterTest.java b/src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MappingMeilisearchConverterUnitTests.java similarity index 96% rename from src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MappingMeilisearchConverterTest.java rename to src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MappingMeilisearchConverterUnitTests.java index b97e1975..c97af57f 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MappingMeilisearchConverterTest.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MappingMeilisearchConverterUnitTests.java @@ -28,7 +28,7 @@ * * @author Junghoon Ban */ -class MappingMeilisearchConverterTest { +class MappingMeilisearchConverterUnitTests { private MappingMeilisearchConverter converter; diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversionsTests.java b/src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversionsUnitTest.java similarity index 65% rename from src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversionsTests.java rename to src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversionsUnitTest.java index 4c3bab98..327238bc 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversionsTests.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversionsUnitTest.java @@ -1,6 +1,21 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.vanslog.spring.data.meilisearch.core.convert; -import static org.assertj.core.api.AssertionsForClassTypes.*; +import static org.assertj.core.api.Assertions.*; import io.vanslog.spring.data.meilisearch.config.MeilisearchConfigurationSupport; @@ -18,7 +33,7 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration -public class MeilisearchCustomConversionsTests { +class MeilisearchCustomConversionsUnitTest { @Autowired MeilisearchConverter meilisearchConverter; diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentEntityTests.java b/src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentEntityUnitTests.java similarity index 97% rename from src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentEntityTests.java rename to src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentEntityUnitTests.java index e621de1d..cc061bef 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentEntityTests.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentEntityUnitTests.java @@ -29,7 +29,7 @@ * * @author Junghoon Ban */ -class SimpleMeilisearchPersistentEntityTests { +class SimpleMeilisearchPersistentEntityUnitTests { @Test void shouldReturnIndexUid() { diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentPropertyTest.java b/src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentPropertyUnitTests.java similarity index 98% rename from src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentPropertyTest.java rename to src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentPropertyUnitTests.java index bd3f20d1..c2820e51 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentPropertyTest.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/core/mapping/SimpleMeilisearchPersistentPropertyUnitTests.java @@ -27,7 +27,7 @@ * * @author Junghoon Ban */ -class SimpleMeilisearchPersistentPropertyTest { +class SimpleMeilisearchPersistentPropertyUnitTests { private final SimpleMeilisearchMappingContext context = new SimpleMeilisearchMappingContext(); @Test diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/entities/Movie.java b/src/test/java/io/vanslog/spring/data/meilisearch/entities/Movie.java index 802b05fe..9e84c367 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/entities/Movie.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/entities/Movie.java @@ -18,6 +18,9 @@ import io.vanslog.spring.data.meilisearch.annotations.Document; +import java.util.Arrays; +import java.util.Objects; + import org.springframework.data.annotation.Id; /** @@ -74,4 +77,28 @@ public String[] getGenres() { public void setGenres(String[] genres) { this.genres = genres; } + + @Override + public boolean equals(Object object) { + + if (this == object) { + return true; + } + + if (object == null || getClass() != object.getClass()) { + return false; + } + + Movie movie = (Movie) object; + return id == movie.id && Objects.equals(title, movie.title) && Objects.equals(description, movie.description) + && Arrays.equals(genres, movie.genres); + } + + @Override + public int hashCode() { + + int result = Objects.hash(id, title, description); + result = 31 * result + Arrays.hashCode(genres); + return result; + } } diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/repository/MeilisearchRepositoryIntegrationTest.java b/src/test/java/io/vanslog/spring/data/meilisearch/repository/MeilisearchRepositoryIntegrationTests.java similarity index 98% rename from src/test/java/io/vanslog/spring/data/meilisearch/repository/MeilisearchRepositoryIntegrationTest.java rename to src/test/java/io/vanslog/spring/data/meilisearch/repository/MeilisearchRepositoryIntegrationTests.java index 3b62b2cf..5ee85def 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/repository/MeilisearchRepositoryIntegrationTest.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/repository/MeilisearchRepositoryIntegrationTests.java @@ -16,7 +16,7 @@ package io.vanslog.spring.data.meilisearch.repository; -import static org.assertj.core.api.AssertionsForClassTypes.*; +import static org.assertj.core.api.Assertions.*; import io.vanslog.spring.data.meilisearch.entities.Movie; import io.vanslog.spring.data.meilisearch.junit.jupiter.MeilisearchTest; @@ -39,8 +39,8 @@ * @author Junghoon Ban */ @MeilisearchTest -@ContextConfiguration(classes = MeilisearchRepositoryIntegrationTest.Config.class) -class MeilisearchRepositoryIntegrationTest { +@ContextConfiguration(classes = MeilisearchRepositoryIntegrationTests.Config.class) +class MeilisearchRepositoryIntegrationTests { @Autowired private MovieRepository movieRepository; diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/repository/support/MeilisearchEntityInformationCreatorImplTest.java b/src/test/java/io/vanslog/spring/data/meilisearch/repository/support/MeilisearchEntityInformationCreatorImplUnitTests.java similarity index 90% rename from src/test/java/io/vanslog/spring/data/meilisearch/repository/support/MeilisearchEntityInformationCreatorImplTest.java rename to src/test/java/io/vanslog/spring/data/meilisearch/repository/support/MeilisearchEntityInformationCreatorImplUnitTests.java index 65e9a908..dfadf566 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/repository/support/MeilisearchEntityInformationCreatorImplTest.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/repository/support/MeilisearchEntityInformationCreatorImplUnitTests.java @@ -16,8 +16,7 @@ package io.vanslog.spring.data.meilisearch.repository.support; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; import io.vanslog.spring.data.meilisearch.annotations.Document; import io.vanslog.spring.data.meilisearch.core.mapping.SimpleMeilisearchMappingContext; @@ -32,7 +31,7 @@ * * @author Junghoon Ban */ -class MeilisearchEntityInformationCreatorImplTest { +class MeilisearchEntityInformationCreatorImplUnitTests { MeilisearchEntityInformationCreatorImpl entityInformationCreator; @@ -60,7 +59,7 @@ void shouldThrowIllegalArgumentExceptionOnMissingIdAnnotation() { } @Document(indexUid = "entity-no-id") - class EntityNoId { + static class EntityNoId { } }