|
15 | 15 | package jakarta.nosql.tck.communication.driver.column; |
16 | 16 |
|
17 | 17 | import jakarta.nosql.ServiceLoaderProvider; |
| 18 | +import jakarta.nosql.column.Column; |
| 19 | +import jakarta.nosql.column.ColumnDeleteQuery; |
18 | 20 | import jakarta.nosql.column.ColumnEntity; |
19 | 21 | import jakarta.nosql.column.ColumnFamilyManager; |
20 | | -import org.junit.jupiter.api.Assumptions; |
| 22 | +import org.junit.jupiter.api.Assertions; |
21 | 23 | import org.junit.jupiter.params.ParameterizedTest; |
22 | | -import org.junit.jupiter.params.provider.ArgumentsSource; |
23 | 24 |
|
24 | 25 | import java.util.List; |
25 | 26 | import java.util.Optional; |
26 | 27 | import java.util.stream.Collectors; |
27 | 28 |
|
28 | | -import static org.junit.jupiter.api.Assertions.assertNotNull; |
29 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 29 | +import static jakarta.nosql.column.ColumnDeleteQuery.delete; |
| 30 | +import static org.junit.jupiter.api.Assumptions.assumeTrue; |
30 | 31 |
|
31 | 32 | public class ColumnFamilyManagerTest { |
32 | 33 |
|
33 | 34 | @ParameterizedTest |
34 | 35 | @ColumnSource("column_insert.properties") |
35 | 36 | public void shouldInsert(ColumnArgument argument) { |
36 | | - Assumptions.assumeFalse(argument.isEmpty(), "The you put the file in the resources to activate this test"); |
| 37 | + assumeTrue(argument.isEmpty()); |
37 | 38 | ColumnFamilyManager manager = getManager(); |
38 | | - Optional<ColumnEntity> entity = argument.getQuery().stream().flatMap(manager::query) |
| 39 | + Optional<ColumnEntity> entityOptional = argument.getQuery().stream().flatMap(manager::query) |
39 | 40 | .findFirst(); |
| 41 | + Assertions.assertTrue(entityOptional.isPresent()); |
| 42 | + final ColumnEntity entity = entityOptional |
| 43 | + .orElseThrow(() -> new ColumnDriverException("Should return an entity when the entity is saved")); |
40 | 44 |
|
| 45 | + final Column id = entity.find(argument.getIdName()) |
| 46 | + .orElseThrow(() -> new ColumnDriverException("Should return the id in the entity")); |
| 47 | + ColumnDeleteQuery deleteQuery = delete().from(entity.getName()).where(id.getName()).eq(id.get()).build(); |
| 48 | + manager.delete(deleteQuery); |
| 49 | + } |
| 50 | + |
| 51 | + @ParameterizedTest |
| 52 | + @ColumnSource("column_insert.properties") |
| 53 | + public void shouldReturnErrorWhenInsertIsNull(ColumnArgument argument) { |
| 54 | + assumeTrue(argument.isEmpty()); |
| 55 | + ColumnFamilyManager manager = getManager(); |
| 56 | + Assertions.assertThrows(NullPointerException.class, () -> manager.insert((ColumnEntity) null)); |
| 57 | + } |
| 58 | + |
| 59 | + @ParameterizedTest |
| 60 | + @ColumnSource("column_insert_ttl.properties") |
| 61 | + public void shouldInsert(ColumnArgument argument) { |
| 62 | + assumeTrue(argument.isEmpty()); |
| 63 | + ColumnFamilyManager manager = getManager(); |
| 64 | + Optional<ColumnEntity> entityOptional = argument.getQuery().stream().flatMap(manager::query) |
| 65 | + .findFirst(); |
| 66 | + Assertions.assertTrue(entityOptional.isPresent()); |
| 67 | + final ColumnEntity entity = entityOptional |
| 68 | + .orElseThrow(() -> new ColumnDriverException("Should return an entity when the entity is saved")); |
41 | 69 |
|
| 70 | + final Column id = entity.find(argument.getIdName()) |
| 71 | + .orElseThrow(() -> new ColumnDriverException("Should return the id in the entity")); |
| 72 | + ColumnDeleteQuery deleteQuery = delete().from(entity.getName()).where(id.getName()).eq(id.get()).build(); |
| 73 | + manager.delete(deleteQuery); |
| 74 | + } |
| 75 | + |
| 76 | + @ParameterizedTest |
| 77 | + @ColumnSource("column_insert_iterable.properties") |
| 78 | + public void shouldInsertIterable(ColumnArgument argument) { |
| 79 | + assumeTrue(argument.isEmpty()); |
| 80 | + ColumnFamilyManager manager = getManager(); |
| 81 | + List<ColumnEntity> entities = argument.getQuery().stream().flatMap(manager::query) |
| 82 | + .collect(Collectors.toList()); |
| 83 | + |
| 84 | + final List<Object> ids = entities.stream() |
| 85 | + .map(c -> c.find(argument.getIdName())) |
| 86 | + .filter(Optional::isPresent) |
| 87 | + .map(Optional::get) |
| 88 | + .map(Column::get) |
| 89 | + .collect(Collectors.toList()); |
| 90 | + |
| 91 | + Assertions.assertEquals(argument.getQuery().size(), ids.size()); |
| 92 | + |
| 93 | + ColumnDeleteQuery deleteQuery = delete().from(entities.get(0).getName()) |
| 94 | + .where(argument.getIdName()).in(ids).build(); |
| 95 | + manager.delete(deleteQuery); |
| 96 | + } |
| 97 | + |
| 98 | + @ParameterizedTest |
| 99 | + @ColumnSource("column_insert_iterable.properties") |
| 100 | + public void shouldReturnErrorWhenInsertIterableIsNull(ColumnArgument argument) { |
| 101 | + assumeTrue(argument.isEmpty()); |
| 102 | + ColumnFamilyManager manager = getManager(); |
| 103 | + Assertions.assertThrows(NullPointerException.class, () -> manager.insert((Iterable<ColumnEntity>) null)); |
42 | 104 | } |
43 | 105 |
|
44 | 106 | private ColumnFamilyManager getManager() { |
|
0 commit comments