From 0d2a80a4c9a3df215604ed55fc0cd2a7ae465c11 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 1 Jun 2024 20:58:50 +0100 Subject: [PATCH] test: create custom repository save scenarios Signed-off-by: Otavio Santana --- .../query/CustomRepositoryHandlerTest.java | 39 +++++++++++++++++++ .../mapping/semistructured/query/People.java | 10 +++++ 2 files changed, 49 insertions(+) diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/query/CustomRepositoryHandlerTest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/query/CustomRepositoryHandlerTest.java index a4a103c2e..46650af3d 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/query/CustomRepositoryHandlerTest.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/query/CustomRepositoryHandlerTest.java @@ -165,6 +165,45 @@ void shouldDeleteArrayEntity() { Mockito.verifyNoMoreInteractions(template); } + @Test + void shouldSaveEntity() { + Person person = Person.builder().withAge(26).withName("Ada").build(); + Mockito.when(template.insert(person)).thenReturn(person); + Person result = people.save(person); + + Mockito.verify(template).insert(person); + Mockito.verify(template).find(Person.class, 0L); + Assertions.assertThat(result).isEqualTo(person); + } + + @Test + void shouldSaveListEntity() { + Person ada = Person.builder().withAge(26).withName("Ada").build(); + var persons = List.of(ada); + Mockito.when(template.insert(persons)).thenReturn(persons); + Mockito.when(template.insert(ada)).thenReturn(ada); + List result = people.save(persons); + + Mockito.verify(template).insert(ada); + Mockito.verify(template).find(Person.class, 0L); + Assertions.assertThat(result).isEqualTo(persons); + } + + @Test + void shouldSaveArrayEntity() { + Person ada = Person.builder().withAge(26).withName("Ada").build(); + var persons = new Person[]{ada}; + Mockito.when(template.insert(Mockito.any())).thenReturn(List.of(ada)); + Mockito.when(template.insert(ada)).thenReturn(ada); + Person[] result = people.save(persons); + + Mockito.verify(template).insert(ada); + Mockito.verify(template).find(Person.class, 0L); + Assertions.assertThat(result).isEqualTo(persons); + } + + + @Test void shouldExecuteObjectMethods(){ Assertions.assertThat(people.toString()).isNotNull(); diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/query/People.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/query/People.java index b09b0dadf..342e28d78 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/query/People.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/query/People.java @@ -23,6 +23,7 @@ import jakarta.data.repository.Insert; import jakarta.data.repository.Param; import jakarta.data.repository.Query; +import jakarta.data.repository.Save; import jakarta.data.repository.Update; import org.eclipse.jnosql.mapping.semistructured.entities.Person; @@ -50,6 +51,15 @@ public interface People { @Update Person[] update(Person[] person); + @Save + List save(List people); + + @Save + Person save(Person person); + + @Save + Person[] save(Person[] person); + @Delete void delete(List people);