diff --git a/jnosql-communication/jnosql-communication-semistructured/src/main/java/org/eclipse/jnosql/communication/semistructured/DatabaseConfiguration.java b/jnosql-communication/jnosql-communication-semistructured/src/main/java/org/eclipse/jnosql/communication/semistructured/DatabaseConfiguration.java index 4f9a0e73e..1df593dc6 100644 --- a/jnosql-communication/jnosql-communication-semistructured/src/main/java/org/eclipse/jnosql/communication/semistructured/DatabaseConfiguration.java +++ b/jnosql-communication/jnosql-communication-semistructured/src/main/java/org/eclipse/jnosql/communication/semistructured/DatabaseConfiguration.java @@ -33,11 +33,10 @@ *

Implementations of this interface should be aware of the underlying provider implementation they represent, * and ensure that the correct configuration is returned based on the provided type.

* - * @param the {@link DatabaseManagerFactory} type * @see DatabaseManagerFactory * @see DatabaseManager */ -public interface DatabaseConfiguration extends Function { +public interface DatabaseConfiguration extends Function { /** @@ -52,7 +51,7 @@ public interface DatabaseConfiguration extends * @throws CommunicationException if no implementation of {@link DatabaseConfiguration} is found */ @SuppressWarnings("unchecked") - static > T getConfiguration() { + static T getConfiguration() { return (T) ServiceLoader.load(DatabaseConfiguration.class) .stream() .map(ServiceLoader.Provider::get) @@ -74,7 +73,7 @@ static > T * @throws CommunicationException if no implementation of {@link DatabaseConfiguration} is found for the specified type */ @SuppressWarnings("unchecked") - static > T getConfiguration(Class type) { + static T getConfiguration(Class type) { return (T) ServiceLoader.load(DatabaseConfiguration.class) .stream() .map(ServiceLoader.Provider::get) diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterConstructorTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterConstructorTest.java deleted file mode 100644 index e3a5c9d06..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterConstructorTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.inject.Inject; -import org.assertj.core.api.SoftAssertions; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnEntity; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.entities.Animal; -import org.eclipse.jnosql.mapping.column.entities.Book; -import org.eclipse.jnosql.mapping.column.entities.BookRelease; -import org.eclipse.jnosql.mapping.column.entities.Money; -import org.eclipse.jnosql.mapping.column.entities.constructor.BookUser; -import org.eclipse.jnosql.mapping.column.entities.constructor.Computer; -import org.eclipse.jnosql.mapping.column.entities.constructor.PetOwner; -import org.eclipse.jnosql.mapping.column.entities.constructor.SuperHero; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Test; - -import java.time.Year; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnEntityConverterConstructorTest { - - @Inject - private ColumnEntityConverter converter; - - @Test - void shouldConverterEntityComputer() { - ColumnEntity communication = ColumnEntity.of("Computer"); - communication.add("_id", 10L); - communication.add("name", "Dell"); - communication.add("age", 2020); - communication.add("model", "Dell 2020"); - communication.add("price", "USD 20"); - Computer computer = this.converter.toEntity(communication); - assertNotNull(computer); - assertEquals(10L, computer.getId()); - assertEquals("Dell", computer.getName()); - assertEquals(2020, computer.getAge()); - assertEquals("Dell 2020", computer.getModel()); - assertEquals(Money.parse("USD 20"), computer.getPrice()); - } - - @Test - void shouldConvertComputerToCommunication() { - Computer computer = new Computer(10L, "Dell", 2020, "Dell 2020", - Money.parse("USD 20")); - ColumnEntity communication = this.converter.toColumn(computer); - assertNotNull(communication); - - assertEquals(computer.getId(), communication.find("_id", Long.class).get()); - assertEquals(computer.getName(), communication.find("name", String.class).get()); - assertEquals(computer.getAge(), communication.find("age", int.class).get()); - assertEquals(computer.getModel(), communication.find("model", String.class).get()); - assertEquals(computer.getPrice().toString(), communication.find("price", String.class).get()); - } - - @Test - void shouldConvertPetOwner() { - ColumnEntity communication = ColumnEntity.of("PetOwner"); - communication.add("_id", 10L); - communication.add("name", "Otavio"); - communication.add("animal", Arrays.asList(Column.of("_id", 23) - , Column.of("name", "Ada"))); - - PetOwner petOwner = this.converter.toEntity(communication); - assertNotNull(petOwner); - assertEquals(10L, petOwner.getId()); - assertEquals("Otavio", petOwner.getName()); - Animal animal = petOwner.getAnimal(); - assertEquals(23L, animal.getId()); - assertEquals("Ada", animal.getName()); - } - - @Test - void shouldConvertPetOwnerCommunication() { - Animal ada = new Animal("Ada"); - PetOwner petOwner = new PetOwner(10L, "Poliana", ada); - ColumnEntity communication = this.converter.toColumn(petOwner); - assertNotNull(communication); - assertEquals(10L, communication.find("_id", Long.class).get()); - assertEquals("Poliana", communication.find("name", String.class).get()); - List columns = communication.find("animal", new TypeReference>() {}) - .get(); - assertThat(columns).contains(Column.of("name", "Ada")); - } - - @Test - void shouldConvertBookUser() { - ColumnEntity communication = ColumnEntity.of("BookUser"); - communication.add("_id", "otaviojava"); - communication.add("native_name", "Otavio Santana"); - List> columns = new ArrayList<>(); - columns.add(Arrays.asList(Column.of("_id", 10), Column.of("name", "Effective Java"))); - columns.add(Arrays.asList(Column.of("_id", 12), Column.of("name", "Clean Code"))); - communication.add("books", columns); - - BookUser bookUser = this.converter.toEntity(communication); - assertNotNull(bookUser); - assertEquals("Otavio Santana", bookUser.getName()); - assertEquals("otaviojava", bookUser.getNickname()); - assertEquals(2, bookUser.getBooks().size()); - List names = bookUser.getBooks().stream().map(Book::getName).toList(); - assertThat(names).contains("Effective Java", "Clean Code"); - - } - - @Test - void shouldConverterFieldsOnEntityComputer() { - ColumnEntity communication = ColumnEntity.of("Computer"); - communication.add("_id", "10"); - communication.add("name", "Dell"); - communication.add("age", "2020"); - communication.add("model", "Dell 2020"); - communication.add("price", "USD 20"); - Computer computer = this.converter.toEntity(communication); - assertNotNull(computer); - assertEquals(10L, computer.getId()); - assertEquals("Dell", computer.getName()); - assertEquals(2020, computer.getAge()); - assertEquals("Dell 2020", computer.getModel()); - assertEquals(Money.parse("USD 20"), computer.getPrice()); - } - - @Test - void shouldConverterEntityBookRelease() { - ColumnEntity communication = ColumnEntity.of("BookRelease"); - communication.add("isbn", "9780132345286"); - communication.add("title", "Effective Java"); - communication.add("author", "Joshua Bloch"); - communication.add("year", Year.of(2001)); - BookRelease book = this.converter.toEntity(communication); - assertNotNull(book); - assertEquals("9780132345286", book.getIsbn()); - assertEquals("Effective Java", book.getTitle()); - assertEquals("Joshua Bloch", book.getAuthor()); - assertEquals(Year.of(2001), book.getYear()); - } - - @Test - void shouldConverterEntityBookReleaseOnStringYear() { - ColumnEntity communication = ColumnEntity.of("BookRelease"); - communication.add("isbn", "9780132345286"); - communication.add("title", "Effective Java"); - communication.add("author", "Joshua Bloch"); - communication.add("year", "2001"); - BookRelease book = this.converter.toEntity(communication); - assertNotNull(book); - assertEquals("9780132345286", book.getIsbn()); - assertEquals("Effective Java", book.getTitle()); - assertEquals("Joshua Bloch", book.getAuthor()); - assertEquals(Year.of(2001), book.getYear()); - } - - @Test - void shouldConvertHero() { - ColumnEntity communication = ColumnEntity.of("SuperHero"); - communication.add("_id", "10L"); - communication.add("name", "Otavio"); - communication.add("powers", List.of("speed", "strength")); - - SuperHero hero = this.converter.toEntity(communication); - SoftAssertions.assertSoftly(softly -> { - softly.assertThat(hero.id()).isEqualTo("10L"); - softly.assertThat(hero.name()).isEqualTo("Otavio"); - softly.assertThat(hero.powers()).contains("speed", "strength"); - }); - } - -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterInheritanceTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterInheritanceTest.java deleted file mode 100644 index e4f3dbe01..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterInheritanceTest.java +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.data.exceptions.MappingException; -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnEntity; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.entities.inheritance.EmailNotification; -import org.eclipse.jnosql.mapping.column.entities.inheritance.LargeProject; -import org.eclipse.jnosql.mapping.column.entities.inheritance.Notification; -import org.eclipse.jnosql.mapping.column.entities.inheritance.NotificationReader; -import org.eclipse.jnosql.mapping.column.entities.inheritance.Project; -import org.eclipse.jnosql.mapping.column.entities.inheritance.ProjectManager; -import org.eclipse.jnosql.mapping.column.entities.inheritance.SmallProject; -import org.eclipse.jnosql.mapping.column.entities.inheritance.SmsNotification; -import org.eclipse.jnosql.mapping.column.entities.inheritance.SocialMediaNotification; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.math.BigDecimal; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnEntityConverterInheritanceTest { - - @Inject - private ColumnEntityConverter converter; - - @Test - void shouldConvertProjectToSmallProject() { - ColumnEntity entity = ColumnEntity.of("Project"); - entity.add("_id", "Small Project"); - entity.add("investor", "Otavio Santana"); - entity.add("size", "Small"); - Project project = this.converter.toEntity(entity); - assertEquals("Small Project", project.getName()); - assertEquals(SmallProject.class, project.getClass()); - SmallProject smallProject = SmallProject.class.cast(project); - assertEquals("Otavio Santana", smallProject.getInvestor()); - } - - @Test - void shouldConvertProjectToLargeProject() { - ColumnEntity entity = ColumnEntity.of("Project"); - entity.add("_id", "Large Project"); - entity.add("budget", BigDecimal.TEN); - entity.add("size", "Large"); - Project project = this.converter.toEntity(entity); - assertEquals("Large Project", project.getName()); - assertEquals(LargeProject.class, project.getClass()); - LargeProject smallProject = LargeProject.class.cast(project); - assertEquals(BigDecimal.TEN, smallProject.getBudget()); - } - - @Test - void shouldConvertLargeProjectToCommunicationEntity() { - LargeProject project = new LargeProject(); - project.setName("Large Project"); - project.setBudget(BigDecimal.TEN); - ColumnEntity entity = this.converter.toColumn(project); - assertNotNull(entity); - assertEquals("Project", entity.name()); - assertEquals(project.getName(), entity.find("_id", String.class).get()); - assertEquals(project.getBudget(), entity.find("budget", BigDecimal.class).get()); - assertEquals("Large", entity.find("size", String.class).get()); - } - - @Test - void shouldConvertSmallProjectToCommunicationEntity() { - SmallProject project = new SmallProject(); - project.setName("Small Project"); - project.setInvestor("Otavio Santana"); - ColumnEntity entity = this.converter.toColumn(project); - assertNotNull(entity); - assertEquals("Project", entity.name()); - assertEquals(project.getName(), entity.find("_id", String.class).get()); - assertEquals(project.getInvestor(), entity.find("investor", String.class).get()); - assertEquals("Small", entity.find("size", String.class).get()); - } - - @Test - void shouldConvertProject() { - ColumnEntity entity = ColumnEntity.of("Project"); - entity.add("_id", "Project"); - entity.add("size", "Project"); - Project project = this.converter.toEntity(entity); - assertEquals("Project", project.getName()); - } - - @Test - void shouldConvertProjectToCommunicationEntity() { - Project project = new Project(); - project.setName("Large Project"); - ColumnEntity entity = this.converter.toColumn(project); - assertNotNull(entity); - assertEquals("Project", entity.name()); - assertEquals(project.getName(), entity.find("_id", String.class).get()); - assertEquals("Project", entity.find("size", String.class).get()); - } - - @Test - void shouldConvertColumnEntityToSocialMedia(){ - LocalDate date = LocalDate.now(); - ColumnEntity entity = ColumnEntity.of("Notification"); - entity.add("_id", 100L); - entity.add("name", "Social Media"); - entity.add("nickname", "otaviojava"); - entity.add("createdOn",date); - entity.add("dtype", SocialMediaNotification.class.getSimpleName()); - SocialMediaNotification notification = this.converter.toEntity(entity); - assertEquals(100L, notification.getId()); - assertEquals("Social Media", notification.getName()); - assertEquals("otaviojava", notification.getNickname()); - assertEquals(date, notification.getCreatedOn()); - } - - @Test - void shouldConvertColumnEntityToSms(){ - LocalDate date = LocalDate.now(); - ColumnEntity entity = ColumnEntity.of("Notification"); - entity.add("_id", 100L); - entity.add("name", "SMS Notification"); - entity.add("phone", "+351987654123"); - entity.add("createdOn", date); - entity.add("dtype", "SMS"); - SmsNotification notification = this.converter.toEntity(entity); - Assertions.assertEquals(100L, notification.getId()); - Assertions.assertEquals("SMS Notification", notification.getName()); - Assertions.assertEquals("+351987654123", notification.getPhone()); - assertEquals(date, notification.getCreatedOn()); - } - - @Test - void shouldConvertColumnEntityToEmail(){ - LocalDate date = LocalDate.now(); - ColumnEntity entity = ColumnEntity.of("Notification"); - entity.add("_id", 100L); - entity.add("name", "Email Notification"); - entity.add("email", "otavio@otavio.test"); - entity.add("createdOn", date); - entity.add("dtype", "Email"); - EmailNotification notification = this.converter.toEntity(entity); - Assertions.assertEquals(100L, notification.getId()); - Assertions.assertEquals("Email Notification", notification.getName()); - Assertions.assertEquals("otavio@otavio.test", notification.getEmail()); - assertEquals(date, notification.getCreatedOn()); - } - - @Test - void shouldConvertSocialMediaToCommunicationEntity(){ - SocialMediaNotification notification = new SocialMediaNotification(); - notification.setId(100L); - notification.setName("Social Media"); - notification.setCreatedOn(LocalDate.now()); - notification.setNickname("otaviojava"); - ColumnEntity entity = this.converter.toColumn(notification); - assertNotNull(entity); - assertEquals("Notification", entity.name()); - assertEquals(notification.getId(), entity.find("_id", Long.class).get()); - assertEquals(notification.getName(), entity.find("name", String.class).get()); - assertEquals(notification.getNickname(), entity.find("nickname", String.class).get()); - assertEquals(notification.getCreatedOn(), entity.find("createdOn", LocalDate.class).get()); - } - - @Test - void shouldConvertSmsToCommunicationEntity(){ - SmsNotification notification = new SmsNotification(); - notification.setId(100L); - notification.setName("SMS"); - notification.setCreatedOn(LocalDate.now()); - notification.setPhone("+351123456987"); - ColumnEntity entity = this.converter.toColumn(notification); - assertNotNull(entity); - assertEquals("Notification", entity.name()); - assertEquals(notification.getId(), entity.find("_id", Long.class).get()); - assertEquals(notification.getName(), entity.find("name", String.class).get()); - assertEquals(notification.getPhone(), entity.find("phone", String.class).get()); - assertEquals(notification.getCreatedOn(), entity.find("createdOn", LocalDate.class).get()); - } - - @Test - void shouldConvertEmailToCommunicationEntity(){ - EmailNotification notification = new EmailNotification(); - notification.setId(100L); - notification.setName("Email Media"); - notification.setCreatedOn(LocalDate.now()); - notification.setEmail("otavio@otavio.test.com"); - ColumnEntity entity = this.converter.toColumn(notification); - assertNotNull(entity); - assertEquals("Notification", entity.name()); - assertEquals(notification.getId(), entity.find("_id", Long.class).get()); - assertEquals(notification.getName(), entity.find("name", String.class).get()); - assertEquals(notification.getEmail(), entity.find("email", String.class).get()); - assertEquals(notification.getCreatedOn(), entity.find("createdOn", LocalDate.class).get()); - } - - @Test - void shouldReturnErrorWhenConvertMissingColumn(){ - LocalDate date = LocalDate.now(); - ColumnEntity entity = ColumnEntity.of("Notification"); - entity.add("_id", 100L); - entity.add("name", "SMS Notification"); - entity.add("phone", "+351987654123"); - entity.add("createdOn", date); - Assertions.assertThrows(MappingException.class, ()-> this.converter.toEntity(entity)); - } - - @Test - void shouldReturnErrorWhenMismatchField() { - LocalDate date = LocalDate.now(); - ColumnEntity entity = ColumnEntity.of("Notification"); - entity.add("_id", 100L); - entity.add("name", "Email Notification"); - entity.add("email", "otavio@otavio.test"); - entity.add("createdOn", date); - entity.add("dtype", "Wrong"); - Assertions.assertThrows(MappingException.class, ()-> this.converter.toEntity(entity)); - } - - - - @Test - void shouldConvertCommunicationNotificationReaderEmail() { - ColumnEntity entity = ColumnEntity.of("NotificationReader"); - entity.add("_id", "poli"); - entity.add("name", "Poliana Santana"); - entity.add("notification", Arrays.asList( - Column.of("_id", 10L), - Column.of("name", "News"), - Column.of("email", "otavio@email.com"), - Column.of("_id", LocalDate.now()), - Column.of("dtype", "Email") - )); - - NotificationReader notificationReader = converter.toEntity(entity); - assertNotNull(notificationReader); - Assertions.assertEquals("poli", notificationReader.getNickname()); - Assertions.assertEquals("Poliana Santana", notificationReader.getName()); - Notification notification = notificationReader.getNotification(); - assertNotNull(notification); - Assertions.assertEquals(EmailNotification.class, notification.getClass()); - EmailNotification email = (EmailNotification) notification; - Assertions.assertEquals(10L, email.getId()); - Assertions.assertEquals("News", email.getName()); - Assertions.assertEquals("otavio@email.com", email.getEmail()); - } - - @Test - void shouldConvertCommunicationNotificationReaderSms() { - ColumnEntity entity = ColumnEntity.of("NotificationReader"); - entity.add("_id", "poli"); - entity.add("name", "Poliana Santana"); - entity.add("notification", Arrays.asList( - Column.of("_id", 10L), - Column.of("name", "News"), - Column.of("phone", "123456789"), - Column.of("_id", LocalDate.now()), - Column.of("dtype", "SMS") - )); - - NotificationReader notificationReader = converter.toEntity(entity); - assertNotNull(notificationReader); - Assertions.assertEquals("poli", notificationReader.getNickname()); - Assertions.assertEquals("Poliana Santana", notificationReader.getName()); - Notification notification = notificationReader.getNotification(); - assertNotNull(notification); - Assertions.assertEquals(SmsNotification.class, notification.getClass()); - SmsNotification sms = (SmsNotification) notification; - Assertions.assertEquals(10L, sms.getId()); - Assertions.assertEquals("News", sms.getName()); - Assertions.assertEquals("123456789", sms.getPhone()); - } - - @Test - void shouldConvertCommunicationNotificationReaderSocial() { - ColumnEntity entity = ColumnEntity.of("NotificationReader"); - entity.add("_id", "poli"); - entity.add("name", "Poliana Santana"); - entity.add("notification", Arrays.asList( - Column.of("_id", 10L), - Column.of("name", "News"), - Column.of("nickname", "123456789"), - Column.of("_id", LocalDate.now()), - Column.of("dtype", "SocialMediaNotification") - )); - - NotificationReader notificationReader = converter.toEntity(entity); - assertNotNull(notificationReader); - Assertions.assertEquals("poli", notificationReader.getNickname()); - Assertions.assertEquals("Poliana Santana", notificationReader.getName()); - Notification notification = notificationReader.getNotification(); - assertNotNull(notification); - Assertions.assertEquals(SocialMediaNotification.class, notification.getClass()); - SocialMediaNotification social = (SocialMediaNotification) notification; - Assertions.assertEquals(10L, social.getId()); - Assertions.assertEquals("News", social.getName()); - Assertions.assertEquals("123456789", social.getNickname()); - } - - @Test - void shouldConvertSocialCommunication() { - SocialMediaNotification notification = new SocialMediaNotification(); - notification.setId(10L); - notification.setName("Ada"); - notification.setNickname("ada.lovelace"); - NotificationReader reader = new NotificationReader("otavio", "Otavio", notification); - - ColumnEntity entity = this.converter.toColumn(reader); - assertNotNull(entity); - - assertEquals("NotificationReader", entity.name()); - assertEquals("otavio", entity.find("_id", String.class).get()); - assertEquals("Otavio", entity.find("name", String.class).get()); - List columns = entity.find("notification", new TypeReference>() { - }).get(); - - assertThat(columns).contains(Column.of("_id", 10L), - Column.of("name", "Ada"), - Column.of("dtype", "SocialMediaNotification"), - Column.of("nickname", "ada.lovelace")); - } - - @Test - void shouldConvertConvertProjectManagerCommunication() { - LargeProject large = new LargeProject(); - large.setBudget(BigDecimal.TEN); - large.setName("large"); - - SmallProject small = new SmallProject(); - small.setInvestor("new investor"); - small.setName("Start up"); - - List projects = new ArrayList<>(); - projects.add(large); - projects.add(small); - - ProjectManager manager = ProjectManager.of(10L, "manager", projects); - ColumnEntity entity = this.converter.toColumn(manager); - assertNotNull(entity); - - assertEquals("ProjectManager", entity.name()); - assertEquals(10L, entity.find("_id", Long.class).get()); - assertEquals("manager", entity.find("name", String.class).get()); - - List> columns = (List>) entity.find("projects").get().get(); - - List largeCommunication = columns.get(0); - List smallCommunication = columns.get(1); - assertThat(largeCommunication).contains( - Column.of("_id", "large"), - Column.of("size", "Large"), - Column.of("budget", BigDecimal.TEN) - ); - - assertThat(smallCommunication).contains( - Column.of("size", "Small"), - Column.of("investor", "new investor"), - Column.of("_id", "Start up") - ); - - } - - @Test - void shouldConvertConvertCommunicationProjectManager() { - ColumnEntity communication = ColumnEntity.of("ProjectManager"); - communication.add("_id", 10L); - communication.add("name", "manager"); - List> columns = new ArrayList<>(); - columns.add(Arrays.asList( - Column.of("_id","small-project"), - Column.of("size","Small"), - Column.of("investor","investor") - )); - columns.add(Arrays.asList( - Column.of("_id","large-project"), - Column.of("size","Large"), - Column.of("budget",BigDecimal.TEN) - )); - communication.add("projects", columns); - - ProjectManager manager = converter.toEntity(communication); - assertNotNull(manager); - - assertEquals(10L, manager.getId()); - assertEquals("manager", manager.getName()); - - List projects = manager.getProjects(); - assertEquals(2, projects.size()); - SmallProject small = (SmallProject) projects.get(0); - LargeProject large = (LargeProject) projects.get(1); - assertNotNull(small); - assertEquals("small-project", small.getName()); - assertEquals("investor", small.getInvestor()); - - assertNotNull(large); - assertEquals("large-project", large.getName()); - assertEquals(BigDecimal.TEN, large.getBudget()); - - } -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterTest.java deleted file mode 100644 index ebb753c98..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityConverterTest.java +++ /dev/null @@ -1,603 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.inject.Inject; -import org.assertj.core.api.SoftAssertions; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.Value; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnEntity; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.entities.Actor; -import org.eclipse.jnosql.mapping.column.entities.Address; -import org.eclipse.jnosql.mapping.column.entities.AppointmentBook; -import org.eclipse.jnosql.mapping.column.entities.Citizen; -import org.eclipse.jnosql.mapping.column.entities.Contact; -import org.eclipse.jnosql.mapping.column.entities.ContactType; -import org.eclipse.jnosql.mapping.column.entities.Director; -import org.eclipse.jnosql.mapping.column.entities.Download; -import org.eclipse.jnosql.mapping.column.entities.Job; -import org.eclipse.jnosql.mapping.column.entities.MainStepType; -import org.eclipse.jnosql.mapping.column.entities.Money; -import org.eclipse.jnosql.mapping.column.entities.Movie; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.entities.Transition; -import org.eclipse.jnosql.mapping.column.entities.Vendor; -import org.eclipse.jnosql.mapping.column.entities.Worker; -import org.eclipse.jnosql.mapping.column.entities.WorkflowStep; -import org.eclipse.jnosql.mapping.column.entities.ZipCode; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Stream; - -import static java.util.Arrays.asList; -import static java.util.Collections.singleton; -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.jnosql.mapping.column.entities.StepTransitionReason.REPEAT; -import static org.junit.jupiter.api.Assertions.*; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnEntityConverterTest { - - @Inject - private DefaultColumnEntityConverter converter; - - private Column[] columns; - - private final Actor actor = Actor.actorBuilder().withAge() - .withId() - .withName() - .withPhones(asList("234", "2342")) - .withMovieCharacter(Collections.singletonMap("JavaZone", "Jedi")) - .withMovieRating(Collections.singletonMap("JavaZone", 10)) - .build(); - - @BeforeEach - void init() { - - columns = new Column[]{Column.of("_id", 12L), - Column.of("age", 10), Column.of("name", "Otavio"), - Column.of("phones", asList("234", "2342")) - , Column.of("movieCharacter", Collections.singletonMap("JavaZone", "Jedi")) - , Column.of("movieRating", Collections.singletonMap("JavaZone", 10))}; - } - - @Test - void shouldConvertEntityFromColumnEntity() { - - Person person = Person.builder().withAge() - .withId(12) - .withName("Otavio") - .withPhones(asList("234", "2342")).build(); - - ColumnEntity entity = converter.toColumn(person); - assertEquals("Person", entity.name()); - assertEquals(4, entity.size()); - assertThat(entity.columns()).contains(Column.of("_id", 12L), - Column.of("age", 10), Column.of("name", "Otavio"), - Column.of("phones", Arrays.asList("234", "2342"))); - - } - - @Test - void shouldConvertColumnEntityFromEntity() { - - ColumnEntity entity = converter.toColumn(actor); - assertEquals("Actor", entity.name()); - assertEquals(6, entity.size()); - - assertThat(entity.columns()).contains(columns); - } - - @Test - void shouldConvertColumnEntityToEntity() { - ColumnEntity entity = ColumnEntity.of("Actor"); - Stream.of(columns).forEach(entity::add); - - Actor actor = converter.toEntity(Actor.class, entity); - assertNotNull(actor); - assertEquals(10, actor.getAge()); - assertEquals(12L, actor.getId()); - assertEquals(asList("234", "2342"), actor.getPhones()); - assertEquals(Collections.singletonMap("JavaZone", "Jedi"), actor.getMovieCharacter()); - assertEquals(Collections.singletonMap("JavaZone", 10), actor.getMovieRating()); - } - - @Test - void shouldConvertColumnEntityToEntity2() { - ColumnEntity entity = ColumnEntity.of("Actor"); - Stream.of(columns).forEach(entity::add); - - Actor actor = converter.toEntity(entity); - assertNotNull(actor); - assertEquals(10, actor.getAge()); - assertEquals(12L, actor.getId()); - assertEquals(asList("234", "2342"), actor.getPhones()); - assertEquals(Collections.singletonMap("JavaZone", "Jedi"), actor.getMovieCharacter()); - assertEquals(Collections.singletonMap("JavaZone", 10), actor.getMovieRating()); - } - - @Test - void shouldConvertColumnEntityToExistEntity() { - ColumnEntity entity = ColumnEntity.of("Actor"); - Stream.of(columns).forEach(entity::add); - Actor actor = Actor.actorBuilder().build(); - Actor result = converter.toEntity(actor, entity); - - assertSame(actor, result); - assertEquals(10, actor.getAge()); - assertEquals(12L, actor.getId()); - assertEquals(asList("234", "2342"), actor.getPhones()); - assertEquals(Collections.singletonMap("JavaZone", "Jedi"), actor.getMovieCharacter()); - assertEquals(Collections.singletonMap("JavaZone", 10), actor.getMovieRating()); - } - - @Test - void shouldReturnErrorWhenToEntityIsNull() { - ColumnEntity entity = ColumnEntity.of("Actor"); - Stream.of(columns).forEach(entity::add); - Actor actor = Actor.actorBuilder().build(); - - assertThrows(NullPointerException.class, () -> converter.toEntity(null, entity)); - - assertThrows(NullPointerException.class, () -> converter.toEntity(actor, null)); - } - - - @Test - void shouldConvertEntityToColumnEntity2() { - - Movie movie = new Movie("Matrix", 2012, Collections.singleton("Actor")); - Director director = Director.builderDirector().withAge(12) - .withId(12) - .withName("Otavio") - .withPhones(asList("234", "2342")).withMovie(movie).build(); - - ColumnEntity entity = converter.toColumn(director); - assertEquals(5, entity.size()); - - assertEquals(getValue(entity.find("name")), director.getName()); - assertEquals(getValue(entity.find("age")), director.getAge()); - assertEquals(getValue(entity.find("_id")), director.getId()); - assertEquals(getValue(entity.find("phones")), director.getPhones()); - - - Column subColumn = entity.find("movie").get(); - List columns = subColumn.get(new TypeReference<>() { - }); - - assertEquals(3, columns.size()); - assertEquals("movie", subColumn.name()); - assertEquals(movie.getTitle(), columns.stream().filter(c -> "title".equals(c.name())).findFirst().get().get()); - assertEquals(movie.getYear(), columns.stream().filter(c -> "year".equals(c.name())).findFirst().get().get()); - assertEquals(movie.getActors(), columns.stream().filter(c -> "actors".equals(c.name())).findFirst().get().get()); - - - } - - @Test - void shouldConvertToEmbeddedClassWhenHasSubColumn() { - Movie movie = new Movie("Matrix", 2012, Collections.singleton("Actor")); - Director director = Director.builderDirector().withAge(12) - .withId(12) - .withName("Otavio") - .withPhones(asList("234", "2342")).withMovie(movie).build(); - - ColumnEntity entity = converter.toColumn(director); - Director director1 = converter.toEntity(entity); - - assertEquals(movie, director1.getMovie()); - assertEquals(director.getName(), director1.getName()); - assertEquals(director.getAge(), director1.getAge()); - assertEquals(director.getId(), director1.getId()); - } - - @Test - void shouldConvertToEmbeddedClassWhenHasSubColumn2() { - Movie movie = new Movie("Matrix", 2012, singleton("Actor")); - Director director = Director.builderDirector().withAge(12) - .withId(12) - .withName("Otavio") - .withPhones(asList("234", "2342")).withMovie(movie).build(); - - ColumnEntity entity = converter.toColumn(director); - entity.remove("movie"); - entity.add(Column.of("movie", Arrays.asList(Column.of("title", "Matrix"), - Column.of("year", 2012), Column.of("actors", singleton("Actor"))))); - Director director1 = converter.toEntity(entity); - - assertEquals(movie, director1.getMovie()); - assertEquals(director.getName(), director1.getName()); - assertEquals(director.getAge(), director1.getAge()); - assertEquals(director.getId(), director1.getId()); - } - - @Test - void shouldConvertToEmbeddedClassWhenHasSubColumn3() { - Movie movie = new Movie("Matrix", 2012, singleton("Actor")); - Director director = Director.builderDirector().withAge(12) - .withId(12) - .withName("Otavio") - .withPhones(asList("234", "2342")).withMovie(movie).build(); - - ColumnEntity entity = converter.toColumn(director); - entity.remove("movie"); - Map map = new HashMap<>(); - map.put("title", "Matrix"); - map.put("year", 2012); - map.put("actors", singleton("Actor")); - - entity.add(Column.of("movie", map)); - Director director1 = converter.toEntity(entity); - - assertEquals(movie, director1.getMovie()); - assertEquals(director.getName(), director1.getName()); - assertEquals(director.getAge(), director1.getAge()); - assertEquals(director.getId(), director1.getId()); - } - - @Test - void shouldConvertToColumnWhenHaConverter() { - Worker worker = new Worker(); - Job job = new Job(); - job.setCity("Sao Paulo"); - job.setDescription("Java Developer"); - worker.setName("Bob"); - worker.setSalary(new Money("BRL", BigDecimal.TEN)); - worker.setJob(job); - ColumnEntity entity = converter.toColumn(worker); - assertEquals("Worker", entity.name()); - assertEquals("Bob", entity.find("name").get().get()); - assertEquals("Sao Paulo", entity.find("city").get().get()); - assertEquals("Java Developer", entity.find("description").get().get()); - assertEquals("BRL 10", entity.find("money").get().get()); - } - - @Test - void shouldConvertToEntityWhenHasConverter() { - Worker worker = new Worker(); - Job job = new Job(); - job.setCity("Sao Paulo"); - job.setDescription("Java Developer"); - worker.setName("Bob"); - worker.setSalary(new Money("BRL", BigDecimal.TEN)); - worker.setJob(job); - ColumnEntity entity = converter.toColumn(worker); - Worker worker1 = converter.toEntity(entity); - assertEquals(worker.getSalary(), worker1.getSalary()); - assertEquals(job.getCity(), worker1.getJob().getCity()); - assertEquals(job.getDescription(), worker1.getJob().getDescription()); - } - - @Test - void shouldConvertEmbeddableLazily() { - ColumnEntity entity = ColumnEntity.of("Worker"); - entity.add("name", "Otavio"); - entity.add("money", "BRL 10"); - - Worker worker = converter.toEntity(entity); - assertEquals("Otavio", worker.getName()); - assertEquals(new Money("BRL", BigDecimal.TEN), worker.getSalary()); - Assertions.assertNull(worker.getJob()); - - } - - - @Test - void shouldConvertToListEmbeddable() { - AppointmentBook appointmentBook = new AppointmentBook("ids"); - appointmentBook.add(Contact.builder().withType(ContactType.EMAIL) - .withName("Ada").withInformation("ada@lovelace.com").build()); - appointmentBook.add(Contact.builder().withType(ContactType.MOBILE) - .withName("Ada").withInformation("11 1231231 123").build()); - appointmentBook.add(Contact.builder().withType(ContactType.PHONE) - .withName("Ada").withInformation("12 123 1231 123123").build()); - - ColumnEntity entity = converter.toColumn(appointmentBook); - Column contacts = entity.find("contacts").get(); - assertEquals("ids", appointmentBook.getId()); - List> columns = (List>) contacts.get(); - - assertEquals(3L, columns.stream().flatMap(Collection::stream) - .filter(c -> c.name().equals("contact_name")) - .count()); - } - - @Test - void shouldConvertFromListEmbeddable() { - ColumnEntity entity = ColumnEntity.of("AppointmentBook"); - entity.add(Column.of("_id", "ids")); - List> columns = new ArrayList<>(); - - columns.add(asList(Column.of("contact_name", "Ada"), Column.of("type", ContactType.EMAIL), - Column.of("information", "ada@lovelace.com"))); - - columns.add(asList(Column.of("contact_name", "Ada"), Column.of("type", ContactType.MOBILE), - Column.of("information", "11 1231231 123"))); - - columns.add(asList(Column.of("contact_name", "Ada"), Column.of("type", ContactType.PHONE), - Column.of("information", "phone"))); - - entity.add(Column.of("contacts", columns)); - - AppointmentBook appointmentBook = converter.toEntity(entity); - - List contacts = appointmentBook.getContacts(); - assertEquals("ids", appointmentBook.getId()); - assertEquals("Ada", contacts.stream().map(Contact::getName).distinct().findFirst().get()); - - } - - - @Test - void shouldConvertSubEntity() { - ZipCode zipcode = new ZipCode(); - zipcode.setZip("12321"); - zipcode.setPlusFour("1234"); - - Address address = new Address(); - address.setCity("Salvador"); - address.setState("Bahia"); - address.setStreet("Rua Engenheiro Jose Anasoh"); - address.setZipCode(zipcode); - - ColumnEntity columnEntity = converter.toColumn(address); - List columns = columnEntity.columns(); - assertEquals("Address", columnEntity.name()); - assertEquals(4, columns.size()); - List zip = columnEntity.find("zipCode").map(d -> d.get(new TypeReference>() { - })).orElse(Collections.emptyList()); - - assertEquals("Rua Engenheiro Jose Anasoh", getValue(columnEntity.find("street"))); - assertEquals("Salvador", getValue(columnEntity.find("city"))); - assertEquals("Bahia", getValue(columnEntity.find("state"))); - assertEquals("12321", getValue(zip.stream().filter(d -> d.name().equals("zip")).findFirst())); - assertEquals("1234", getValue(zip.stream().filter(d -> d.name().equals("plusFour")).findFirst())); - } - - @Test - void shouldConvertColumnInSubEntity() { - - ColumnEntity entity = ColumnEntity.of("Address"); - - entity.add(Column.of("street", "Rua Engenheiro Jose Anasoh")); - entity.add(Column.of("city", "Salvador")); - entity.add(Column.of("state", "Bahia")); - entity.add(Column.of("zipCode", Arrays.asList( - Column.of("zip", "12321"), - Column.of("plusFour", "1234")))); - Address address = converter.toEntity(entity); - - assertEquals("Rua Engenheiro Jose Anasoh", address.getStreet()); - assertEquals("Salvador", address.getCity()); - assertEquals("Bahia", address.getState()); - assertEquals("12321", address.getZipCode().getZip()); - assertEquals("1234", address.getZipCode().getPlusFour()); - - } - - @Test - void shouldReturnNullWhenThereIsNotSubEntity() { - ColumnEntity entity = ColumnEntity.of("Address"); - - entity.add(Column.of("street", "Rua Engenheiro Jose Anasoh")); - entity.add(Column.of("city", "Salvador")); - entity.add(Column.of("state", "Bahia")); - entity.add(Column.of("zip", "12321")); - entity.add(Column.of("plusFour", "1234")); - - Address address = converter.toEntity(entity); - - assertEquals("Rua Engenheiro Jose Anasoh", address.getStreet()); - assertEquals("Salvador", address.getCity()); - assertEquals("Bahia", address.getState()); - assertNull(address.getZipCode()); - } - - @Test - void shouldConvertAndDoNotUseUnmodifiableCollection() { - ColumnEntity entity = ColumnEntity.of("vendors"); - entity.add("name", "name"); - entity.add("prefixes", Arrays.asList("value", "value2")); - - Vendor vendor = converter.toEntity(entity); - vendor.add("value3"); - - Assertions.assertEquals(3, vendor.getPrefixes().size()); - - } - - @Test - void shouldConvertEntityToDocumentWithArray() { - byte[] contents = {1, 2, 3, 4, 5, 6}; - - ColumnEntity entity = ColumnEntity.of("download"); - entity.add("_id", 1L); - entity.add("contents", contents); - - Download download = converter.toEntity(entity); - Assertions.assertEquals(1L, download.getId()); - Assertions.assertArrayEquals(contents, download.getContents()); - } - - @Test - void shouldConvertDocumentToEntityWithArray() { - byte[] contents = {1, 2, 3, 4, 5, 6}; - - Download download = new Download(); - download.setId(1L); - download.setContents(contents); - - ColumnEntity entity = converter.toColumn(download); - - Assertions.assertEquals(1L, entity.find("_id").get().get()); - final byte[] bytes = entity.find("contents").map(v -> v.get(byte[].class)).orElse(new byte[0]); - Assertions.assertArrayEquals(contents, bytes); - } - - @Test - void shouldCreateUserScope() { - ColumnEntity entity = ColumnEntity.of("UserScope"); - entity.add("_id", "userName"); - entity.add("scope", "scope"); - entity.add("properties", Collections.singletonList(Column.of("halo", "weld"))); - - UserScope user = converter.toEntity(entity); - Assertions.assertNotNull(user); - Assertions.assertEquals("userName",user.getUserName()); - Assertions.assertEquals("scope",user.getScope()); - Assertions.assertEquals(Collections.singletonMap("halo", "weld"),user.getProperties()); - - } - - @Test - void shouldCreateUserScope2() { - ColumnEntity entity = ColumnEntity.of("UserScope"); - entity.add("_id", "userName"); - entity.add("scope", "scope"); - entity.add("properties", Column.of("halo", "weld")); - - UserScope user = converter.toEntity(entity); - Assertions.assertNotNull(user); - Assertions.assertEquals("userName",user.getUserName()); - Assertions.assertEquals("scope",user.getScope()); - Assertions.assertEquals(Collections.singletonMap("halo", "weld"),user.getProperties()); - - } - - @Test - void shouldCreateLazilyEntity() { - ColumnEntity entity = ColumnEntity.of("Citizen"); - entity.add("id", "10"); - entity.add("name", "Salvador"); - - Citizen citizen = converter.toEntity(entity); - Assertions.assertNotNull(citizen); - Assertions.assertNull(citizen.getCity()); - } - - - @Test - void shouldReturnNullValuePresent() { - Person person = Person.builder().build(); - - ColumnEntity entity = converter.toColumn(person); - SoftAssertions.assertSoftly(soft -> { - soft.assertThat(entity.find("name")).isPresent(); - soft.assertThat(entity.find("age")).isPresent(); - soft.assertThat(entity.find("phones")).isPresent(); - soft.assertThat(entity.find("ignore")).isNotPresent(); - - soft.assertThat(entity.find("name", String.class)).isNotPresent(); - soft.assertThat(entity.find("phones", String.class)).isNotPresent(); - }); - } - - @Test - void shouldConvertWorkflow(){ - var workflowStep = WorkflowStep.builder() - .id("id") - .key("key") - .workflowSchemaKey("workflowSchemaKey") - .stepName("stepName") - .mainStepType(MainStepType.MAIN) - .stepNo(1) - .componentConfigurationKey("componentConfigurationKey") - .relationTypeKey("relationTypeKey") - .availableTransitions(List.of(new Transition("TEST_WORKFLOW_STEP_KEY", REPEAT, - null, List.of("ADMIN")))) - .build(); - - var document = this.converter.toColumn(workflowStep); - WorkflowStep result = this.converter.toEntity(document); - SoftAssertions.assertSoftly(soft ->{ - soft.assertThat(result).isNotNull(); - soft.assertThat(result.id()).isEqualTo("id"); - soft.assertThat(result.key()).isEqualTo("key"); - soft.assertThat(result.workflowSchemaKey()).isEqualTo("workflowSchemaKey"); - soft.assertThat(result.stepName()).isEqualTo("stepName"); - soft.assertThat(result.mainStepType()).isEqualTo(MainStepType.MAIN); - soft.assertThat(result.stepNo()).isEqualTo(1L); - soft.assertThat(result.componentConfigurationKey()).isEqualTo("componentConfigurationKey"); - soft.assertThat(result.relationTypeKey()).isEqualTo("relationTypeKey"); - soft.assertThat(result.availableTransitions()).hasSize(1); - soft.assertThat(result.availableTransitions().get(0).targetWorkflowStepKey()).isEqualTo("TEST_WORKFLOW_STEP_KEY"); - soft.assertThat(result.availableTransitions().get(0).stepTransitionReason()).isEqualTo(REPEAT); - soft.assertThat(result.availableTransitions().get(0).mailTemplateKey()).isNull(); - soft.assertThat(result.availableTransitions().get(0).restrictedRoleGroups()).hasSize(1); - soft.assertThat(result.availableTransitions().get(0).restrictedRoleGroups().get(0)).isEqualTo("ADMIN"); - }); - - } - - @Test - void shouldUpdateEmbeddable2() { - var workflowStep = WorkflowStep.builder() - .id("id") - .key("key") - .workflowSchemaKey("workflowSchemaKey") - .stepName("stepName") - .mainStepType(MainStepType.MAIN) - .stepNo(null) - .componentConfigurationKey("componentConfigurationKey") - .relationTypeKey("relationTypeKey") - .availableTransitions(null) - .build(); - var document = this.converter.toColumn(workflowStep); - WorkflowStep result = this.converter.toEntity(document); - SoftAssertions.assertSoftly(soft ->{ - soft.assertThat(result).isNotNull(); - soft.assertThat(result.id()).isEqualTo("id"); - soft.assertThat(result.key()).isEqualTo("key"); - soft.assertThat(result.workflowSchemaKey()).isEqualTo("workflowSchemaKey"); - soft.assertThat(result.stepName()).isEqualTo("stepName"); - soft.assertThat(result.mainStepType()).isEqualTo(MainStepType.MAIN); - soft.assertThat(result.stepNo()).isNull(); - soft.assertThat(result.componentConfigurationKey()).isEqualTo("componentConfigurationKey"); - soft.assertThat(result.relationTypeKey()).isEqualTo("relationTypeKey"); - soft.assertThat(result.availableTransitions()).isNull(); - - }); - - } - - - private Object getValue(Optional column) { - return column.map(Column::value).map(Value::get).orElse(null); - } - -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityImmutableTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityImmutableTest.java deleted file mode 100644 index bda4f1a91..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEntityImmutableTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnEntity; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.entities.Car; -import org.eclipse.jnosql.mapping.column.entities.Hero; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.time.Year; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.junit.jupiter.api.Assertions.*; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnEntityImmutableTest { - - @Inject - private DefaultColumnEntityConverter converter; - - private Column[] columns; - - private Car car; - - @BeforeEach - void init() { - - this.car = new Car("123456789", "SF90", "Ferrari", Year.now()); - - columns = new Column[]{Column.of("_id", "123456789"), - Column.of("model", "SF90"), - Column.of("manufacturer", "Ferrari"), - Column.of("year", Year.now()) - }; - } - - @Test - void shouldConvertCommunicationEntity() { - - ColumnEntity entity = converter.toColumn(car); - assertEquals("Car", entity.name()); - assertEquals(4, entity.size()); - assertThat(entity.columns()).contains(Column.of("_id", "123456789"), - Column.of("model", "SF90"), - Column.of("manufacturer", "Ferrari")); - - } - - @Test - void shouldConvertCommunicationEntity2() { - - ColumnEntity entity = converter.toColumn(car); - assertEquals("Car", entity.name()); - assertEquals(4, entity.size()); - - assertThat(entity.columns()).contains(columns); - } - - @Test - void shouldConvertEntity() { - ColumnEntity entity = ColumnEntity.of("Car"); - Stream.of(columns).forEach(entity::add); - - Car ferrari = converter.toEntity(Car.class, entity); - assertNotNull(ferrari); - assertEquals("123456789", ferrari.plate()); - assertEquals("SF90", ferrari.model()); - assertEquals("Ferrari", ferrari.manufacturer()); - assertEquals(Year.now(), ferrari.year()); - - } - - @Test - void shouldConvertExistRecord() { - ColumnEntity entity = ColumnEntity.of("Car"); - Stream.of(columns).forEach(entity::add); - Car ferrari = new Car(null, null, null, null); - Car result = converter.toEntity(ferrari, entity); - - assertEquals("123456789", result.plate()); - assertEquals("SF90", result.model()); - assertEquals("Ferrari", result.manufacturer()); - assertEquals(Year.now(), result.year()); - assertNotSame(ferrari, car); - assertSoftly(soft -> { - soft.assertThat(ferrari.model()).isNull(); - soft.assertThat(ferrari.manufacturer()).isNull(); - soft.assertThat(ferrari.plate()).isNull(); - soft.assertThat(ferrari.year()).isNull(); - - soft.assertThat(result.model()).isEqualTo("SF90"); - soft.assertThat(result.manufacturer()).isEqualTo("Ferrari"); - soft.assertThat(result.plate()).isEqualTo("123456789"); - soft.assertThat(result.year()).isEqualTo(Year.now()); - }); - } - - @Test - void shouldConvertExist() { - ColumnEntity entity = ColumnEntity.of("Hero"); - entity.add("_id", "2342"); - entity.add("name", "Iron man"); - Hero hero = new Hero(null, null); - Hero result = converter.toEntity(hero, entity); - assertSame(hero, result); - assertSoftly(soft -> { - soft.assertThat(hero.id()).isEqualTo("2342"); - soft.assertThat(hero.name()).isEqualTo("Iron man"); - } - ); - } - - -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEventPersistManagerTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEventPersistManagerTest.java deleted file mode 100644 index 4e6c059e8..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnEventPersistManagerTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.enterprise.event.Event; -import org.eclipse.jnosql.mapping.EntityPostPersist; -import org.eclipse.jnosql.mapping.EntityPrePersist; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.verify; - -@ExtendWith(MockitoExtension.class) -class ColumnEventPersistManagerTest { - - - @InjectMocks - private ColumnEventPersistManager subject; - - - @Mock - private Event entityPrePersistEvent; - - @Mock - private Event entityPostPersistEvent; - - - - - - - @Test - void shouldFirePreEntity() { - Jedi jedi = new Jedi(); - jedi.name = "Luke"; - subject.firePreEntity(jedi); - ArgumentCaptor captor = ArgumentCaptor.forClass(EntityPrePersist.class); - verify(entityPrePersistEvent).fire(captor.capture()); - EntityPrePersist value = captor.getValue(); - assertEquals(jedi, value.get()); - } - - @Test - void shouldFirePostEntity() { - Jedi jedi = new Jedi(); - jedi.name = "Luke"; - subject.firePostEntity(jedi); - ArgumentCaptor captor = ArgumentCaptor.forClass(EntityPostPersist.class); - verify(entityPostPersistEvent).fire(captor.capture()); - EntityPostPersist value = captor.getValue(); - assertEquals(jedi, value.get()); - } - - - static class Jedi { - private String name; - } -} \ No newline at end of file diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnMapperObserverTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnMapperObserverTest.java deleted file mode 100644 index a538b21ba..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnMapperObserverTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.column.ColumnObserverParser; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.entities.Car; -import org.eclipse.jnosql.mapping.column.entities.Vendor; -import org.eclipse.jnosql.mapping.column.entities.Worker; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnMapperObserverTest { - - @Inject - private EntitiesMetadata mappings; - - private ColumnObserverParser parser; - - @BeforeEach - void setUp() { - this.parser = new ColumnMapperObserver(mappings); - } - - @Test - void shouldFireEntity(){ - var entity = parser.fireEntity("Vendor"); - Assertions.assertEquals("vendors", entity); - } - - @Test - void shouldFireFromClass(){ - var entity = parser.fireEntity(Car.class.getSimpleName()); - Assertions.assertEquals("Car", entity); - } - - @Test - void shouldFireFromClassName(){ - var entity = parser.fireEntity(Car.class.getSimpleName()); - Assertions.assertEquals("Car", entity); - } - - @Test - void shouldFireField(){ - var field = parser.fireField("Worker", "salary"); - Assertions.assertEquals("money", field); - } - - @Test - void shouldFireFieldFromClassName(){ - var field = parser.fireField(Worker.class.getName(), "salary"); - Assertions.assertEquals("money", field); - } - - @Test - void shouldFireFieldFromSimplesName(){ - var field = parser.fireField(Worker.class.getSimpleName(), "salary"); - Assertions.assertEquals("money", field); - } - - @Test - void shouldFireFieldFromEntity(){ - var field = parser.fireField(Vendor.class.getSimpleName(), "name"); - Assertions.assertEquals("_id", field); - } - -} \ No newline at end of file diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnTemplateInheritanceTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnTemplateInheritanceTest.java deleted file mode 100644 index 198bc9287..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/ColumnTemplateInheritanceTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.enterprise.inject.Instance; -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.Condition; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnCondition; -import org.eclipse.jnosql.communication.column.ColumnDeleteQuery; -import org.eclipse.jnosql.communication.column.ColumnManager; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.column.entities.inheritance.EmailNotification; -import org.eclipse.jnosql.mapping.column.entities.inheritance.Notification; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; - -import java.util.List; - -import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.mockito.Mockito.when; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnTemplateInheritanceTest { - - @Inject - private ColumnEntityConverter converter; - - @Inject - private EntitiesMetadata entities; - - @Inject - private Converters converters; - - private ColumnManager managerMock; - - private DefaultColumnTemplate template; - - - @BeforeEach - void setUp() { - managerMock = Mockito.mock(ColumnManager.class); - var documentEventPersistManager = Mockito.mock(ColumnEventPersistManager.class); - - Instance instance = Mockito.mock(Instance.class); - when(instance.get()).thenReturn(managerMock); - this.template = new DefaultColumnTemplate(converter, instance, - documentEventPersistManager, entities, converters); - } - - @Test - void shouldSelectFilter(){ - var captor = ArgumentCaptor.forClass(ColumnQuery.class); - template.select(EmailNotification.class).stream().toList(); - Mockito.verify(this.managerMock).select(captor.capture()); - var query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(Condition.EQUALS); - soft.assertThat(condition.column()).isEqualTo(Column.of("dtype", "Email")); - }); - } - - @Test - void shouldSelectNoFilter(){ - var captor = ArgumentCaptor.forClass(ColumnQuery.class); - template.select(Notification.class).stream().toList(); - Mockito.verify(this.managerMock).select(captor.capture()); - var query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isEmpty(); - }); - } - - @Test - void shouldDeleteFilter(){ - var captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - template.delete(EmailNotification.class).execute(); - Mockito.verify(this.managerMock).delete(captor.capture()); - var query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(Condition.EQUALS); - soft.assertThat(condition.column()).isEqualTo(Column.of("dtype", "Email")); - }); - } - - @Test - void shouldDeleteNoFilter(){ - var captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - template.delete(Notification.class).execute(); - Mockito.verify(this.managerMock).delete(captor.capture()); - var query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isEmpty(); - }); - } - - @Test - void shouldSelectFilterCondition(){ - var captor = ArgumentCaptor.forClass(ColumnQuery.class); - template.select(EmailNotification.class).where("name") - .eq("notification").stream().toList(); - Mockito.verify(this.managerMock).select(captor.capture()); - var query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(Condition.AND); - var documents = condition.column().get(new TypeReference>() {}); - soft.assertThat(documents).contains(ColumnCondition.eq(Column.of("dtype", "Email")), - ColumnCondition.eq(Column.of("name", "notification"))); - }); - } - - @Test - void shouldDeleteFilterCondition(){ - var captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - template.delete(EmailNotification.class).where("name") - .eq("notification").execute(); - Mockito.verify(this.managerMock).delete(captor.capture()); - var query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(Condition.AND); - var documents = condition.column().get(new TypeReference>() {}); - soft.assertThat(documents).contains(ColumnCondition.eq(Column.of("dtype", "Email")), - ColumnCondition.eq(Column.of("name", "notification"))); - }); - } - - @Test - void shouldCountAllFilter(){ - var captor = ArgumentCaptor.forClass(ColumnQuery.class); - template.count(EmailNotification.class); - Mockito.verify(this.managerMock).count(captor.capture()); - var query = captor.getValue(); - - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(Condition.EQUALS); - soft.assertThat(condition.column()).isEqualTo(Column.of("dtype", "Email")); - }); - } - - @Test - void shouldFindAllFilter(){ - var captor = ArgumentCaptor.forClass(ColumnQuery.class); - template.findAll(EmailNotification.class); - Mockito.verify(this.managerMock).select(captor.capture()); - var query = captor.getValue(); - - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(Condition.EQUALS); - soft.assertThat(condition.column()).isEqualTo(Column.of("dtype", "Email")); - }); - } - - @Test - void shouldDeleteAllFilter(){ - var captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - template.deleteAll(EmailNotification.class); - Mockito.verify(this.managerMock).delete(captor.capture()); - var query = captor.getValue(); - - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(Condition.EQUALS); - soft.assertThat(condition.column()).isEqualTo(Column.of("dtype", "Email")); - }); - } - - - @Test - void shouldCountAllNoFilter(){ - var captor = ArgumentCaptor.forClass(ColumnQuery.class); - template.count(Notification.class); - Mockito.verify(this.managerMock).count(captor.capture()); - var query = captor.getValue(); - - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isEmpty(); - }); - } - - @Test - void shouldFindAllNoFilter(){ - var captor = ArgumentCaptor.forClass(ColumnQuery.class); - template.findAll(Notification.class); - Mockito.verify(this.managerMock).select(captor.capture()); - var query = captor.getValue(); - - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isEmpty(); - }); - } - @Test - void shouldDeleteAllNoFilter(){ - var captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - template.deleteAll(Notification.class); - Mockito.verify(this.managerMock).delete(captor.capture()); - var query = captor.getValue(); - - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isEmpty(); - }); - } -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/DefaultColumnTemplateTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/DefaultColumnTemplateTest.java deleted file mode 100644 index b09422463..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/DefaultColumnTemplateTest.java +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.data.exceptions.NonUniqueResultException; -import jakarta.enterprise.inject.Instance; -import jakarta.inject.Inject; -import jakarta.nosql.PreparedStatement; -import org.assertj.core.api.SoftAssertions; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnCondition; -import org.eclipse.jnosql.communication.column.ColumnDeleteQuery; -import org.eclipse.jnosql.communication.column.ColumnEntity; -import org.eclipse.jnosql.communication.column.ColumnManager; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.IdNotFoundException; -import org.eclipse.jnosql.mapping.column.entities.Job; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; - -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.eclipse.jnosql.communication.column.ColumnDeleteQuery.delete; -import static org.eclipse.jnosql.communication.column.ColumnQuery.select; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class DefaultColumnTemplateTest { - - private final Person person = Person.builder(). - withAge(). - withPhones(Arrays.asList("234", "432")). - withName("Name") - .withId(19) - .withIgnore().build(); - - private final Column[] columns = new Column[]{ - Column.of("age", 10), - Column.of("phones", Arrays.asList("234", "432")), - Column.of("name", "Name"), - Column.of("id", 19L), - }; - - @Inject - private ColumnEntityConverter converter; - - @Inject - private EntitiesMetadata entities; - - @Inject - private Converters converters; - - private ColumnManager managerMock; - - private DefaultColumnTemplate template; - - private ArgumentCaptor captor; - - private ColumnEventPersistManager columnEventPersistManager; - - @SuppressWarnings("unchecked") - @BeforeEach - void setUp() { - managerMock = Mockito.mock(ColumnManager.class); - columnEventPersistManager = Mockito.mock(ColumnEventPersistManager.class); - captor = ArgumentCaptor.forClass(ColumnEntity.class); - Instance instance = Mockito.mock(Instance.class); - Mockito.when(instance.get()).thenReturn(managerMock); - this.template = new DefaultColumnTemplate(converter, instance, - columnEventPersistManager, entities, converters); - } - - @Test - void shouldInsert() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .insert(any(ColumnEntity.class))) - .thenReturn(columnEntity); - - template.insert(this.person); - verify(managerMock).insert(captor.capture()); - verify(columnEventPersistManager).firePostEntity(any(Person.class)); - verify(columnEventPersistManager).firePreEntity(any(Person.class)); - ColumnEntity value = captor.getValue(); - assertEquals("Person", value.name()); - assertEquals(4, value.columns().size()); - } - - - @Test - void shouldMergeOnInsert() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .insert(any(ColumnEntity.class))) - .thenReturn(columnEntity); - - Person person = Person.builder().build(); - Person result = template.insert(person); - verify(managerMock).insert(captor.capture()); - verify(columnEventPersistManager).firePostEntity(any(Person.class)); - verify(columnEventPersistManager).firePreEntity(any(Person.class)); - assertSame(person, result); - assertEquals(10, person.getAge()); - - } - - - - - @Test - void shouldInsertTTL() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .insert(any(ColumnEntity.class), - any(Duration.class))) - .thenReturn(columnEntity); - - template.insert(this.person, Duration.ofHours(2)); - verify(managerMock).insert(captor.capture(), Mockito.eq(Duration.ofHours(2))); - verify(columnEventPersistManager).firePostEntity(any(Person.class)); - verify(columnEventPersistManager).firePreEntity(any(Person.class)); - ColumnEntity value = captor.getValue(); - assertEquals("Person", value.name()); - assertEquals(4, value.columns().size()); - } - - @Test - void shouldUpdate() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .update(any(ColumnEntity.class))) - .thenReturn(columnEntity); - - template.update(this.person); - verify(managerMock).update(captor.capture()); - verify(columnEventPersistManager).firePostEntity(any(Person.class)); - verify(columnEventPersistManager).firePreEntity(any(Person.class)); - ColumnEntity value = captor.getValue(); - assertEquals("Person", value.name()); - assertEquals(4, value.columns().size()); - } - - @Test - void shouldMergeOnUpdate() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .update(any(ColumnEntity.class))) - .thenReturn(columnEntity); - - Person person = Person.builder().build(); - Person result = template.update(person); - verify(managerMock).update(captor.capture()); - verify(columnEventPersistManager).firePostEntity(any(Person.class)); - verify(columnEventPersistManager).firePreEntity(any(Person.class)); - assertSame(person, result); - assertEquals(10, person.getAge()); - - } - - @Test - void shouldInsertEntitiesTTL() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - Duration duration = Duration.ofHours(2); - - Mockito.when(managerMock - .insert(any(ColumnEntity.class), Mockito.eq(duration))) - .thenReturn(columnEntity); - - template.insert(Arrays.asList(person, person), duration); - verify(managerMock, times(2)).insert(any(ColumnEntity.class), any(Duration.class)); - } - - @Test - void shouldInsertEntities() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .insert(any(ColumnEntity.class))) - .thenReturn(columnEntity); - - template.insert(Arrays.asList(person, person)); - verify(managerMock, times(2)).insert(any(ColumnEntity.class)); - } - - @Test - void shouldUpdateEntities() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .update(any(ColumnEntity.class))) - .thenReturn(columnEntity); - - template.update(Arrays.asList(person, person)); - verify(managerMock, times(2)).update(any(ColumnEntity.class)); - } - - @Test - void shouldDelete() { - - ColumnDeleteQuery query = delete().from("delete").build(); - template.delete(query); - verify(managerMock).delete(query); - } - - @Test - void shouldSelect() { - ColumnQuery query = select().from("person").build(); - template.select(query); - verify(managerMock).select(query); - } - - @Test - void shouldCountBy() { - ColumnQuery query = select().from("person").build(); - template.count(query); - verify(managerMock).count(query); - } - - @Test - void shouldExist() { - ColumnQuery query = select().from("person").build(); - template.exists(query); - verify(managerMock).exists(query); - } - - @Test - void shouldReturnSingleResult() { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .select(any(ColumnQuery.class))) - .thenReturn(Stream.of(columnEntity)); - - ColumnQuery query = select().from("person").build(); - - Optional result = template.singleResult(query); - assertTrue(result.isPresent()); - } - - @Test - void shouldReturnSingleResultIsEmpty() { - Mockito.when(managerMock - .select(any(ColumnQuery.class))) - .thenReturn(Stream.empty()); - - ColumnQuery query = select().from("person").build(); - - Optional result = template.singleResult(query); - assertFalse(result.isPresent()); - } - - @Test - void shouldReturnErrorWhenThereMoreThanASingleResult() { - Assertions.assertThrows(NonUniqueResultException.class, () -> { - ColumnEntity columnEntity = ColumnEntity.of("Person"); - columnEntity.addAll(Stream.of(columns).collect(Collectors.toList())); - - Mockito.when(managerMock - .select(any(ColumnQuery.class))) - .thenReturn(Stream.of(columnEntity, columnEntity)); - - ColumnQuery query = select().from("person").build(); - - template.singleResult(query); - }); - } - - - @Test - void shouldReturnErrorWhenFindIdHasIdNull() { - Assertions.assertThrows(NullPointerException.class, () -> template.find(Person.class, null)); - } - - @Test - void shouldReturnErrorWhenFindIdHasClassNull() { - Assertions.assertThrows(NullPointerException.class, () -> template.find(null, "10")); - } - - @Test - void shouldReturnErrorWhenThereIsNotIdInFind() { - Assertions.assertThrows(IdNotFoundException.class, () -> template.find(Job.class, "10")); - } - - @Test - void shouldReturnFind() { - template.find(Person.class, "10"); - ArgumentCaptor queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(managerMock).select(queryCaptor.capture()); - ColumnQuery query = queryCaptor.getValue(); - ColumnCondition condition = query.condition().get(); - - assertEquals("Person", query.name()); - assertEquals(ColumnCondition.eq(Column.of("_id", 10L)), condition); - } - - @Test - void shouldDeleteEntity() { - template.delete(Person.class, "10"); - ArgumentCaptor queryCaptor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - verify(managerMock).delete(queryCaptor.capture()); - - ColumnDeleteQuery query = queryCaptor.getValue(); - - ColumnCondition condition = query.condition().get(); - - assertEquals("Person", query.name()); - assertEquals(ColumnCondition.eq(Column.of("_id", 10L)), condition); - } - - @Test - void shouldExecuteQuery() { - template.query("select * from Person"); - ArgumentCaptor queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(managerMock).select(queryCaptor.capture()); - ColumnQuery query = queryCaptor.getValue(); - assertEquals("Person", query.name()); - } - - @Test - void shouldConvertEntity() { - template.query("select * from Movie"); - ArgumentCaptor queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(managerMock).select(queryCaptor.capture()); - ColumnQuery query = queryCaptor.getValue(); - assertEquals("movie", query.name()); - } - - @Test - void shouldConvertEntityName() { - template.query("select * from download"); - ArgumentCaptor queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(managerMock).select(queryCaptor.capture()); - ColumnQuery query = queryCaptor.getValue(); - assertEquals("download", query.name()); - } - @Test - void shouldConvertEntityNameClassName() { - template.query("select * from " + Person.class.getName()); - ArgumentCaptor queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(managerMock).select(queryCaptor.capture()); - ColumnQuery query = queryCaptor.getValue(); - assertEquals("Person", query.name()); - } - - @Test - void shouldConvertConvertFromAnnotationEntity(){ - template.query("select * from Vendor" ); - ArgumentCaptor queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(managerMock).select(queryCaptor.capture()); - ColumnQuery query = queryCaptor.getValue(); - assertEquals("vendors", query.name()); - } - - @Test - void shouldPreparedStatement() { - PreparedStatement preparedStatement = template.prepare("select * from Person where name = @name"); - preparedStatement.bind("name", "Ada"); - preparedStatement.result(); - ArgumentCaptor queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(managerMock).select(queryCaptor.capture()); - ColumnQuery query = queryCaptor.getValue(); - assertEquals("Person", query.name()); - } - - @Test - void shouldCount() { - template.count("Person"); - verify(managerMock).count("Person"); - } - - @Test - void shouldCountFromEntityClass() { - template.count(Person.class); - var captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(managerMock).count(captor.capture()); - var query = captor.getValue(); - SoftAssertions.assertSoftly(soft ->{ - soft.assertThat(query.condition()).isEmpty(); - }); - } - - - @Test - void shouldFindAll(){ - template.findAll(Person.class); - verify(managerMock).select(select().from("Person").build()); - } - - @Test - void shouldDeleteAll(){ - template.deleteAll(Person.class); - verify(managerMock).delete(delete().from("Person").build()); - } -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/MapperDeleteTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/MapperDeleteTest.java deleted file mode 100644 index d5df16897..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/MapperDeleteTest.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.enterprise.inject.Instance; -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.column.ColumnDeleteQuery; -import org.eclipse.jnosql.communication.column.ColumnManager; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.entities.Address; -import org.eclipse.jnosql.mapping.column.entities.Money; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.entities.Worker; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; - -import java.math.BigDecimal; - -import static org.eclipse.jnosql.communication.column.ColumnDeleteQuery.delete; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.when; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class MapperDeleteTest { - - @Inject - private ColumnEntityConverter converter; - - @Inject - private EntitiesMetadata entities; - - @Inject - private Converters converters; - - private ColumnManager managerMock; - - private DefaultColumnTemplate template; - - - private ArgumentCaptor captor; - - @BeforeEach - void setUp() { - managerMock = Mockito.mock(ColumnManager.class); - ColumnEventPersistManager persistManager = Mockito.mock(ColumnEventPersistManager.class); - Instance instance = Mockito.mock(Instance.class); - this.captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - when(instance.get()).thenReturn(managerMock); - this.template = new DefaultColumnTemplate(converter, instance, - persistManager, entities, converters); - } - - @Test - void shouldReturnDeleteFrom() { - template.delete(Person.class).execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").build(); - assertEquals(queryExpected, query); - } - - - @Test - void shouldDeleteWhereEq() { - template.delete(Person.class).where("name").eq("Ada").execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - - ColumnDeleteQuery queryExpected = delete().from("Person").where("name") - .eq("Ada").build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldDeleteWhereLike() { - template.delete(Person.class).where("name").like("Ada").execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("name") - .like("Ada").build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldDeleteWhereGt() { - template.delete(Person.class).where("id").gt(10).execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("_id").gt(10L).build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldDeleteWhereGte() { - template.delete(Person.class).where("id").gte(10).execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("_id") - .gte(10L).build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldDeleteWhereLt() { - template.delete(Person.class).where("id").lt(10).execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("_id").lt(10L).build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldDeleteWhereLte() { - template.delete(Person.class).where("id").lte(10).execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("_id").lte(10L).build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldDeleteWhereBetween() { - template.delete(Person.class).where("id") - .between(10, 20).execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("_id") - .between(10L, 20L).build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldDeleteWhereNot() { - template.delete(Person.class).where("name").not().like("Ada").execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("name").not().like("Ada").build(); - assertEquals(queryExpected, query); - } - - - @Test - void shouldDeleteWhereAnd() { - template.delete(Person.class).where("age").between(10, 20) - .and("name").eq("Ada").execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("age") - .between(10, 20) - .and("name").eq("Ada").build(); - - assertEquals(queryExpected, query); - } - - @Test - void shouldDeleteWhereOr() { - template.delete(Person.class).where("id").between(10, 20) - .or("name").eq("Ada").execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("_id") - .between(10L, 20L) - .or("name").eq("Ada").build(); - - assertEquals(queryExpected, query); - } - - @Test - void shouldConvertField() { - template.delete(Person.class).where("id").eq("20") - .execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Person").where("_id").eq(20L) - .build(); - - assertEquals(queryExpected, query); - } - - @Test - void shouldUseAttributeConverter() { - template.delete(Worker.class).where("salary") - .eq(new Money("USD", BigDecimal.TEN)).execute(); - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Worker").where("money") - .eq("USD 10").build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldQueryByEmbeddable() { - template.delete(Worker.class).where("job.city").eq("Salvador") - .execute(); - - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - ColumnDeleteQuery queryExpected = delete().from("Worker").where("city").eq("Salvador") - .build(); - - assertEquals(queryExpected, query); - } - - @Test - void shouldQueryBySubEntity() { - template.delete(Address.class).where("zipCode.zip").eq("01312321") - .execute(); - - Mockito.verify(managerMock).delete(captor.capture()); - ColumnDeleteQuery query = captor.getValue(); - - ColumnDeleteQuery queryExpected = delete().from("Address").where("zipCode.zip").eq("01312321") - .build(); - - assertEquals(queryExpected, query); - } -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/MapperSelectTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/MapperSelectTest.java deleted file mode 100644 index d112b6dc6..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/MapperSelectTest.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column; - -import jakarta.enterprise.inject.Instance; -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.column.ColumnEntity; -import org.eclipse.jnosql.communication.column.ColumnManager; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.entities.Address; -import org.eclipse.jnosql.mapping.column.entities.Money; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.entities.Worker; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; - -import java.math.BigDecimal; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.jnosql.communication.column.ColumnQuery.select; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.when; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class MapperSelectTest { - - @Inject - private ColumnEntityConverter converter; - - @Inject - private EntitiesMetadata entities; - - @Inject - private Converters converters; - - private ColumnManager managerMock; - - private DefaultColumnTemplate template; - - private ArgumentCaptor captor; - - @BeforeEach - public void setUp() { - managerMock = Mockito.mock(ColumnManager.class); - ColumnEventPersistManager persistManager = Mockito.mock(ColumnEventPersistManager.class); - Instance instance = Mockito.mock(Instance.class); - this.captor = ArgumentCaptor.forClass(ColumnQuery.class); - when(instance.get()).thenReturn(managerMock); - this.template = new DefaultColumnTemplate(converter, instance, - persistManager, entities, converters); - } - - - @Test - void shouldExecuteSelectFrom() { - template.select(Person.class).result(); - ColumnQuery queryExpected = select().from("Person").build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectOrderAsc() { - template.select(Worker.class).orderBy("salary").asc().result(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnQuery queryExpected = select().from("Worker").orderBy("money").asc().build(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectOrderDesc() { - template.select(Worker.class).orderBy("salary").desc().result(); - ColumnQuery queryExpected = select().from("Worker").orderBy("money").desc().build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectLimit() { - template.select(Worker.class).limit(10).result(); - ColumnQuery queryExpected = select().from("Worker").limit(10L).build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectStart() { - template.select(Worker.class).skip(10).result(); - ColumnQuery queryExpected = select().from("Worker").skip(10L).build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - - @Test - void shouldSelectWhereEq() { - template.select(Person.class).where("name").eq("Ada").result(); - ColumnQuery queryExpected = select().from("Person").where("name") - .eq("Ada").build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectWhereLike() { - template.select(Person.class).where("name").like("Ada").result(); - ColumnQuery queryExpected = select().from("Person").where("name") - .like("Ada").build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectWhereGt() { - template.select(Person.class).where("id").gt(10).result(); - ColumnQuery queryExpected = select().from("Person").where("_id") - .gt(10L).build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectWhereGte() { - template.select(Person.class).where("id").gte(10).result(); - ColumnQuery queryExpected = select().from("Person").where("_id") - .gte(10L).build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - - @Test - void shouldSelectWhereLt() { - template.select(Person.class).where("id").lt(10).result(); - ColumnQuery queryExpected = select().from("Person").where("_id") - .lt(10L).build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectWhereLte() { - template.select(Person.class).where("id").lte(10).result(); - ColumnQuery queryExpected = select().from("Person").where("_id") - .lte(10L).build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectWhereBetween() { - template.select(Person.class).where("id") - .between(10, 20).result(); - ColumnQuery queryExpected = select().from("Person").where("_id") - .between(10L, 20L).build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectWhereNot() { - template.select(Person.class).where("name").not().like("Ada").result(); - ColumnQuery queryExpected = select().from("Person").where("name") - .not().like("Ada").build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - - @Test - void shouldSelectWhereAnd() { - template.select(Person.class).where("age").between(10, 20) - .and("name").eq("Ada").result(); - ColumnQuery queryExpected = select().from("Person").where("age") - .between(10, 20) - .and("name").eq("Ada").build(); - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - - assertEquals(queryExpected, query); - } - - @Test - void shouldSelectWhereOr() { - template.select(Person.class).where("id").between(10, 20) - .or("name").eq("Ada").result(); - ColumnQuery queryExpected = select().from("Person").where("_id") - .between(10L, 20L) - .or("name").eq("Ada").build(); - - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldConvertField() { - template.select(Person.class).where("id").eq("20") - .result(); - ColumnQuery queryExpected = select().from("Person").where("_id").eq(20L) - .build(); - - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - - assertEquals(queryExpected, query); - } - - @Test - void shouldUseAttributeConverter() { - template.select(Worker.class).where("salary") - .eq(new Money("USD", BigDecimal.TEN)).result(); - ColumnQuery queryExpected = select().from("Worker").where("money") - .eq("USD 10").build(); - - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldQueryByEmbeddable() { - template.select(Worker.class).where("job.city").eq("Salvador") - .result(); - ColumnQuery queryExpected = select().from("Worker").where("city") - .eq("Salvador") - .build(); - - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - @Test - void shouldQueryBySubEntity() { - template.select(Address.class).where("zipCode.zip").eq("01312321") - .result(); - ColumnQuery queryExpected = select().from("Address").where("zipCode.zip") - .eq("01312321") - .build(); - - Mockito.verify(managerMock).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals(queryExpected, query); - } - - - @Test - void shouldResult() { - ColumnQuery query = select().from("Person").build(); - ColumnEntity entity = ColumnEntity.of("Person"); - entity.add("_id", 1L); - entity.add("name", "Ada"); - entity.add("age", 20); - Mockito.when(managerMock.select(query)).thenReturn(Stream.of(entity)); - List result = template.select(Person.class).result(); - Assertions.assertNotNull(result); - assertThat(result).hasSize(1) - .map(Person::getName).contains("Ada"); - } - - - @Test - void shouldStream() { - - ColumnQuery query = select().from("Person").build(); - ColumnEntity entity = ColumnEntity.of("Person"); - entity.add("_id", 1L); - entity.add("name", "Ada"); - entity.add("age", 20); - Mockito.when(managerMock.select(query)).thenReturn(Stream.of(entity)); - Stream result = template.select(Person.class).stream(); - Assertions.assertNotNull(result); - } - - @Test - void shouldSingleResult() { - - ColumnQuery query = select().from("Person").build(); - ColumnEntity entity = ColumnEntity.of("Person"); - entity.add("_id", 1L); - entity.add("name", "Ada"); - entity.add("age", 20); - Mockito.when(managerMock.select(query)).thenReturn(Stream.of(entity)); - Optional result = template.select(Person.class).singleResult(); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.isPresent()); - } - - @Test - void shouldReturnErrorSelectWhenOrderIsNull() { - Assertions.assertThrows(NullPointerException.class, () -> template.select(Worker.class).orderBy(null)); - } - -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnCrudInheritanceRepositoryProxyTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnCrudInheritanceRepositoryProxyTest.java deleted file mode 100644 index deba08a53..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnCrudInheritanceRepositoryProxyTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - - -import jakarta.data.repository.CrudRepository; -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnCondition; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.NoSQLRepository; -import org.eclipse.jnosql.mapping.column.ColumnEntityConverter; -import org.eclipse.jnosql.mapping.column.JNoSQLColumnTemplate; -import org.eclipse.jnosql.mapping.column.MockProducer; -import org.eclipse.jnosql.mapping.column.entities.inheritance.EmailNotification; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; - -import java.lang.reflect.Proxy; -import java.util.List; - -import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.eclipse.jnosql.communication.Condition.AND; -import static org.mockito.Mockito.verify; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnCrudInheritanceRepositoryProxyTest { - - private JNoSQLColumnTemplate template; - - @Inject - private EntitiesMetadata entities; - - @Inject - private Converters converters; - - private EmailRepository emailRepository; - - - - @BeforeEach - public void setUp() { - this.template = Mockito.mock(JNoSQLColumnTemplate.class); - - ColumnRepositoryProxy personHandler = new ColumnRepositoryProxy<>(template, - entities, EmailRepository.class, converters); - - - emailRepository = (EmailRepository) Proxy.newProxyInstance(EmailRepository.class.getClassLoader(), - new Class[]{EmailRepository.class}, - personHandler); - } - - @Test - void shouldPutFilterAtFindAll() { - emailRepository.findAll(); - verify(template).findAll(EmailNotification.class); - } - - @Test - void shouldPutFilterAtCount() { - emailRepository.countBy(); - verify(template).count(EmailNotification.class); - } - - @Test - void shouldPutFilterAtFindByName() { - emailRepository.findByName("name"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(AND); - var conditions = condition.column().get(new TypeReference>() { - }); - soft.assertThat(conditions).hasSize(2).contains(ColumnCondition.eq(Column.of("dtype", "Email"))); - }); - } - - @Test - void shouldPutFilterAtCountByName() { - emailRepository.countByName("name"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).count(captor.capture()); - ColumnQuery query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(AND); - var conditions = condition.column().get(new TypeReference>() { - }); - soft.assertThat(conditions).hasSize(2).contains(ColumnCondition.eq(Column.of("dtype", "Email"))); - }); - } - - - @Test - void shouldPutFilterAtExistByName() { - emailRepository.existsByName("name"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).exists(captor.capture()); - ColumnQuery query = captor.getValue(); - assertSoftly(soft ->{ - soft.assertThat(query.name()).isEqualTo("Notification"); - soft.assertThat(query.condition()).isPresent(); - ColumnCondition condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(AND); - var conditions = condition.column().get(new TypeReference>() { - }); - soft.assertThat(conditions).hasSize(2).contains(ColumnCondition.eq(Column.of("dtype", "Email"))); - }); - } - - @Test - void shouldPutFilterAtDeleteAll() { - emailRepository.deleteAll(); - verify(template).deleteAll(EmailNotification.class); - } - - - public interface EmailRepository extends NoSQLRepository { - - List findByName(String name); - - long countByName(String name); - - boolean existsByName(String name); - - - } -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnCrudRepositoryProxyTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnCrudRepositoryProxyTest.java deleted file mode 100644 index d6edad09b..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnCrudRepositoryProxyTest.java +++ /dev/null @@ -1,804 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - -import jakarta.data.repository.CrudRepository; -import jakarta.data.repository.Param; -import jakarta.data.repository.Query; -import jakarta.data.Sort; -import jakarta.inject.Inject; -import jakarta.nosql.PreparedStatement; -import org.assertj.core.api.Assertions; -import org.eclipse.jnosql.communication.Condition; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.Value; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnCondition; -import org.eclipse.jnosql.communication.column.ColumnDeleteQuery; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.ColumnEntityConverter; -import org.eclipse.jnosql.mapping.column.JNoSQLColumnTemplate; -import org.eclipse.jnosql.mapping.column.MockProducer; -import org.eclipse.jnosql.mapping.column.entities.Address; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.entities.Vendor; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; - -import java.lang.reflect.Proxy; -import java.math.BigDecimal; -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Queue; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.jnosql.communication.Condition.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnCrudRepositoryProxyTest { - - private JNoSQLColumnTemplate template; - - @Inject - private EntitiesMetadata entities; - - @Inject - private Converters converters; - - private PersonRepository personRepository; - - private VendorRepository vendorRepository; - - private AddressRepository addressRepository; - - - @BeforeEach - public void setUp() { - this.template = Mockito.mock(JNoSQLColumnTemplate.class); - - ColumnRepositoryProxy personHandler = new ColumnRepositoryProxy(template, - entities, PersonRepository.class, converters); - - ColumnRepositoryProxy vendorHandler = new ColumnRepositoryProxy(template, - entities, VendorRepository.class, converters); - - ColumnRepositoryProxy addressHandler = new ColumnRepositoryProxy(template, - entities, AddressRepository.class, converters); - - - when(template.insert(any(Person.class))).thenReturn(Person.builder().build()); - when(template.insert(any(Person.class), any(Duration.class))).thenReturn(Person.builder().build()); - when(template.update(any(Person.class))).thenReturn(Person.builder().build()); - - personRepository = (PersonRepository) Proxy.newProxyInstance(PersonRepository.class.getClassLoader(), - new Class[]{PersonRepository.class}, - personHandler); - vendorRepository = (VendorRepository) Proxy.newProxyInstance(VendorRepository.class.getClassLoader(), - new Class[]{VendorRepository.class}, vendorHandler); - - addressRepository = (AddressRepository) Proxy.newProxyInstance(AddressRepository.class.getClassLoader(), - new Class[]{AddressRepository.class}, addressHandler); - } - - - @Test - void shouldSaveUsingInsertWhenDataDoesNotExist() { - when(template.find(Person.class, 10L)).thenReturn(Optional.empty()); - - ArgumentCaptor captor = ArgumentCaptor.forClass(Person.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - assertNotNull(personRepository.save(person)); - verify(template).insert(captor.capture()); - Person value = captor.getValue(); - assertEquals(person, value); - } - - - @Test - void shouldSaveUsingUpdateWhenDataExists() { - - when(template.find(Person.class, 10L)).thenReturn(Optional.of(Person.builder().build())); - - ArgumentCaptor captor = ArgumentCaptor.forClass(Person.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - assertNotNull(personRepository.save(person)); - verify(template).update(captor.capture()); - Person value = captor.getValue(); - assertEquals(person, value); - } - - - @Test - void shouldSaveIterable() { - when(personRepository.findById(10L)).thenReturn(Optional.empty()); - - ArgumentCaptor captor = ArgumentCaptor.forClass(Person.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - - personRepository.saveAll(singletonList(person)); - verify(template).insert(captor.capture()); - Person personCapture = captor.getValue(); - assertEquals(person, personCapture); - } - - - @Test - void shouldInsert() { - - ArgumentCaptor captor = ArgumentCaptor.forClass(Person.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - assertNotNull(personRepository.insert(person)); - verify(template).insert(captor.capture()); - Person value = captor.getValue(); - assertEquals(person, value); - } - - @Test - void shouldUpdate() { - - ArgumentCaptor captor = ArgumentCaptor.forClass(Person.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - personRepository.update(person); - verify(template).update(captor.capture()); - Person value = captor.getValue(); - assertEquals(person, value); - } - - - @Test - void shouldInsertIterable() { - - ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - assertNotNull(personRepository.insertAll(List.of(person))); - verify(template).insert(captor.capture()); - List value = captor.getValue(); - assertThat(value).contains(person); - } - - @Test - void shouldUpdateIterable() { - - ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - personRepository.updateAll(List.of(person)); - verify(template).update(captor.capture()); - List value = captor.getValue(); - assertThat(value).contains(person); - } - - - @Test - void shouldFindByNameInstance() { - - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - personRepository.findByName("name"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(Condition.EQUALS, condition.condition()); - assertEquals(Column.of("name", "name"), condition.column()); - - assertNotNull(personRepository.findByName("name")); - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .empty()); - - assertNull(personRepository.findByName("name")); - - - } - - @Test - void shouldFindByNameANDAge() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - List persons = personRepository.findByNameAndAge("name", 20); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - - } - - @Test - void shouldFindByAgeANDName() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - Set persons = personRepository.findByAgeAndName(20, "name"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - - } - - @Test - void shouldFindByNameANDAgeOrderByName() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - Stream persons = personRepository.findByNameAndAgeOrderByName("name", 20); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons.collect(Collectors.toList())).contains(ada); - - } - - @Test - void shouldFindByNameANDAgeOrderByAge() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - Queue persons = personRepository.findByNameAndAgeOrderByAge("name", 20); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - - } - - @Test - void shouldDeleteByName() { - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - personRepository.deleteByName("Ada"); - verify(template).delete(captor.capture()); - ColumnDeleteQuery deleteQuery = captor.getValue(); - ColumnCondition condition = deleteQuery.condition().get(); - assertEquals("Person", deleteQuery.name()); - assertEquals(Condition.EQUALS, condition.condition()); - assertEquals(Column.of("name", "Ada"), condition.column()); - - } - - @Test - void shouldFindById() { - personRepository.findById(10L); - verify(template).find(Person.class, 10L); - } - - @Test - void shouldFindByIds() { - when(template.find(Mockito.eq(Person.class), Mockito.any(Long.class))) - .thenReturn(Optional.of(Person.builder().build())); - - personRepository.findByIdIn(singletonList(10L)).toList(); - verify(template).find(Person.class, 10L); - - personRepository.findByIdIn(asList(1L, 2L, 3L)).toList(); - verify(template, times(4)).find(Mockito.eq(Person.class), Mockito.any(Long.class)); - } - - @Test - void shouldDeleteById() { - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - personRepository.deleteById(10L); - verify(template).delete(Person.class, 10L); - } - - @Test - void shouldDeleteByIds() { - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - personRepository.deleteByIdIn(singletonList(10L)); - verify(template).delete(Person.class, 10L); - } - - - @Test - void shouldContainsById() { - when(template.find(Person.class, 10L)).thenReturn(Optional.of(Person.builder().build())); - - assertTrue(personRepository.existsById(10L)); - Mockito.verify(template).find(Person.class, 10L); - - when(template.find(Person.class, 10L)).thenReturn(Optional.empty()); - assertFalse(personRepository.existsById(10L)); - - } - - @Test - void shouldFindAll() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findAll().toList(); - ArgumentCaptor> captor = ArgumentCaptor.forClass(Class.class); - verify(template).findAll(captor.capture()); - assertEquals(captor.getValue(), Person.class); - - } - - @Test - void shouldReturnToString() { - assertNotNull(personRepository.toString()); - } - - @Test - void shouldReturnHasCode() { - assertEquals(personRepository.hashCode(), personRepository.hashCode()); - } - - @Test - void shouldFindByNameAndAgeGreaterEqualThan() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(AND, condition.condition()); - List conditions = condition.column().get(new TypeReference<>() { - }); - ColumnCondition columnCondition = conditions.get(0); - ColumnCondition columnCondition2 = conditions.get(1); - - assertEquals(Condition.EQUALS, columnCondition.condition()); - assertEquals("Ada", columnCondition.column().get()); - assertEquals("name", columnCondition.column().name()); - - assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.condition()); - assertEquals(33, columnCondition2.column().get()); - assertEquals("age", columnCondition2.column().name()); - } - - @Test - void shouldFindByGreaterThan() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeGreaterThan(33); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(GREATER_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - - } - - @Test - void shouldFindByAgeLessThanEqual() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeLessThanEqual(33); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LESSER_EQUALS_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - - } - - @Test - void shouldFindByAgeLessEqual() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeLessThan(33); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LESSER_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - - } - - @Test - void shouldFindByAgeBetween() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeBetween(10, 15); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(BETWEEN, condition.condition()); - List values = condition.column().get(new TypeReference<>() { - }); - assertEquals(Arrays.asList(10, 15), values.stream().map(Value::get).collect(Collectors.toList())); - assertTrue(condition.column().name().contains("age")); - } - - - @Test - void shouldFindByNameLike() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByNameLike("Ada"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LIKE, condition.condition()); - assertEquals(Column.of("name", "Ada"), condition.column()); - - } - - - @Test - void shouldFindByStringWhenFieldIsSet() { - Vendor vendor = new Vendor("vendor"); - vendor.setPrefixes(Collections.singleton("prefix")); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(vendor)); - - vendorRepository.findByPrefixes("prefix"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("vendors", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("prefixes", "prefix"), condition.column()); - - } - - @Test - void shouldFindByIn() { - Vendor vendor = new Vendor("vendor"); - vendor.setPrefixes(Collections.singleton("prefix")); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(vendor)); - - vendorRepository.findByPrefixesIn(singletonList("prefix")); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("vendors", query.name()); - assertEquals(IN, condition.condition()); - - } - - - @Test - void shouldConvertFieldToTheType() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAge("120"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("age", 120), condition.column()); - } - - - @Test - void shouldExecuteJNoSQLQuery() { - personRepository.findByQuery(); - verify(template).query("select * from Person"); - } - - @Test - void shouldExecuteJNoSQLPrepare() { - PreparedStatement statement = Mockito.mock(PreparedStatement.class); - when(template.prepare(Mockito.anyString())).thenReturn(statement); - personRepository.findByQuery("Ada"); - verify(statement).bind("id", "Ada"); - } - - @Test - void shouldFindBySalary_Currency() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findBySalary_Currency("USD"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - final Column column = condition.column(); - assertEquals("Person", query.name()); - assertEquals("salary.currency", column.name()); - - } - - @Test - void shouldFindBySalary_CurrencyAndSalary_Value() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - personRepository.findBySalary_CurrencyAndSalary_Value("USD", BigDecimal.TEN); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - final Column column = condition.column(); - final List conditions = column.get(new TypeReference<>() { - }); - final List names = conditions.stream().map(ColumnCondition::column) - .map(Column::name).collect(Collectors.toList()); - assertEquals("Person", query.name()); - assertThat(names).contains("salary.currency", "salary.value"); - - } - - @Test - void shouldFindBySalary_CurrencyOrderByCurrency_Name() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findBySalary_CurrencyOrderByCurrency_Name("USD"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - final Sort sort = query.sorts().get(0); - final Column document = condition.column(); - assertEquals("Person", query.name()); - assertEquals("salary.currency", document.name()); - assertEquals("currency.name", sort.property()); - - } - - @Test - void shouldFindByNameNotEquals() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByNameNotEquals("Otavio"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition negate = query.condition().get(); - assertEquals(Condition.NOT, negate.condition()); - ColumnCondition condition = negate.column().get(ColumnCondition.class); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("name", "Otavio"), condition.column()); - } - - @Test - void shouldFindByAgeNotGreaterThan() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeNotGreaterThan(10); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition negate = query.condition().get(); - assertEquals(Condition.NOT, negate.condition()); - ColumnCondition condition = negate.column().get(ColumnCondition.class); - assertEquals(GREATER_THAN, condition.condition()); - assertEquals(Column.of("age", 10), condition.column()); - } - - @Test - void shouldConvertMapAddressRepository() { - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - addressRepository.findByZipCodeZip("123456"); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - Assertions.assertThat(query) - .isNotNull() - .matches(c -> c.name().equals("Address")) - .matches(c -> c.columns().isEmpty()) - .matches(c -> c.sorts().isEmpty()) - .extracting(ColumnQuery::condition) - .extracting(Optional::orElseThrow) - .matches(c -> c.condition().equals(EQUALS)) - .extracting(ColumnCondition::column) - .matches(d -> d.value().get().equals("123456")) - .matches(d -> d.name().equals("zipCode.zip")); - - } - - @Test - void shouldConvertMapAddressRepositoryOrder() { - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - addressRepository.findByZipCodeZipOrderByZipCodeZip("123456"); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - Assertions.assertThat(query) - .isNotNull() - .matches(c -> c.name().equals("Address")) - .matches(c -> c.columns().isEmpty()) - .matches(c -> !c.sorts().isEmpty()) - .extracting(ColumnQuery::condition) - .extracting(Optional::orElseThrow) - .matches(c -> c.condition().equals(EQUALS)) - .extracting(ColumnCondition::column) - .matches(d -> d.value().get().equals("123456")) - .matches(d -> d.name().equals("zipCode.zip")); - - - Assertions.assertThat(query.sorts()).contains(Sort.asc("zipCode.zip")); - - } - - - interface PersonRepository extends CrudRepository { - - List findBySalary_Currency(String currency); - - List findBySalary_CurrencyAndSalary_Value(String currency, BigDecimal value); - - List findBySalary_CurrencyOrderByCurrency_Name(String currency); - - Person findByName(String name); - - List findByNameNotEquals(String name); - - List findByAgeNotGreaterThan(Integer age); - - void deleteByName(String name); - - List findByAge(String age); - - List findByNameAndAge(String name, Integer age); - - Set findByAgeAndName(Integer age, String name); - - Stream findByNameAndAgeOrderByName(String name, Integer age); - - Queue findByNameAndAgeOrderByAge(String name, Integer age); - - Set findByNameAndAgeGreaterThanEqual(String name, Integer age); - - Set findByAgeGreaterThan(Integer age); - - Set findByAgeLessThanEqual(Integer age); - - Set findByAgeLessThan(Integer age); - - Set findByAgeBetween(Integer ageA, Integer ageB); - - Set findByNameLike(String name); - - @Query("select * from Person") - Optional findByQuery(); - - @Query("select * from Person where id = @id") - Optional findByQuery(@Param("id") String id); - } - - public interface VendorRepository extends CrudRepository { - - Vendor findByPrefixes(String prefix); - - Vendor findByPrefixesIn(List prefix); - - } - - public interface AddressRepository extends CrudRepository { - - List
findByZipCodeZip(String zip); - - List
findByZipCodeZipOrderByZipCodeZip(String zip); - } -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnParameterBasedQueryTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnParameterBasedQueryTest.java deleted file mode 100644 index 23fe411bf..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnParameterBasedQueryTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - -import jakarta.data.Sort; -import jakarta.data.page.PageRequest; -import jakarta.inject.Inject; -import org.assertj.core.api.SoftAssertions; -import org.eclipse.jnosql.communication.Condition; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnCondition; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.column.ColumnEntityConverter; -import org.eclipse.jnosql.mapping.column.MockProducer; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.metadata.EntityMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnParameterBasedQueryTest { - - @Inject - private EntitiesMetadata entitiesMetadata; - - private EntityMetadata metadata; - @BeforeEach - void setUp(){ - this.metadata = entitiesMetadata.get(Person.class); - } - - @Test - void shouldCreateQuerySingleParameter(){ - Map params = Map.of("name", "Ada"); - ColumnQuery query = ColumnParameterBasedQuery.INSTANCE.toQuery(params, metadata); - - SoftAssertions.assertSoftly(soft ->{ - soft.assertThat(query.limit()).isEqualTo(0L); - soft.assertThat(query.skip()).isEqualTo(0L); - soft.assertThat(query.name()).isEqualTo("Person"); - soft.assertThat(query.sorts()).isEmpty(); - soft.assertThat(query.condition()).isNotEmpty(); - soft.assertThat(query.condition()).get().isEqualTo(ColumnCondition.eq(Column.of("name", "Ada"))); - }); - } - - @Test - void shouldCreateQueryMultipleParams(){ - Map params = Map.of("name", "Ada", "age", 10); - ColumnQuery query = ColumnParameterBasedQuery.INSTANCE.toQuery(params, metadata); - - SoftAssertions.assertSoftly(soft ->{ - soft.assertThat(query.limit()).isEqualTo(0L); - soft.assertThat(query.skip()).isEqualTo(0L); - soft.assertThat(query.name()).isEqualTo("Person"); - soft.assertThat(query.sorts()).isEmpty(); - soft.assertThat(query.condition()).isNotEmpty(); - var condition = query.condition().orElseThrow(); - soft.assertThat(condition.condition()).isEqualTo(Condition.AND); - soft.assertThat(condition.column().get(new TypeReference>() { - })).contains(ColumnCondition.eq(Column.of("name", "Ada")), - ColumnCondition.eq(Column.of("age", 10))); - }); - - } - - @Test - void shouldCreateQueryEmptyParams(){ - Map params = Collections.emptyMap(); - ColumnQuery query = ColumnParameterBasedQuery.INSTANCE.toQuery(params, metadata); - - SoftAssertions.assertSoftly(soft ->{ - soft.assertThat(query.limit()).isEqualTo(0L); - soft.assertThat(query.skip()).isEqualTo(0L); - soft.assertThat(query.name()).isEqualTo("Person"); - soft.assertThat(query.sorts()).isEmpty(); - soft.assertThat(query.condition()).isEmpty(); - }); - } - -} \ No newline at end of file diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnRepositoryProxyPageRequestTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnRepositoryProxyPageRequestTest.java deleted file mode 100644 index 2db35b21a..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnRepositoryProxyPageRequestTest.java +++ /dev/null @@ -1,658 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - -import jakarta.data.Limit; -import jakarta.data.page.Page; -import jakarta.data.page.PageRequest; -import jakarta.data.repository.BasicRepository; -import jakarta.data.page.Slice; -import jakarta.data.Sort; -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.Condition; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.Value; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnCondition; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.core.NoSQLPage; -import org.eclipse.jnosql.mapping.column.ColumnEntityConverter; -import org.eclipse.jnosql.mapping.column.JNoSQLColumnTemplate; -import org.eclipse.jnosql.mapping.column.MockProducer; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.entities.Vendor; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; - -import java.lang.reflect.Proxy; -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Queue; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.jnosql.communication.Condition.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -public class ColumnRepositoryProxyPageRequestTest { - - private JNoSQLColumnTemplate template; - - @Inject - private EntitiesMetadata entities; - - @Inject - private Converters converters; - - private PersonRepository personRepository; - - private VendorRepository vendorRepository; - - - @BeforeEach - public void setUp() { - this.template = Mockito.mock(JNoSQLColumnTemplate.class); - - ColumnRepositoryProxy personHandler = new ColumnRepositoryProxy(template, - entities, PersonRepository.class, converters); - - ColumnRepositoryProxy vendorHandler = new ColumnRepositoryProxy(template, - entities, VendorRepository.class, converters); - - when(template.insert(any(Person.class))).thenReturn(Person.builder().build()); - when(template.insert(any(Person.class), any(Duration.class))).thenReturn(Person.builder().build()); - when(template.update(any(Person.class))).thenReturn(Person.builder().build()); - - personRepository = (PersonRepository) Proxy.newProxyInstance(PersonRepository.class.getClassLoader(), - new Class[]{PersonRepository.class}, - personHandler); - vendorRepository = (VendorRepository) Proxy.newProxyInstance(VendorRepository.class.getClassLoader(), - new Class[]{VendorRepository.class}, vendorHandler); - } - - - @Test - public void shouldFindByNameInstance() { - - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - PageRequest pageRequest = getPageRequest(); - personRepository.findByName("name", pageRequest); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(Condition.EQUALS, condition.condition()); - assertEquals(pageRequest.size(), query.skip()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - - assertEquals(Column.of("name", "name"), condition.column()); - - assertNotNull(personRepository.findByName("name", pageRequest)); - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .empty()); - - assertNull(personRepository.findByName("name", pageRequest)); - - - } - - @Test - public void shouldFindByNameANDAge() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - List persons = personRepository.findByNameAndAge("name", 20, pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - - ColumnQuery query = captor.getValue(); - assertEquals("Person", query.name()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - @Test - public void shouldFindByAgeANDName() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - Set persons = personRepository.findByAgeAndName(20, "name", pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - ColumnQuery query = captor.getValue(); - assertEquals("Person", query.name()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - @Test - public void shouldFindByNameANDAgeOrderByName() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - - Stream persons = personRepository.findByNameAndAgeOrderByName("name", 20, pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons.collect(Collectors.toList())).contains(ada); - ColumnQuery query = captor.getValue(); - assertEquals("Person", query.name()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - @Test - public void shouldFindByNameANDAgeOrderByAge() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - Queue persons = personRepository.findByNameAndAgeOrderByAge("name", 20, pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - ColumnQuery query = captor.getValue(); - assertEquals("Person", query.name()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - - } - - - @Test - public void shouldFindAll() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.findAll(Person.class)) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - - List persons = personRepository.findAll(pageRequest).content(); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertFalse(query.condition().isPresent()); - assertEquals("Person", query.name()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - } - - - @Test - public void shouldFindByNameAndAgeGreaterEqualThan() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33, pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(AND, condition.condition()); - List conditions = condition.column().get(new TypeReference<>() { - }); - ColumnCondition columnCondition = conditions.get(0); - ColumnCondition columnCondition2 = conditions.get(1); - - assertEquals(Condition.EQUALS, columnCondition.condition()); - assertEquals("Ada", columnCondition.column().get()); - assertEquals("name", columnCondition.column().name()); - - assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.condition()); - assertEquals(33, columnCondition2.column().get()); - assertEquals("age", columnCondition2.column().name()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - } - - @Test - public void shouldFindByGreaterThan() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - personRepository.findByAgeGreaterThan(33, pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(GREATER_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - @Test - public void shouldFindByAgeLessThanEqual() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - personRepository.findByAgeLessThanEqual(33, pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LESSER_EQUALS_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - @Test - public void shouldFindByAgeLessEqual() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - personRepository.findByAgeLessThan(33, pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LESSER_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - @Test - public void shouldFindByAgeBetween() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - personRepository.findByAgeBetween(10, 15, pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(BETWEEN, condition.condition()); - List values = condition.column().get(new TypeReference<>() { - }); - assertEquals(Arrays.asList(10, 15), values.stream().map(Value::get).collect(Collectors.toList())); - assertTrue(condition.column().name().contains("age")); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - } - - - @Test - public void shouldFindByNameLike() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - personRepository.findByNameLike("Ada", pageRequest); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LIKE, condition.condition()); - assertEquals(Column.of("name", "Ada"), condition.column()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - - @Test - public void shouldFindByStringWhenFieldIsSet() { - Vendor vendor = new Vendor("vendor"); - vendor.setPrefixes(Collections.singleton("prefix")); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(vendor)); - - PageRequest pageRequest = getPageRequest(); - vendorRepository.findByPrefixes("prefix", pageRequest); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("vendors", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("prefixes", "prefix"), condition.column()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - @Test - public void shouldFindByIn() { - Vendor vendor = new Vendor("vendor"); - vendor.setPrefixes(Collections.singleton("prefix")); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(vendor)); - - PageRequest pageRequest = getPageRequest(); - vendorRepository.findByPrefixesIn(singletonList("prefix"), pageRequest); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("vendors", query.name()); - assertEquals(IN, condition.condition()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - - } - - @Test - public void shouldConvertFieldToTheType() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - PageRequest pageRequest = getPageRequest(); - Slice slice = personRepository.findByAge("120", pageRequest); - Assertions.assertNotNull(slice); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("age", 120), condition.column()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - } - - @Test - public void shouldFindByNameOrderName() { - - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - PageRequest pageRequest = getPageRequest().sortBy(Sort.asc("name")); - personRepository.findByName("name", pageRequest); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - assertThat(query.sorts()).hasSize(1) - .contains(Sort.asc("name")); - - assertEquals(Column.of("name", "name"), condition.column()); - - assertNotNull(personRepository.findByName("name", pageRequest)); - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .empty()); - assertNull(personRepository.findByName("name", pageRequest)); - } - - @Test - public void shouldFindByNameOrderName2() { - - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - PageRequest pageRequest = getPageRequest().sortBy(Sort.asc("name")); - Page page = personRepository.findByNameOrderByAge("name", pageRequest); - - Assertions.assertNotNull(page); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(NoSQLPage.skip(pageRequest), query.limit()); - assertEquals(pageRequest.size(), query.limit()); - assertThat(query.sorts()).hasSize(2) - .containsExactly(Sort.asc("age"), Sort.asc("name")); - - assertEquals(Column.of("name", "name"), condition.column()); - - assertNotNull(personRepository.findByName("name", pageRequest)); - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .empty()); - assertNull(personRepository.findByName("name", pageRequest)); - } - - @Test - public void shouldFindByNameSort() { - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - PageRequest pageRequest = getPageRequest().sortBy(Sort.desc("age")); - personRepository.findByName("name", Sort.asc("name"), pageRequest); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertThat(query.sorts()).hasSize(2) - .containsExactly(Sort.asc("name"), Sort.desc("age")); - assertEquals(Column.of("name", "name"), condition.column()); - } - - @Test - public void shouldFindByNameSortPagination() { - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - personRepository.findByName("name", Sort.asc("name")); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertThat(query.sorts()).hasSize(1) - .containsExactly(Sort.asc("name")); - assertEquals(Column.of("name", "name"), condition.column()); - } - - @Test - public void shouldFindByNameLimit() { - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - personRepository.findByName("name", Limit.of(3), Sort.asc("name")); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(0, query.skip()); - assertEquals(3, query.limit()); - assertEquals(EQUALS, condition.condition()); - assertThat(query.sorts()).hasSize(1) - .containsExactly(Sort.asc("name")); - assertEquals(Column.of("name", "name"), condition.column()); - } - - @Test - public void shouldFindByNameLimit2() { - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - personRepository.findByName("name", Limit.range(1, 3), Sort.asc("name")); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(0, query.skip()); - assertEquals(3, query.limit()); - assertEquals(EQUALS, condition.condition()); - assertThat(query.sorts()).hasSize(1) - .containsExactly(Sort.asc("name")); - assertEquals(Column.of("name", "name"), condition.column()); - } - - @Test - public void shouldFindByNameLimit3() { - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - personRepository.findByName("name", Limit.range(2, 3), Sort.asc("name")); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(1, query.skip()); - assertEquals(2, query.limit()); - assertEquals(EQUALS, condition.condition()); - assertThat(query.sorts()).hasSize(1) - .containsExactly(Sort.asc("name")); - assertEquals(Column.of("name", "name"), condition.column()); - } - - - private PageRequest getPageRequest() { - return PageRequest.ofPage(2).size(6); - } - - interface PersonRepository extends BasicRepository { - - Person findByName(String name, PageRequest pageRequest); - - List findByName(String name, Sort sort); - - List findByName(String name, Limit limit, Sort sort); - - List findByName(String name, Sort sort, PageRequest pageRequest); - - Page findByNameOrderByAge(String name, PageRequest pageRequest); - - Slice findByAge(String age, PageRequest pageRequest); - - List findByNameAndAge(String name, Integer age, PageRequest pageRequest); - - Set findByAgeAndName(Integer age, String name, PageRequest pageRequest); - - Stream findByNameAndAgeOrderByName(String name, Integer age, PageRequest pageRequest); - - Queue findByNameAndAgeOrderByAge(String name, Integer age, PageRequest pageRequest); - - Set findByNameAndAgeGreaterThanEqual(String name, Integer age, PageRequest pageRequest); - - Set findByAgeGreaterThan(Integer age, PageRequest pageRequest); - - Set findByAgeLessThanEqual(Integer age, PageRequest pageRequest); - - Set findByAgeLessThan(Integer age, PageRequest pageRequest); - - Set findByAgeBetween(Integer ageA, Integer ageB, PageRequest pageRequest); - - Set findByNameLike(String name, PageRequest pageRequest); - - } - - public interface VendorRepository extends BasicRepository { - - Vendor findByPrefixes(String prefix, PageRequest pageRequest); - - Vendor findByPrefixesIn(List prefix, PageRequest pageRequest); - - } -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnRepositoryProxyTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnRepositoryProxyTest.java deleted file mode 100644 index 54b23f76c..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ColumnRepositoryProxyTest.java +++ /dev/null @@ -1,971 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - -import jakarta.data.exceptions.MappingException; -import jakarta.data.repository.By; -import jakarta.data.repository.Delete; -import jakarta.data.repository.Insert; -import jakarta.data.repository.OrderBy; -import jakarta.data.repository.BasicRepository; -import jakarta.data.repository.Param; -import jakarta.data.repository.Query; -import jakarta.data.Sort; -import jakarta.data.repository.Save; -import jakarta.data.repository.Update; -import jakarta.inject.Inject; -import jakarta.nosql.PreparedStatement; -import org.assertj.core.api.SoftAssertions; -import org.eclipse.jnosql.communication.Condition; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.Value; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnCondition; -import org.eclipse.jnosql.communication.column.ColumnDeleteQuery; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.NoSQLRepository; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.ColumnEntityConverter; -import org.eclipse.jnosql.mapping.column.JNoSQLColumnTemplate; -import org.eclipse.jnosql.mapping.column.MockProducer; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.entities.PersonStatisticRepository; -import org.eclipse.jnosql.mapping.column.entities.Vendor; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; - -import java.lang.reflect.Proxy; -import java.math.BigDecimal; -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Queue; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.jnosql.communication.Condition.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ColumnRepositoryProxyTest { - - private JNoSQLColumnTemplate template; - - @Inject - private EntitiesMetadata entities; - - @Inject - private Converters converters; - - private PersonRepository personRepository; - - private VendorRepository vendorRepository; - - - @BeforeEach - void setUp() { - this.template = Mockito.mock(JNoSQLColumnTemplate.class); - - ColumnRepositoryProxy personHandler = new ColumnRepositoryProxy(template, - entities, PersonRepository.class, converters); - - ColumnRepositoryProxy vendorHandler = new ColumnRepositoryProxy(template, - entities, VendorRepository.class, converters); - - when(template.insert(any(Person.class))).thenReturn(Person.builder().build()); - when(template.insert(any(Person.class), any(Duration.class))).thenReturn(Person.builder().build()); - when(template.update(any(Person.class))).thenReturn(Person.builder().build()); - - personRepository = (PersonRepository) Proxy.newProxyInstance(PersonRepository.class.getClassLoader(), - new Class[]{PersonRepository.class}, - personHandler); - vendorRepository = (VendorRepository) Proxy.newProxyInstance(VendorRepository.class.getClassLoader(), - new Class[]{VendorRepository.class}, vendorHandler); - } - - - @Test - void shouldSaveUsingInsertWhenDataDoesNotExist() { - when(template.find(Person.class, 10L)).thenReturn(Optional.empty()); - - ArgumentCaptor captor = ArgumentCaptor.forClass(Person.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - assertNotNull(personRepository.save(person)); - verify(template).insert(captor.capture()); - Person value = captor.getValue(); - assertEquals(person, value); - } - - - @Test - void shouldSaveUsingUpdateWhenDataExists() { - - when(template.find(Person.class, 10L)).thenReturn(Optional.of(Person.builder().build())); - - ArgumentCaptor captor = ArgumentCaptor.forClass(Person.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - assertNotNull(personRepository.save(person)); - verify(template).update(captor.capture()); - Person value = captor.getValue(); - assertEquals(person, value); - } - - - @Test - void shouldSaveIterable() { - when(personRepository.findById(10L)).thenReturn(Optional.empty()); - - ArgumentCaptor captor = ArgumentCaptor.forClass(Person.class); - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - - personRepository.saveAll(singletonList(person)); - verify(template).insert(captor.capture()); - Person personCapture = captor.getValue(); - assertEquals(person, personCapture); - } - - - @Test - void shouldFindByNameInstance() { - - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - personRepository.findByName("name"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(Condition.EQUALS, condition.condition()); - assertEquals(Column.of("name", "name"), condition.column()); - - assertNotNull(personRepository.findByName("name")); - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .empty()); - - assertNull(personRepository.findByName("name")); - - - } - - @Test - void shouldFindByNameANDAge() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - List persons = personRepository.findByNameAndAge("name", 20); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - - } - - @Test - void shouldFindByAgeANDName() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - Set persons = personRepository.findByAgeAndName(20, "name"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - - } - - @Test - void shouldFindByNameANDAgeOrderByName() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - Stream persons = personRepository.findByNameAndAgeOrderByName("name", 20); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons.collect(Collectors.toList())).contains(ada); - - } - - @Test - void shouldFindByNameANDAgeOrderByAge() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - Queue persons = personRepository.findByNameAndAgeOrderByAge("name", 20); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - assertThat(persons).contains(ada); - - } - - @Test - void shouldDeleteByName() { - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - personRepository.deleteByName("Ada"); - verify(template).delete(captor.capture()); - ColumnDeleteQuery deleteQuery = captor.getValue(); - ColumnCondition condition = deleteQuery.condition().get(); - assertEquals("Person", deleteQuery.name()); - assertEquals(Condition.EQUALS, condition.condition()); - assertEquals(Column.of("name", "Ada"), condition.column()); - - } - - @Test - void shouldFindById() { - personRepository.findById(10L); - verify(template).find(Person.class, 10L); - } - - @Test - void shouldFindByIds() { - when(template.find(Mockito.eq(Person.class), Mockito.any(Long.class))) - .thenReturn(Optional.of(Person.builder().build())); - - personRepository.findByIdIn(singletonList(10L)).toList(); - verify(template).find(Person.class, 10L); - - personRepository.findByIdIn(asList(1L, 2L, 3L)).toList(); - verify(template, times(4)).find(Mockito.eq(Person.class), Mockito.any(Long.class)); - } - - @Test - void shouldDeleteById() { - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - personRepository.deleteById(10L); - verify(template).delete(Person.class, 10L); - } - - @Test - void shouldDeleteByIds() { - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class); - personRepository.deleteByIdIn(singletonList(10L)); - verify(template).delete(Person.class, 10L); - } - - - @Test - void shouldContainsById() { - when(template.find(Person.class, 10L)).thenReturn(Optional.of(Person.builder().build())); - - assertTrue(personRepository.existsById(10L)); - Mockito.verify(template).find(Person.class, 10L); - - when(template.find(Person.class, 10L)).thenReturn(Optional.empty()); - assertFalse(personRepository.existsById(10L)); - - } - - @Test - void shouldFindAll() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findAll().toList(); - ArgumentCaptor> captor = ArgumentCaptor.forClass(Class.class); - verify(template).findAll(captor.capture()); - assertEquals(captor.getValue(), Person.class); - - } - - @Test - void shouldDeleteAll() { - personRepository.deleteAll(); - ArgumentCaptor> captor = ArgumentCaptor.forClass(Class.class); - verify(template).deleteAll(captor.capture()); - assertEquals(captor.getValue(), Person.class); - - } - - @Test - void shouldDeleteEntity(){ - Person person = Person.builder().withId(1L).withAge(20).withName("Ada").build(); - personRepository.delete(person); - verify(template).delete(Person.class, 1L); - } - - @Test - void shouldDeleteEntities(){ - Person person = Person.builder().withId(1L).withAge(20).withName("Ada").build(); - personRepository.deleteAll(List.of(person)); - verify(template).delete(Person.class, 1L); - } - - @Test - void shouldReturnToString() { - assertNotNull(personRepository.toString()); - } - - @Test - void shouldReturnSameHashCode() { - assertEquals(personRepository.hashCode(), personRepository.hashCode()); - } - - @Test - void shouldReturnNotNull() { - assertNotNull(personRepository); - } - - @Test - void shouldFindByNameAndAgeGreaterEqualThan() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(AND, condition.condition()); - List conditions = condition.column().get(new TypeReference<>() { - }); - ColumnCondition columnCondition = conditions.get(0); - ColumnCondition columnCondition2 = conditions.get(1); - - assertEquals(Condition.EQUALS, columnCondition.condition()); - assertEquals("Ada", columnCondition.column().get()); - assertEquals("name", columnCondition.column().name()); - - assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.condition()); - assertEquals(33, columnCondition2.column().get()); - assertEquals("age", columnCondition2.column().name()); - } - - @Test - void shouldFindByGreaterThan() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeGreaterThan(33); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(GREATER_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - - } - - @Test - void shouldFindByAgeLessThanEqual() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeLessThanEqual(33); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LESSER_EQUALS_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - - } - - @Test - void shouldFindByAgeLessEqual() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeLessThan(33); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LESSER_THAN, condition.condition()); - assertEquals(Column.of("age", 33), condition.column()); - - } - - @Test - void shouldFindByAgeBetween() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAgeBetween(10, 15); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(BETWEEN, condition.condition()); - List values = condition.column().get(new TypeReference<>() { - }); - assertEquals(Arrays.asList(10, 15), values.stream().map(Value::get).collect(Collectors.toList())); - assertTrue(condition.column().name().contains("age")); - } - - - @Test - void shouldFindByNameLike() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByNameLike("Ada"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(LIKE, condition.condition()); - assertEquals(Column.of("name", "Ada"), condition.column()); - - } - - @Test - void shouldGotOrderException() { - Assertions.assertThrows(MappingException.class, () -> - personRepository.findBy()); - } - - @Test - void shouldGotOrderException2() { - Assertions.assertThrows(MappingException.class, () -> - personRepository.findByException()); - } - - - @Test - void shouldFindByStringWhenFieldIsSet() { - Vendor vendor = new Vendor("vendor"); - vendor.setPrefixes(Collections.singleton("prefix")); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(vendor)); - - vendorRepository.findByPrefixes("prefix"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("vendors", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("prefixes", "prefix"), condition.column()); - - } - - @Test - void shouldFindByIn() { - Vendor vendor = new Vendor("vendor"); - vendor.setPrefixes(Collections.singleton("prefix")); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(vendor)); - - vendorRepository.findByPrefixesIn(singletonList("prefix")); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("vendors", query.name()); - assertEquals(IN, condition.condition()); - - } - - - @Test - void shouldConvertFieldToTheType() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByAge("120"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("age", 120), condition.column()); - } - - @Test - void shouldFindByActiveTrue() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByActiveTrue(); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("active", true), condition.column()); - } - - @Test - void shouldFindByActiveFalse() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findByActiveFalse(); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals("Person", query.name()); - assertEquals(EQUALS, condition.condition()); - assertEquals(Column.of("active", false), condition.column()); - } - - - @Test - void shouldExecuteJNoSQLQuery() { - personRepository.findByQuery(); - verify(template).query("select * from Person"); - } - - @Test - void shouldExecuteJNoSQLPrepare() { - PreparedStatement statement = Mockito.mock(PreparedStatement.class); - when(template.prepare(Mockito.anyString())).thenReturn(statement); - personRepository.findByQuery("Ada"); - verify(statement).bind("id", "Ada"); - } - - @Test - void shouldFindBySalary_Currency() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findBySalary_Currency("USD"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - final Column column = condition.column(); - assertEquals("Person", query.name()); - assertEquals("salary.currency", column.name()); - - } - - @Test - void shouldFindBySalary_CurrencyAndSalary_Value() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - personRepository.findBySalary_CurrencyAndSalary_Value("USD", BigDecimal.TEN); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - final Column column = condition.column(); - final List conditions = column.get(new TypeReference<>() { - }); - final List names = conditions.stream().map(ColumnCondition::column) - .map(Column::name).collect(Collectors.toList()); - assertEquals("Person", query.name()); - assertThat(names).contains("salary.currency", "salary.value"); - - } - - @Test - void shouldFindBySalary_CurrencyOrderByCurrency_Name() { - Person ada = Person.builder() - .withAge(20).withName("Ada").build(); - - when(template.select(any(ColumnQuery.class))) - .thenReturn(Stream.of(ada)); - - personRepository.findBySalary_CurrencyOrderByCurrency_Name("USD"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - final Sort sort = query.sorts().get(0); - final Column document = condition.column(); - assertEquals("Person", query.name()); - assertEquals("salary.currency", document.name()); - assertEquals("currency.name", sort.property()); - } - - @Test - void shouldCountByName() { - when(template.count(any(ColumnQuery.class))) - .thenReturn(10L); - - var result = personRepository.countByName("Poliana"); - Assertions.assertEquals(10L, result); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).count(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - final Column column = condition.column(); - assertEquals("Person", query.name()); - assertEquals("name", column.name()); - assertEquals("Poliana", column.get()); - } - - @Test - void shouldExistsByName() { - when(template.exists(any(ColumnQuery.class))) - .thenReturn(true); - - var result = personRepository.existsByName("Poliana"); - assertTrue(result); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).exists(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - final Column column = condition.column(); - assertEquals("Person", query.name()); - assertEquals("name", column.name()); - assertEquals("Poliana", column.get()); - } - - @Test - void shouldFindByNameNot() { - - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - personRepository.findByNameNot("name"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals(Condition.NOT, condition.condition()); - assertEquals("Person", query.name()); - ColumnCondition columnCondition = condition.column().get(ColumnCondition.class); - assertEquals(Condition.EQUALS, columnCondition.condition()); - assertEquals(Column.of("name", "name"), columnCondition.column()); - - assertNotNull(personRepository.findByName("name")); - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .empty()); - - assertNull(personRepository.findByName("name")); - } - - @Test - void shouldFindByNameNotEquals() { - - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .of(Person.builder().build())); - - personRepository.findByNameNotEquals("name"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).singleResult(captor.capture()); - ColumnQuery query = captor.getValue(); - ColumnCondition condition = query.condition().get(); - assertEquals(Condition.NOT, condition.condition()); - assertEquals("Person", query.name()); - ColumnCondition columnCondition = condition.column().get(ColumnCondition.class); - assertEquals(Condition.EQUALS, columnCondition.condition()); - assertEquals(Column.of("name", "name"), columnCondition.column()); - - assertNotNull(personRepository.findByName("name")); - when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional - .empty()); - - assertNull(personRepository.findByName("name")); - } - - @Test - void shouldExecuteDefaultMethod() { - personRepository.partcionate("name"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template, Mockito.times(2)).singleResult(captor.capture()); - List values = captor.getAllValues(); - assertThat(values).isNotNull().hasSize(2); - } - - @Test - void shouldUseQueriesFromOtherInterface() { - personRepository.findByNameLessThan("name"); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals("Person", query.name()); - ColumnCondition condition = query.condition().get(); - assertEquals(LESSER_THAN, condition.condition()); - assertEquals(Column.of("name", "name"), condition.column()); - } - - @Test - void shouldUseDefaultMethodFromOtherInterface() { - personRepository.ada(); - - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - assertEquals("Person", query.name()); - ColumnCondition condition = query.condition().get(); - assertEquals(LESSER_THAN, condition.condition()); - assertEquals(Column.of("name", "Ada"), condition.column()); - } - - @Test - void shouldExecuteCustomRepository(){ - PersonStatisticRepository.PersonStatistic statistics = personRepository.statistics("Salvador"); - assertThat(statistics).isNotNull(); - SoftAssertions.assertSoftly(softly -> { - softly.assertThat(statistics.average()).isEqualTo(26); - softly.assertThat(statistics.sum()).isEqualTo(26); - softly.assertThat(statistics.max()).isEqualTo(26); - softly.assertThat(statistics.min()).isEqualTo(26); - softly.assertThat(statistics.count()).isEqualTo(1); - softly.assertThat(statistics.city()).isEqualTo("Salvador"); - }); - } - - @Test - void shouldInsertUsingAnnotation(){ - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - personRepository.insertPerson(person); - Mockito.verify(template).insert(person); - } - - @Test - void shouldUpdateUsingAnnotation(){ - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - personRepository.updatePerson(person); - Mockito.verify(template).update(person); - } - - @Test - void shouldDeleteUsingAnnotation(){ - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - personRepository.deletePerson(person); - Mockito.verify(template).delete(Person.class, 10L); - } - - @Test - void shouldSaveUsingAnnotation(){ - Person person = Person.builder().withName("Ada") - .withId(10L) - .withPhones(singletonList("123123")) - .build(); - personRepository.savePerson(person); - Mockito.verify(template).insert(person); - } - - @Test - void shouldExecuteMatchParameter(){ - personRepository.find("Ada"); - ArgumentCaptor captor = ArgumentCaptor.forClass(ColumnQuery.class); - verify(template).select(captor.capture()); - ColumnQuery query = captor.getValue(); - SoftAssertions.assertSoftly(softly -> { - softly.assertThat(query.name()).isEqualTo("Person"); - var condition = query.condition().orElseThrow(); - softly.assertThat(condition.condition()).isEqualTo(Condition.EQUALS); - softly.assertThat(condition.column()).isEqualTo(Column.of("name", "Ada")); - }); - } - - public interface BaseQuery { - - List findByNameLessThan(String name); - - default List ada() { - return this.findByNameLessThan("Ada"); - } - } - - public interface PersonRepository extends NoSQLRepository, BaseQuery, PersonStatisticRepository { - - List findByActiveTrue(); - - List findByActiveFalse(); - - List findBySalary_Currency(String currency); - - List findBySalary_CurrencyAndSalary_Value(String currency, BigDecimal value); - - List findBySalary_CurrencyOrderByCurrency_Name(String currency); - - Person findByName(String name); - - Person findByNameNot(String name); - - Person findByNameNotEquals(String name); - - @Insert - Person insertPerson(Person person); - @Update - Person updatePerson(Person person); - - @Save - Person savePerson(Person person); - - @Delete - void deletePerson(Person person); - - default Map> partcionate(String name) { - Objects.requireNonNull(name, "name is required"); - - var person = Person.builder() - .withName("Ada Lovelace") - .withAge(20) - .withId(1L).build(); - findByName(name); - findByNameNot(name); - Map> map = new HashMap<>(); - map.put(true, List.of(person)); - map.put(false, List.of(person)); - return map; - } - - void deleteByName(String name); - - List findByAge(String age); - - List findByNameAndAge(String name, Integer age); - - Set findByAgeAndName(Integer age, String name); - - Stream findByNameAndAgeOrderByName(String name, Integer age); - - Queue findByNameAndAgeOrderByAge(String name, Integer age); - - Set findByNameAndAgeGreaterThanEqual(String name, Integer age); - - Set findByAgeGreaterThan(Integer age); - - Set findByAgeLessThanEqual(Integer age); - - Set findByAgeLessThan(Integer age); - - Set findByAgeBetween(Integer ageA, Integer ageB); - - Set findByNameLike(String name); - - @Query("select * from Person") - Optional findByQuery(); - - @Query("select * from Person where id = @id") - Optional findByQuery(@Param("id") String id); - - long countByName(String name); - - boolean existsByName(String name); - - @OrderBy("name") - List findBy(); - - @OrderBy("name") - @OrderBy("age") - List findByException(); - - List find(@By("name") String name); - } - - public interface VendorRepository extends BasicRepository { - - Vendor findByPrefixes(String prefix); - - Vendor findByPrefixesIn(List prefix); - - } -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/DefaultColumnRepositoryProducerTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/DefaultColumnRepositoryProducerTest.java deleted file mode 100644 index 62c3574f3..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/DefaultColumnRepositoryProducerTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.column.ColumnManager; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.ColumnEntityConverter; -import org.eclipse.jnosql.mapping.column.JNoSQLColumnTemplate; -import org.eclipse.jnosql.mapping.column.MockProducer; -import org.eclipse.jnosql.mapping.column.entities.PersonRepository; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class DefaultColumnRepositoryProducerTest { - - @Inject - private ColumnRepositoryProducer producer; - - - @Test - void shouldCreateFromManager() { - ColumnManager manager= Mockito.mock(ColumnManager.class); - PersonRepository personRepository = producer.get(PersonRepository.class, manager); - assertNotNull(personRepository); - } - - - @Test - void shouldCreateFromTemplate() { - JNoSQLColumnTemplate template= Mockito.mock(JNoSQLColumnTemplate.class); - PersonRepository personRepository = producer.get(PersonRepository.class, template); - assertNotNull(personRepository); - } - - -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/DynamicQueryTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/DynamicQueryTest.java deleted file mode 100644 index 8f9d5f425..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/DynamicQueryTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - -import jakarta.data.Limit; -import jakarta.data.page.PageRequest; -import jakarta.data.Sort; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.mapping.core.repository.SpecialParameters; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - - -class DynamicQueryTest { - - @Mock - private SpecialParameters special; - - @Mock - private ColumnQuery query; - - @Mock - private Limit limit; - - @BeforeEach - void setUp() { - MockitoAnnotations.openMocks(this); - } - - @Test - void shouldCreateDynamicQuery() { - when(special.isEmpty()).thenReturn(true); - when(query.condition()).thenReturn(Optional.empty()); - when(query.name()).thenReturn("sampleQuery"); - - DynamicQuery dynamicQuery = DynamicQuery.of(new Object[]{}, query); - - assertEquals(query, dynamicQuery.get()); - } - - @Test - void shouldCreateDynamicQueryWithSortsAndLimit() { - when(special.isEmpty()).thenReturn(false); - when(special.hasOnlySort()).thenReturn(true); - when(special.sorts()).thenReturn(List.of(mock(Sort.class))); - when(limit.startAt()).thenReturn(1L); - when(special.limit()).thenReturn(Optional.of(limit)); - when(query.condition()).thenReturn(Optional.empty()); - when(query.name()).thenReturn("sampleQuery"); - when(query.sorts()).thenReturn(List.of(mock(Sort.class))); - when(query.skip()).thenReturn(0L); - when(query.limit()).thenReturn(10L); - - DynamicQuery dynamicQuery = DynamicQuery.of(new Object[]{}, query); - - assertEquals("sampleQuery", dynamicQuery.get().name()); - assertEquals(0, dynamicQuery.get().skip()); - assertEquals(10, dynamicQuery.get().limit()); - assertEquals(1, dynamicQuery.get().sorts().size()); - } - - @Test - void shouldCreateDynamicQueryWithLimit() { - when(special.isEmpty()).thenReturn(false); - when(special.hasOnlySort()).thenReturn(false); - when(limit.startAt()).thenReturn(1L); - when(special.limit()).thenReturn(Optional.of(limit)); - when(query.condition()).thenReturn(Optional.empty()); - when(query.name()).thenReturn("sampleQuery"); - when(query.sorts()).thenReturn(List.of(mock(Sort.class))); - when(query.skip()).thenReturn(0L); - when(query.limit()).thenReturn(10L); - - DynamicQuery dynamicQuery = DynamicQuery.of(new Object[]{}, query); - - assertEquals("sampleQuery", dynamicQuery.get().name()); - assertEquals(0, dynamicQuery.get().skip()); - assertEquals(10, dynamicQuery.get().limit()); - assertEquals(1, dynamicQuery.get().sorts().size()); - } - - @Test - void shouldCreateDynamicQueryWithPageRequest() { - when(special.isEmpty()).thenReturn(false); - when(special.pageRequest()).thenReturn(Optional.of(mock(PageRequest.class))); - when(special.sorts()).thenReturn(List.of(mock(Sort.class))); - when(query.condition()).thenReturn(Optional.empty()); - when(query.name()).thenReturn("sampleQuery"); - when(query.sorts()).thenReturn(List.of(mock(Sort.class))); - when(query.skip()).thenReturn(0L); - when(query.limit()).thenReturn(10L); - - DynamicQuery dynamicQuery = DynamicQuery.of(new Object[]{}, query); - - assertEquals("sampleQuery", dynamicQuery.get().name()); - assertEquals(0, dynamicQuery.get().skip()); - assertEquals(10, dynamicQuery.get().limit()); - assertEquals(1, dynamicQuery.get().sorts().size()); - } - - @Test - void shouldReturnWhenThereIsLimitAndSort(){ - when(special.isEmpty()).thenReturn(false); - when(special.pageRequest()).thenReturn(Optional.of(mock(PageRequest.class))); - when(query.condition()).thenReturn(Optional.empty()); - when(query.name()).thenReturn("sampleQuery"); - when(query.sorts()).thenReturn(Collections.emptyList()); - when(query.skip()).thenReturn(0L); - when(query.limit()).thenReturn(10L); - - DynamicQuery dynamicQuery = DynamicQuery.of(new Object[]{Sort.asc("name"), Limit.of(20)} - , query); - - ColumnQuery columnQuery = dynamicQuery.get(); - assertEquals("sampleQuery", columnQuery.name()); - assertEquals(0, columnQuery.skip()); - assertEquals(20, columnQuery.limit()); - assertEquals(1, columnQuery.sorts().size()); - } -} \ No newline at end of file diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ParamsBinderTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ParamsBinderTest.java deleted file mode 100644 index 4536d426d..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/ParamsBinderTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - -import jakarta.inject.Inject; -import org.eclipse.jnosql.communication.Params; -import org.eclipse.jnosql.communication.TypeReference; -import org.eclipse.jnosql.communication.Value; -import org.eclipse.jnosql.communication.column.Column; -import org.eclipse.jnosql.communication.column.ColumnCondition; -import org.eclipse.jnosql.communication.column.ColumnQuery; -import org.eclipse.jnosql.communication.column.ColumnQueryParams; -import org.eclipse.jnosql.communication.column.SelectQueryParser; -import org.eclipse.jnosql.communication.query.SelectQuery; -import org.eclipse.jnosql.communication.query.method.SelectMethodProvider; -import org.eclipse.jnosql.mapping.core.Converters; -import org.eclipse.jnosql.mapping.column.ColumnEntityConverter; -import org.eclipse.jnosql.mapping.column.MockProducer; -import org.eclipse.jnosql.mapping.column.entities.Person; -import org.eclipse.jnosql.mapping.column.spi.ColumnExtension; -import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; -import org.eclipse.jnosql.mapping.metadata.EntityMetadata; -import org.eclipse.jnosql.mapping.reflection.Reflections; -import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; -import org.eclipse.jnosql.mapping.core.util.ParamsBinder; -import org.jboss.weld.junit5.auto.AddExtensions; -import org.jboss.weld.junit5.auto.AddPackages; -import org.jboss.weld.junit5.auto.EnableAutoWeld; -import org.junit.jupiter.api.Test; - -import java.lang.reflect.Method; -import java.util.List; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -@EnableAutoWeld -@AddPackages(value = {Converters.class, ColumnEntityConverter.class}) -@AddPackages(MockProducer.class) -@AddPackages(Reflections.class) -@AddExtensions({EntityMetadataExtension.class, ColumnExtension.class}) -class ParamsBinderTest { - - - @Inject - private EntitiesMetadata mappings; - - @Inject - private Converters converters; - - private ParamsBinder paramsBinder; - - @Test - void shouldConvert() { - - Method method = Stream.of(PersonRepository.class.getMethods()) - .filter(m -> m.getName().equals("findByAge")).findFirst().get(); - EntityMetadata entityMetadata = mappings.get(Person.class); - RepositoryColumnObserverParser parser = new RepositoryColumnObserverParser(entityMetadata); - paramsBinder = new ParamsBinder(entityMetadata, converters); - - SelectMethodProvider selectMethodFactory = SelectMethodProvider.INSTANCE; - SelectQuery selectQuery = selectMethodFactory.apply(method, entityMetadata.name()); - SelectQueryParser queryParser = new SelectQueryParser(); - ColumnQueryParams columnQueryParams = queryParser.apply(selectQuery, parser); - Params params = columnQueryParams.params(); - Object[] args = {10}; - paramsBinder.bind(params, args, method); - ColumnQuery query = columnQueryParams.query(); - ColumnCondition columnCondition = query.condition().get(); - Value value = columnCondition.column().value(); - assertEquals(10, value.get()); - - } - - @Test - void shouldConvert2() { - - Method method = Stream.of(PersonRepository.class.getMethods()) - .filter(m -> m.getName().equals("findByAgeAndName")).findFirst().get(); - EntityMetadata entityMetadata = mappings.get(Person.class); - RepositoryColumnObserverParser parser = new RepositoryColumnObserverParser(entityMetadata); - paramsBinder = new ParamsBinder(entityMetadata, converters); - - SelectMethodProvider selectMethodFactory = SelectMethodProvider.INSTANCE; - SelectQuery selectQuery = selectMethodFactory.apply(method, entityMetadata.name()); - SelectQueryParser queryParser = new SelectQueryParser(); - ColumnQueryParams queryParams = queryParser.apply(selectQuery, parser); - Params params = queryParams.params(); - paramsBinder.bind(params, new Object[]{10L, "Ada"}, method); - ColumnQuery query = queryParams.query(); - ColumnCondition columnCondition = query.condition().get(); - List conditions = columnCondition.column().get(new TypeReference<>() { - }); - List values = conditions.stream().map(ColumnCondition::column) - .map(Column::value) - .map(Value::get).toList(); - assertEquals(10, values.get(0)); - assertEquals("Ada", values.get(1)); - - } - - - interface PersonRepository { - - List findByAge(Integer age); - - List findByAgeAndName(Long age, String name); - } - - -} diff --git a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/RepositoryColumnObserverParserTest.java b/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/RepositoryColumnObserverParserTest.java deleted file mode 100644 index e86293b2a..000000000 --- a/jnosql-mapping/jnosql-mapping-column/src/test/java/org/eclipse/jnosql/mapping/column/query/RepositoryColumnObserverParserTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. - * - * You may elect to redistribute this code under either of these licenses. - * - * Contributors: - * - * Otavio Santana - */ -package org.eclipse.jnosql.mapping.column.query; - -import org.eclipse.jnosql.communication.column.ColumnObserverParser; -import org.eclipse.jnosql.mapping.metadata.EntityMetadata; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import static org.junit.jupiter.api.Assertions.*; - -class RepositoryColumnObserverParserTest { - - @Test - void shouldCreateFromRepository() { - EntityMetadata entityMetadata = Mockito.mock(EntityMetadata.class); - ColumnObserverParser parser = RepositoryColumnObserverParser.of(entityMetadata); - assertNotNull(parser); - } -} \ No newline at end of file