Close DB in junits
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / EntityTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2021 Nordix Foundation.
4  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.dao;
23
24 import static org.assertj.core.api.Assertions.assertThatCode;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29
30 import java.time.Instant;
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Properties;
36 import java.util.Set;
37 import java.util.TreeSet;
38 import java.util.UUID;
39 import org.eclipse.persistence.config.PersistenceUnitProperties;
40 import org.junit.After;
41 import org.junit.Test;
42 import org.onap.policy.models.base.PfConceptKey;
43 import org.onap.policy.models.base.PfModelException;
44 import org.onap.policy.models.base.PfReferenceKey;
45 import org.onap.policy.models.base.PfTimestampKey;
46 import org.onap.policy.models.dao.impl.DefaultPfDao;
47
48 /**
49  * JUnit test class.
50  */
51 public class EntityTest {
52     private static final String DESCRIPTION2 = "key description 2";
53     private static final String DESCRIPTION1 = "key description 1";
54     private static final String DESCRIPTION0 = "key description 0";
55     private static final String ENTITY0 = "Entity0";
56     private static final String UUID2 = "00000000-0000-0000-0000-000000000002";
57     private static final String UUID1 = "00000000-0000-0000-0000-000000000001";
58     private static final String UUID0 = "00000000-0000-0000-0000-000000000000";
59     private static final String VERSION003 = "0.0.3";
60     private static final String VERSION002 = "0.0.2";
61     private static final String VERSION001 = "0.0.1";
62     private static final Instant TIMESTAMP0 = Instant.ofEpochSecond(1613494293);
63     private static final Instant TIMESTAMP1 = Instant.ofEpochSecond(1613494293).plusSeconds(55);
64     private static final Instant TIMESTAMP2 = Instant.ofEpochSecond(1613494293).plusSeconds(90);
65     private PfDao pfDao;
66
67     /**
68      * Closes the DAO.
69      */
70     @After
71     public void tearDown() {
72         if (pfDao != null) {
73             pfDao.close();
74             pfDao = null;
75         }
76     }
77
78     @Test
79     public void testEntityTestSanity() throws PfModelException {
80         final DaoParameters daoParameters = new DaoParameters();
81
82         Properties jdbcProperties = new Properties();
83         // @formatter:off
84         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER,   "org.h2.Driver");
85         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL,      "jdbc:h2:mem:EntityTest");
86         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER,     "sa");
87         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "");
88         // @formatter:on
89
90         daoParameters.setJdbcProperties(jdbcProperties);
91
92         pfDao = new PfDaoFactory().createPfDao(daoParameters);
93
94         assertThatThrownBy(() -> pfDao.init(null)).hasMessage("Policy Framework persistence unit parameter not set");
95
96         assertThatThrownBy(() -> pfDao.init(daoParameters))
97                         .hasMessage("Policy Framework persistence unit parameter not set");
98
99         daoParameters.setPluginClass("somewhere.over.the.rainbow");
100         daoParameters.setPersistenceUnit("Dorothy");
101
102         assertThatThrownBy(() -> pfDao.init(daoParameters))
103                         .hasMessage("Creation of Policy Framework persistence unit \"Dorothy\" failed");
104
105         assertThatThrownBy(() -> pfDao.create(new PfConceptKey()))
106                         .hasMessage("Policy Framework DAO has not been initialized");
107     }
108
109     @Test
110     public void testEntityTestAllOpsJpa() throws PfModelException {
111
112         final DaoParameters daoParameters = new DaoParameters();
113         daoParameters.setPluginClass(DefaultPfDao.class.getName());
114         daoParameters.setPersistenceUnit("DaoTest");
115
116         Properties jdbcProperties = new Properties();
117         jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
118         jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:EntityTest");
119         jdbcProperties.setProperty("javax.persistence.jdbc.user", "sa");
120         jdbcProperties.setProperty("javax.persistence.jdbc.password", "");
121
122         daoParameters.setJdbcProperties(jdbcProperties);
123
124         pfDao = new PfDaoFactory().createPfDao(daoParameters);
125         pfDao.init(daoParameters);
126
127         testAllOps();
128
129         testVersionOps();
130
131         testgetFilteredOps();
132     }
133
134     @Test
135     public void testEntityTestBadVals() throws PfModelException {
136         final DaoParameters daoParameters = new DaoParameters();
137         daoParameters.setPluginClass(DefaultPfDao.class.getName());
138         daoParameters.setPersistenceUnit("DaoTest");
139
140         pfDao = new PfDaoFactory().createPfDao(daoParameters);
141         pfDao.init(daoParameters);
142
143         final PfConceptKey nullKey = null;
144         final PfReferenceKey nullRefKey = null;
145         final PfTimestampKey nullTimeKey = null;
146         final List<PfConceptKey> nullKeyList = null;
147         final List<PfConceptKey> emptyKeyList = new ArrayList<>();
148         final List<PfReferenceKey> nullRKeyList = null;
149         final List<PfReferenceKey> emptyRKeyList = new ArrayList<>();
150
151         pfDao.create(nullKey);
152         pfDao.createCollection(nullKeyList);
153         pfDao.createCollection(emptyKeyList);
154
155         pfDao.delete(nullKey);
156         pfDao.deleteCollection(nullKeyList);
157         pfDao.deleteCollection(emptyKeyList);
158         pfDao.delete(PfConceptKey.class, nullKey);
159         pfDao.delete(PfReferenceKey.class, nullRefKey);
160         pfDao.delete(PfTimestampKey.class, nullTimeKey);
161         pfDao.deleteByConceptKey(PfConceptKey.class, nullKeyList);
162         pfDao.deleteByConceptKey(PfConceptKey.class, emptyKeyList);
163         pfDao.deleteByReferenceKey(PfReferenceKey.class, nullRKeyList);
164         pfDao.deleteByReferenceKey(PfReferenceKey.class, emptyRKeyList);
165
166         pfDao.get(null, nullKey);
167         pfDao.get(null, nullRefKey);
168         pfDao.get(null, nullTimeKey);
169         pfDao.getAll(null);
170         pfDao.getAll(null, nullKey);
171         pfDao.getConcept(null, nullKey);
172         pfDao.getConcept(PfConceptKey.class, nullKey);
173         pfDao.getConcept(null, nullRefKey);
174         pfDao.getConcept(PfReferenceKey.class, nullRefKey);
175
176         assertThatCode(() -> pfDao.size(null)).doesNotThrowAnyException();
177     }
178
179     private void testAllOps() {
180         final PfConceptKey aKey0 = new PfConceptKey("A-KEY0", VERSION001);
181         final PfConceptKey aKey1 = new PfConceptKey("A-KEY1", VERSION001);
182         final PfConceptKey aKey2 = new PfConceptKey("A-KEY2", VERSION001);
183         final DummyConceptEntity keyInfo0 = new DummyConceptEntity(aKey0,
184                 UUID.fromString(UUID0), DESCRIPTION0);
185         final DummyConceptEntity keyInfo1 = new DummyConceptEntity(aKey1,
186                 UUID.fromString(UUID1), DESCRIPTION1);
187         final DummyConceptEntity keyInfo2 = new DummyConceptEntity(aKey2,
188                 UUID.fromString(UUID2), DESCRIPTION2);
189
190         pfDao.create(keyInfo0);
191
192         final DummyConceptEntity keyInfoBack0 = pfDao.get(DummyConceptEntity.class, aKey0);
193         assertEquals(keyInfo0, keyInfoBack0);
194
195         final DummyConceptEntity keyInfoBackNull = pfDao.get(DummyConceptEntity.class, PfConceptKey.getNullKey());
196         assertNull(keyInfoBackNull);
197
198         final DummyConceptEntity keyInfoBack1 = pfDao.getConcept(DummyConceptEntity.class, aKey0);
199         assertEquals(keyInfoBack0, keyInfoBack1);
200
201         final DummyConceptEntity keyInfoBack2 =
202                 pfDao.getConcept(DummyConceptEntity.class, new PfConceptKey("A-KEY3", VERSION001));
203         assertNull(keyInfoBack2);
204
205         final Set<DummyConceptEntity> keyInfoSetIn = new TreeSet<>();
206         keyInfoSetIn.add(keyInfo1);
207         keyInfoSetIn.add(keyInfo2);
208
209         pfDao.createCollection(keyInfoSetIn);
210
211         Set<DummyConceptEntity> keyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyConceptEntity.class));
212
213         keyInfoSetIn.add(keyInfo0);
214         assertEquals(keyInfoSetIn, keyInfoSetOut);
215
216         pfDao.delete(keyInfo1);
217         keyInfoSetIn.remove(keyInfo1);
218         keyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyConceptEntity.class));
219         assertEquals(keyInfoSetIn, keyInfoSetOut);
220
221         pfDao.deleteCollection(keyInfoSetIn);
222         keyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyConceptEntity.class));
223         assertEquals(0, keyInfoSetOut.size());
224
225         keyInfoSetIn.add(keyInfo0);
226         keyInfoSetIn.add(keyInfo1);
227         keyInfoSetIn.add(keyInfo0);
228         pfDao.createCollection(keyInfoSetIn);
229         keyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyConceptEntity.class));
230         assertEquals(keyInfoSetIn, keyInfoSetOut);
231
232         pfDao.delete(DummyConceptEntity.class, aKey0);
233         keyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyConceptEntity.class));
234         assertEquals(2, keyInfoSetOut.size());
235         assertEquals(2, pfDao.size(DummyConceptEntity.class));
236
237         final Set<PfConceptKey> keySetIn = new TreeSet<>();
238         keySetIn.add(aKey1);
239         keySetIn.add(aKey2);
240
241         final int deletedCount = pfDao.deleteByConceptKey(DummyConceptEntity.class, keySetIn);
242         assertEquals(2, deletedCount);
243
244         keyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyConceptEntity.class));
245         assertEquals(0, keyInfoSetOut.size());
246
247         keyInfoSetIn.add(keyInfo0);
248         keyInfoSetIn.add(keyInfo1);
249         keyInfoSetIn.add(keyInfo0);
250         pfDao.createCollection(keyInfoSetIn);
251         keyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyConceptEntity.class));
252         assertEquals(keyInfoSetIn, keyInfoSetOut);
253
254         pfDao.deleteAll(DummyConceptEntity.class);
255         assertEquals(0, pfDao.size(DummyConceptEntity.class));
256
257         final PfConceptKey owner0Key = new PfConceptKey("Owner0", VERSION001);
258         final PfConceptKey owner1Key = new PfConceptKey("Owner1", VERSION001);
259         final PfConceptKey owner2Key = new PfConceptKey("Owner2", VERSION001);
260         final PfConceptKey owner3Key = new PfConceptKey("Owner3", VERSION001);
261         final PfConceptKey owner4Key = new PfConceptKey("Owner4", VERSION001);
262         final PfConceptKey owner5Key = new PfConceptKey("Owner5", VERSION001);
263
264         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner0Key, ENTITY0), 100.0));
265         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner0Key, "Entity1"), 101.0));
266         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner0Key, "Entity2"), 102.0));
267         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner0Key, "Entity3"), 103.0));
268         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner0Key, "Entity4"), 104.0));
269         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner1Key, "Entity5"), 105.0));
270         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner1Key, "Entity6"), 106.0));
271         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner1Key, "Entity7"), 107.0));
272         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner2Key, "Entity8"), 108.0));
273         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner2Key, "Entity9"), 109.0));
274         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner3Key, "EntityA"), 110.0));
275         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner4Key, "EntityB"), 111.0));
276         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner5Key, "EntityC"), 112.0));
277         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner5Key, "EntityD"), 113.0));
278         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner5Key, "EntityE"), 114.0));
279         pfDao.create(new DummyReferenceEntity(new PfReferenceKey(owner5Key, "EntityF"), 115.0));
280
281         TreeSet<DummyReferenceEntity> testEntitySetOut =
282                 new TreeSet<>(pfDao.getAll(DummyReferenceEntity.class));
283         assertEquals(16, testEntitySetOut.size());
284
285         testEntitySetOut = new TreeSet<>(pfDao.getAll(DummyReferenceEntity.class, owner0Key));
286         assertEquals(5, testEntitySetOut.size());
287
288         testEntitySetOut = new TreeSet<>(pfDao.getAll(DummyReferenceEntity.class, owner1Key));
289         assertEquals(3, testEntitySetOut.size());
290
291         testEntitySetOut = new TreeSet<>(pfDao.getAll(DummyReferenceEntity.class, owner2Key));
292         assertEquals(2, testEntitySetOut.size());
293
294         testEntitySetOut = new TreeSet<>(pfDao.getAll(DummyReferenceEntity.class, owner3Key));
295         assertEquals(1, testEntitySetOut.size());
296
297         testEntitySetOut = new TreeSet<>(pfDao.getAll(DummyReferenceEntity.class, owner4Key));
298         assertEquals(1, testEntitySetOut.size());
299
300         testEntitySetOut = new TreeSet<>(pfDao.getAll(DummyReferenceEntity.class, owner5Key));
301         assertEquals(4, testEntitySetOut.size());
302
303         assertNotNull(pfDao.get(DummyReferenceEntity.class, new PfReferenceKey(owner0Key, ENTITY0)));
304         assertNotNull(pfDao.getConcept(DummyReferenceEntity.class, new PfReferenceKey(owner0Key, ENTITY0)));
305         assertNull(pfDao.get(DummyReferenceEntity.class, new PfReferenceKey(owner0Key, "Entity1000")));
306         assertNull(pfDao.getConcept(DummyReferenceEntity.class, new PfReferenceKey(owner0Key, "Entity1000")));
307         pfDao.delete(DummyReferenceEntity.class, new PfReferenceKey(owner0Key, ENTITY0));
308
309         final Set<PfReferenceKey> rKeySetIn = new TreeSet<>();
310         rKeySetIn.add(new PfReferenceKey(owner4Key, "EntityB"));
311         rKeySetIn.add(new PfReferenceKey(owner5Key, "EntityD"));
312
313         final int deletedRCount = pfDao.deleteByReferenceKey(DummyReferenceEntity.class, rKeySetIn);
314         assertEquals(2, deletedRCount);
315
316         pfDao.update(new DummyReferenceEntity(new PfReferenceKey(owner5Key, "EntityF"), 120.0));
317
318         final PfTimestampKey atKey0 = new PfTimestampKey("AT-KEY0", VERSION001, TIMESTAMP0);
319         final PfTimestampKey atKey1 = new PfTimestampKey("AT-KEY1", VERSION001, TIMESTAMP1);
320         final PfTimestampKey atKey2 = new PfTimestampKey("AT-KEY2", VERSION001, TIMESTAMP2);
321         final DummyTimestampEntity tkeyInfo0 = new DummyTimestampEntity(atKey0, 200.0);
322         final DummyTimestampEntity tkeyInfo1 = new DummyTimestampEntity(atKey1, 200.1);
323         final DummyTimestampEntity tkeyInfo2 = new DummyTimestampEntity(atKey2, 200.2);
324
325         pfDao.create(tkeyInfo0);
326
327         final DummyTimestampEntity tkeyInfoBack0 = pfDao.get(DummyTimestampEntity.class, atKey0);
328         assertEquals(tkeyInfo0, tkeyInfoBack0);
329
330         final DummyTimestampEntity tkeyInfoBackNull =
331                 pfDao.get(DummyTimestampEntity.class, PfTimestampKey.getNullKey());
332         assertNull(tkeyInfoBackNull);
333
334
335
336         final Set<DummyTimestampEntity> tkeyInfoSetIn = new TreeSet<>();
337         tkeyInfoSetIn.add(tkeyInfo1);
338         tkeyInfoSetIn.add(tkeyInfo2);
339
340         pfDao.createCollection(tkeyInfoSetIn);
341
342         Set<DummyTimestampEntity> tkeyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyTimestampEntity.class));
343
344         tkeyInfoSetIn.add(tkeyInfo0);
345         assertEquals(tkeyInfoSetIn, tkeyInfoSetOut);
346
347         pfDao.delete(tkeyInfo1);
348         tkeyInfoSetIn.remove(tkeyInfo1);
349         tkeyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyTimestampEntity.class));
350         assertEquals(tkeyInfoSetIn, tkeyInfoSetOut);
351
352         pfDao.deleteCollection(tkeyInfoSetIn);
353         tkeyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyTimestampEntity.class));
354         assertEquals(0, tkeyInfoSetOut.size());
355
356         tkeyInfoSetIn.add(tkeyInfo2);
357         pfDao.createCollection(tkeyInfoSetIn);
358         tkeyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyTimestampEntity.class));
359         assertEquals(keyInfoSetIn, keyInfoSetOut);
360
361         pfDao.delete(DummyTimestampEntity.class, atKey2);
362         tkeyInfoSetOut = new TreeSet<>(pfDao.getAll(DummyTimestampEntity.class));
363         assertEquals(3, keyInfoSetOut.size());
364         assertEquals(1, pfDao.size(DummyTimestampEntity.class));
365
366         pfDao.deleteAll(DummyTimestampEntity.class);
367         assertEquals(0, pfDao.size(DummyTimestampEntity.class));
368     }
369
370     private void testVersionOps() {
371         final PfConceptKey aKey0 = new PfConceptKey("AAA0", VERSION001);
372         final PfConceptKey aKey1 = new PfConceptKey("AAA0", VERSION002);
373         final PfConceptKey aKey2 = new PfConceptKey("AAA0", VERSION003);
374         final PfConceptKey bKey0 = new PfConceptKey("BBB0", VERSION001);
375         final PfConceptKey bKey1 = new PfConceptKey("BBB0", VERSION002);
376         final PfConceptKey bKey2 = new PfConceptKey("BBB0", VERSION003);
377         final DummyConceptEntity keyInfo0 = new DummyConceptEntity(aKey0,
378                 UUID.fromString(UUID0), DESCRIPTION0);
379         final DummyConceptEntity keyInfo1 = new DummyConceptEntity(aKey1,
380                 UUID.fromString(UUID1), DESCRIPTION1);
381         final DummyConceptEntity keyInfo2 = new DummyConceptEntity(aKey2,
382                 UUID.fromString(UUID2), DESCRIPTION2);
383         final DummyConceptEntity keyInfo3 = new DummyConceptEntity(bKey0,
384                 UUID.fromString(UUID0), DESCRIPTION0);
385         final DummyConceptEntity keyInfo4 = new DummyConceptEntity(bKey1,
386                 UUID.fromString(UUID1), DESCRIPTION1);
387         final DummyConceptEntity keyInfo5 = new DummyConceptEntity(bKey2,
388                 UUID.fromString(UUID2), DESCRIPTION2);
389
390         pfDao.create(keyInfo0);
391         pfDao.create(keyInfo1);
392         pfDao.create(keyInfo2);
393         pfDao.create(keyInfo3);
394         pfDao.create(keyInfo4);
395         pfDao.create(keyInfo5);
396
397         assertEquals(3, pfDao.getAllVersions(DummyConceptEntity.class, "AAA0").size());
398         assertEquals(0, pfDao.getAllVersions(null, "AAA0").size());
399         assertEquals(0, pfDao.getAllVersions(DummyConceptEntity.class, null).size());
400     }
401
402     private void testgetFilteredOps() {
403         final PfConceptKey aKey0 = new PfConceptKey("AAA0", VERSION001);
404         final PfConceptKey aKey1 = new PfConceptKey("AAA0", VERSION002);
405         final PfConceptKey aKey2 = new PfConceptKey("AAA0", VERSION003);
406         final PfConceptKey bKey0 = new PfConceptKey("BBB0", VERSION001);
407         final PfConceptKey bKey1 = new PfConceptKey("BBB0", VERSION002);
408         final PfConceptKey bKey2 = new PfConceptKey("BBB0", VERSION003);
409         final DummyConceptEntity keyInfo0 = new DummyConceptEntity(aKey0,
410                 UUID.fromString(UUID0), DESCRIPTION0);
411         final DummyConceptEntity keyInfo1 = new DummyConceptEntity(aKey1,
412                 UUID.fromString(UUID1), DESCRIPTION1);
413         final DummyConceptEntity keyInfo2 = new DummyConceptEntity(aKey2,
414                 UUID.fromString(UUID2), DESCRIPTION2);
415         final DummyConceptEntity keyInfo3 = new DummyConceptEntity(bKey0,
416                 UUID.fromString(UUID0), DESCRIPTION0);
417         final DummyConceptEntity keyInfo4 = new DummyConceptEntity(bKey1,
418                 UUID.fromString(UUID1), DESCRIPTION1);
419         final DummyConceptEntity keyInfo5 = new DummyConceptEntity(bKey2,
420                 UUID.fromString(UUID2), DESCRIPTION2);
421
422         pfDao.create(keyInfo0);
423         pfDao.create(keyInfo1);
424         pfDao.create(keyInfo2);
425         pfDao.create(keyInfo3);
426         pfDao.create(keyInfo4);
427         pfDao.create(keyInfo5);
428
429         assertEquals(6, pfDao.getFiltered(DummyConceptEntity.class, null, null).size());
430         assertEquals(3, pfDao.getFiltered(DummyConceptEntity.class, "AAA0", null).size());
431         assertEquals(3, pfDao.getFiltered(DummyConceptEntity.class, "BBB0", null).size());
432         assertEquals(1, pfDao.getFiltered(DummyConceptEntity.class, "BBB0", VERSION003).size());
433         assertEquals(6, pfDao.getFiltered(DummyConceptEntity.class, null, VERSION003).size());
434
435         final PfTimestampKey atKey0 = new PfTimestampKey("AT-KEY0", VERSION001, TIMESTAMP0);
436         final PfTimestampKey atKey1 = new PfTimestampKey("AT-KEY1", VERSION001, TIMESTAMP1);
437         final PfTimestampKey atKey2 = new PfTimestampKey("AT-KEY2", VERSION001, TIMESTAMP2);
438         final DummyTimestampEntity tkeyInfo0 = new DummyTimestampEntity(atKey0, 200.0);
439         final DummyTimestampEntity tkeyInfo1 = new DummyTimestampEntity(atKey1, 200.1);
440         final DummyTimestampEntity tkeyInfo2 = new DummyTimestampEntity(atKey2, 200.2);
441
442         pfDao.create(tkeyInfo0);
443         pfDao.create(tkeyInfo1);
444         pfDao.create(tkeyInfo2);
445
446
447         assertEquals(1, pfDao
448                 .getFiltered(DummyTimestampEntity.class, "AT-KEY0", VERSION001, null, null, null, "DESC", 0).size());
449         assertEquals(1,
450                 pfDao.getFiltered(DummyTimestampEntity.class, "AT-KEY0", null, null, null, null, "DESC", 0).size());
451         assertEquals(3, pfDao
452                 .getFiltered(DummyTimestampEntity.class, null, VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 0)
453                 .size());
454         assertEquals(1, pfDao
455                 .getFiltered(DummyTimestampEntity.class, "AT-KEY0", VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 0)
456                 .size());
457         assertEquals(3, pfDao
458                 .getFiltered(DummyTimestampEntity.class, null, VERSION001, null, TIMESTAMP2, null, "DESC", 0).size());
459         assertEquals(3, pfDao
460                 .getFiltered(DummyTimestampEntity.class, null, VERSION001, TIMESTAMP0, null, null, "DESC", 0).size());
461         assertEquals(2,
462                 pfDao.getFiltered(DummyTimestampEntity.class, null, VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 2)
463                         .size());
464
465         Map<String, Object> filterMap = new HashMap<>();
466         filterMap.put("doubleValue", 200.1);
467         assertEquals(1,
468                 pfDao.getFiltered(DummyTimestampEntity.class, null, null, null, null, filterMap, "DESC", 0).size());
469
470     }
471 }