|
20 | 20 |
|
21 | 21 | package com.arangodb;
|
22 | 22 |
|
23 |
| -import com.arangodb.ArangoDB.Builder; |
24 | 23 | import com.arangodb.model.AqlQueryOptions;
|
25 | 24 | import com.arangodb.velocypack.VPackSlice;
|
| 25 | +import org.junit.BeforeClass; |
26 | 26 | import org.junit.Test;
|
27 | 27 | import org.junit.runner.RunWith;
|
28 | 28 | import org.junit.runners.Parameterized;
|
|
33 | 33 | import java.util.Set;
|
34 | 34 | import java.util.concurrent.atomic.AtomicLong;
|
35 | 35 |
|
| 36 | +import static org.hamcrest.MatcherAssert.assertThat; |
36 | 37 | import static org.hamcrest.Matchers.*;
|
37 |
| -import static org.junit.Assert.assertThat; |
38 | 38 |
|
39 | 39 | /**
|
40 | 40 | * @author Mark Vollmary
|
41 | 41 | */
|
42 | 42 | @RunWith(Parameterized.class)
|
43 | 43 | public class ArangoCursorTest extends BaseTest {
|
44 | 44 |
|
45 |
| - public ArangoCursorTest(final Builder builder) { |
46 |
| - super(builder); |
47 |
| - } |
48 |
| - |
49 |
| - @Test |
50 |
| - public void first() { |
51 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
52 |
| - final VPackSlice first = cursor.first(); |
53 |
| - assertThat(first, is(not(nullValue()))); |
54 |
| - assertThat(first.isInteger(), is(true)); |
55 |
| - assertThat(first.getAsLong(), is(0L)); |
56 |
| - } |
57 |
| - |
58 |
| - @Test |
59 |
| - public void next() { |
60 |
| - |
61 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", new AqlQueryOptions().batchSize(5), VPackSlice.class); |
62 |
| - |
63 |
| - while (cursor.hasNext()) { |
64 |
| - cursor.next(); |
65 |
| - } |
66 |
| - |
67 |
| - } |
68 |
| - |
69 |
| - @Test |
70 |
| - public void mapFilterCount() { |
71 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
72 |
| - final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).count(); |
73 |
| - assertThat(count, is(50L)); |
74 |
| - } |
75 |
| - |
76 |
| - @Test |
77 |
| - public void mapMapFilterCount() { |
78 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
79 |
| - final long count = cursor.map(VPackSlice::getAsLong).map(t -> t * 10).filter(t -> t < 500).count(); |
80 |
| - assertThat(count, is(50L)); |
81 |
| - } |
82 |
| - |
83 |
| - @Test |
84 |
| - public void mapMapFilterFilterCount() { |
85 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
86 |
| - final long count = cursor.map(VPackSlice::getAsLong).map(t -> t * 10).filter(t -> t < 500).filter(t -> t < 250).count(); |
87 |
| - assertThat(count, is(25L)); |
88 |
| - } |
89 |
| - |
90 |
| - @Test |
91 |
| - public void mapFilterNext() { |
92 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
93 |
| - final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).iterator().next(); |
94 |
| - assertThat(count, is(0L)); |
95 |
| - } |
96 |
| - |
97 |
| - @Test |
98 |
| - public void mapFilterFirst() { |
99 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
100 |
| - final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).first(); |
101 |
| - assertThat(count, is(0L)); |
102 |
| - } |
103 |
| - |
104 |
| - @Test |
105 |
| - public void mapFilterCollectIntoList() { |
106 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
107 |
| - final List<Long> target = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).collectInto(new ArrayList<>()); |
108 |
| - assertThat(target, is(not(nullValue()))); |
109 |
| - assertThat(target.size(), is(50)); |
110 |
| - } |
111 |
| - |
112 |
| - @Test |
113 |
| - public void mapFilterCollectIntoSet() { |
114 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
115 |
| - final Set<Long> target = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).collectInto(new HashSet<>()); |
116 |
| - assertThat(target, is(not(nullValue()))); |
117 |
| - assertThat(target.size(), is(50)); |
118 |
| - } |
119 |
| - |
120 |
| - @Test |
121 |
| - public void foreach() { |
122 |
| - final AtomicLong i = new AtomicLong(0L); |
123 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
124 |
| - cursor.foreach(t -> assertThat(t.getAsLong(), is(i.getAndIncrement()))); |
125 |
| - } |
126 |
| - |
127 |
| - @Test |
128 |
| - public void mapForeach() { |
129 |
| - final AtomicLong i = new AtomicLong(0L); |
130 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
131 |
| - cursor.map(VPackSlice::getAsLong).foreach(t -> assertThat(t, is(i.getAndIncrement()))); |
132 |
| - } |
133 |
| - |
134 |
| - @Test |
135 |
| - public void mapFilterForeach() { |
136 |
| - final AtomicLong i = new AtomicLong(0L); |
137 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
138 |
| - cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).foreach(t -> assertThat(t, is(i.getAndIncrement()))); |
139 |
| - } |
140 |
| - |
141 |
| - @Test |
142 |
| - public void anyMatch() { |
143 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
144 |
| - final boolean match = cursor.anyMatch(t -> t.getAsLong() == 50L); |
145 |
| - assertThat(match, is(true)); |
146 |
| - } |
147 |
| - |
148 |
| - @Test |
149 |
| - public void mapAnyMatch() { |
150 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
151 |
| - final boolean match = cursor.map(VPackSlice::getAsLong).anyMatch(t -> t == 50L); |
152 |
| - assertThat(match, is(true)); |
153 |
| - } |
154 |
| - |
155 |
| - @Test |
156 |
| - public void mapFilterAnyMatch() { |
157 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
158 |
| - final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).anyMatch(t -> t == 25L); |
159 |
| - assertThat(match, is(true)); |
160 |
| - } |
161 |
| - |
162 |
| - @Test |
163 |
| - public void noneMatch() { |
164 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
165 |
| - final boolean match = cursor.noneMatch(t -> t.getAsLong() == 100L); |
166 |
| - assertThat(match, is(true)); |
167 |
| - } |
168 |
| - |
169 |
| - @Test |
170 |
| - public void mapNoneMatch() { |
171 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
172 |
| - final boolean match = cursor.map(VPackSlice::getAsLong).noneMatch(t -> t == 100L); |
173 |
| - assertThat(match, is(true)); |
174 |
| - } |
175 |
| - |
176 |
| - @Test |
177 |
| - public void mapFilterNoneMatch() { |
178 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
179 |
| - final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).noneMatch(t -> t == 50L); |
180 |
| - assertThat(match, is(true)); |
181 |
| - } |
182 |
| - |
183 |
| - @Test |
184 |
| - public void allMatch() { |
185 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
186 |
| - final boolean match = cursor.allMatch(t -> t.getAsLong() < 100L); |
187 |
| - assertThat(match, is(true)); |
188 |
| - } |
189 |
| - |
190 |
| - @Test |
191 |
| - public void mapAllMatch() { |
192 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
193 |
| - final boolean match = cursor.map(VPackSlice::getAsLong).allMatch(t -> t < 100); |
194 |
| - assertThat(match, is(true)); |
195 |
| - } |
196 |
| - |
197 |
| - @Test |
198 |
| - public void mapFilterAllMatch() { |
199 |
| - final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
200 |
| - final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).allMatch(t -> t < 50); |
201 |
| - assertThat(match, is(true)); |
202 |
| - } |
| 45 | + @BeforeClass |
| 46 | + public static void init() { |
| 47 | + BaseTest.initDB(); |
| 48 | + } |
| 49 | + |
| 50 | + public ArangoCursorTest(final ArangoDB arangoDB) { |
| 51 | + super(arangoDB); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void first() { |
| 56 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 57 | + final VPackSlice first = cursor.first(); |
| 58 | + assertThat(first, is(not(nullValue()))); |
| 59 | + assertThat(first.isInteger(), is(true)); |
| 60 | + assertThat(first.getAsLong(), is(0L)); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void next() { |
| 65 | + |
| 66 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", new AqlQueryOptions().batchSize(5), VPackSlice.class); |
| 67 | + |
| 68 | + while (cursor.hasNext()) { |
| 69 | + cursor.next(); |
| 70 | + } |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void mapFilterCount() { |
| 76 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 77 | + final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).count(); |
| 78 | + assertThat(count, is(50L)); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void mapMapFilterCount() { |
| 83 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 84 | + final long count = cursor.map(VPackSlice::getAsLong).map(t -> t * 10).filter(t -> t < 500).count(); |
| 85 | + assertThat(count, is(50L)); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + public void mapMapFilterFilterCount() { |
| 90 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 91 | + final long count = cursor.map(VPackSlice::getAsLong).map(t -> t * 10).filter(t -> t < 500).filter(t -> t < 250).count(); |
| 92 | + assertThat(count, is(25L)); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void mapFilterNext() { |
| 97 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 98 | + final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).iterator().next(); |
| 99 | + assertThat(count, is(0L)); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void mapFilterFirst() { |
| 104 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 105 | + final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).first(); |
| 106 | + assertThat(count, is(0L)); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void mapFilterCollectIntoList() { |
| 111 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 112 | + final List<Long> target = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).collectInto(new ArrayList<>()); |
| 113 | + assertThat(target, is(not(nullValue()))); |
| 114 | + assertThat(target.size(), is(50)); |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + public void mapFilterCollectIntoSet() { |
| 119 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 120 | + final Set<Long> target = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).collectInto(new HashSet<>()); |
| 121 | + assertThat(target, is(not(nullValue()))); |
| 122 | + assertThat(target.size(), is(50)); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + public void foreach() { |
| 127 | + final AtomicLong i = new AtomicLong(0L); |
| 128 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 129 | + cursor.foreach(t -> assertThat(t.getAsLong(), is(i.getAndIncrement()))); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void mapForeach() { |
| 134 | + final AtomicLong i = new AtomicLong(0L); |
| 135 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 136 | + cursor.map(VPackSlice::getAsLong).foreach(t -> assertThat(t, is(i.getAndIncrement()))); |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + public void mapFilterForeach() { |
| 141 | + final AtomicLong i = new AtomicLong(0L); |
| 142 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 143 | + cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).foreach(t -> assertThat(t, is(i.getAndIncrement()))); |
| 144 | + } |
| 145 | + |
| 146 | + @Test |
| 147 | + public void anyMatch() { |
| 148 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 149 | + final boolean match = cursor.anyMatch(t -> t.getAsLong() == 50L); |
| 150 | + assertThat(match, is(true)); |
| 151 | + } |
| 152 | + |
| 153 | + @Test |
| 154 | + public void mapAnyMatch() { |
| 155 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 156 | + final boolean match = cursor.map(VPackSlice::getAsLong).anyMatch(t -> t == 50L); |
| 157 | + assertThat(match, is(true)); |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + public void mapFilterAnyMatch() { |
| 162 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 163 | + final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).anyMatch(t -> t == 25L); |
| 164 | + assertThat(match, is(true)); |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + public void noneMatch() { |
| 169 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 170 | + final boolean match = cursor.noneMatch(t -> t.getAsLong() == 100L); |
| 171 | + assertThat(match, is(true)); |
| 172 | + } |
| 173 | + |
| 174 | + @Test |
| 175 | + public void mapNoneMatch() { |
| 176 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 177 | + final boolean match = cursor.map(VPackSlice::getAsLong).noneMatch(t -> t == 100L); |
| 178 | + assertThat(match, is(true)); |
| 179 | + } |
| 180 | + |
| 181 | + @Test |
| 182 | + public void mapFilterNoneMatch() { |
| 183 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 184 | + final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).noneMatch(t -> t == 50L); |
| 185 | + assertThat(match, is(true)); |
| 186 | + } |
| 187 | + |
| 188 | + @Test |
| 189 | + public void allMatch() { |
| 190 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 191 | + final boolean match = cursor.allMatch(t -> t.getAsLong() < 100L); |
| 192 | + assertThat(match, is(true)); |
| 193 | + } |
| 194 | + |
| 195 | + @Test |
| 196 | + public void mapAllMatch() { |
| 197 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 198 | + final boolean match = cursor.map(VPackSlice::getAsLong).allMatch(t -> t < 100); |
| 199 | + assertThat(match, is(true)); |
| 200 | + } |
| 201 | + |
| 202 | + @Test |
| 203 | + public void mapFilterAllMatch() { |
| 204 | + final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class); |
| 205 | + final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).allMatch(t -> t < 50); |
| 206 | + assertThat(match, is(true)); |
| 207 | + } |
203 | 208 | }
|
0 commit comments