/
DefaultColumnQueryPaginationTest.java
96 lines (73 loc) · 3.43 KB
/
DefaultColumnQueryPaginationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
*
* Copyright (c) 2019 Otávio Santana and others
* 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.jnosql.artemis.column;
import org.jnosql.artemis.Pagination;
import org.jnosql.diana.api.column.ColumnQuery;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.jnosql.diana.api.column.query.ColumnQueryBuilder.select;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class DefaultColumnQueryPaginationTest {
@Test
public void shouldReturnNPEWhenQueryIsNull() {
Assertions.assertThrows(NullPointerException.class, () ->
ColumnQueryPagination.of(null, Pagination.page(1).of(2)));
}
@Test
public void shouldReturnNPEWhenPaginationIsNull() {
Assertions.assertThrows(NullPointerException.class, () ->
ColumnQueryPagination.of(select().from("column").build(), null));
}
@Test
public void shouldCreateColumnQueryPagination() {
ColumnQuery query = select().from("column").build();
Pagination pagination = Pagination.page(1).of(2);
ColumnQueryPagination queryPagination = ColumnQueryPagination.of(query, pagination);
assertNotNull(queryPagination);
isQueryEquals(query, pagination, queryPagination);
}
@Test
public void shouldOverrideSkipLimit() {
ColumnQuery query = select().from("column").build();
Pagination pagination = Pagination.page(1).of(2);
ColumnQueryPagination queryPagination = ColumnQueryPagination.of(query, pagination);
assertNotNull(queryPagination);
assertEquals(pagination.getLimit(), queryPagination.getLimit());
assertEquals(pagination.getSkip(), queryPagination.getSkip());
}
@Test
public void shouldNext() {
ColumnQuery query = select().from("column").where("name").eq("Ada").build();
Pagination pagination = Pagination.page(1).of(2);
Pagination secondPage = pagination.next();
ColumnQueryPagination queryPagination = ColumnQueryPagination.of(query, pagination);
assertNotNull(queryPagination);
assertEquals(pagination.getLimit(), queryPagination.getLimit());
assertEquals(pagination.getSkip(), queryPagination.getSkip());
isQueryEquals(query, pagination, queryPagination);
ColumnQueryPagination next = queryPagination.next();
isQueryEquals(query, secondPage, next);
}
private void isQueryEquals(ColumnQuery query, Pagination pagination, ColumnQueryPagination queryPagination) {
assertEquals(query.getColumnFamily(), queryPagination.getColumnFamily());
assertEquals(query.getColumns(), queryPagination.getColumns());
assertEquals(pagination, queryPagination.getPagination());
assertEquals(query.getSorts(), queryPagination.getSorts());
assertEquals(query.getCondition().orElse(null), queryPagination.getCondition().orElse(null));
}
}