summaryrefslogtreecommitdiffstats
path: root/models-dao/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-06-10 17:38:58 -0400
committerJim Hahn <jrh3@att.com>2021-06-14 08:21:04 -0400
commit8cbad257df2d5f5c585ce37e61cfd16e402be738 (patch)
tree18027d19e9c6c231e41e4321d5938c8b0a5d5632 /models-dao/src/test
parent1b460194bc034443ba57fa690d294131836a3e9e (diff)
Fix sonars in policy-models
Fixed: - too many parameters in method call Fixed it by introducing PfFilterParameters. However, classes having the Builder annotation are not easily subclassed, so introduced an interface, too. Issue-ID: POLICY-3094 Change-Id: Ida99522a542b1296b367c55b7e8f8e83783c2e4f Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-dao/src/test')
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java132
1 files changed, 57 insertions, 75 deletions
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
index 59fc9b482..c0b0f2ad0 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.models.dao;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
@@ -598,11 +599,11 @@ public class EntityTest {
pfDao.create(keyInfo4);
pfDao.create(keyInfo5);
- assertEquals(6, pfDao.getFiltered(DummyConceptEntity.class, null, null).size());
- assertEquals(3, pfDao.getFiltered(DummyConceptEntity.class, "AAA0", null).size());
- assertEquals(3, pfDao.getFiltered(DummyConceptEntity.class, "BBB0", null).size());
- assertEquals(1, pfDao.getFiltered(DummyConceptEntity.class, "BBB0", VERSION003).size());
- assertEquals(6, pfDao.getFiltered(DummyConceptEntity.class, null, VERSION003).size());
+ assertThat(pfDao.getFiltered(DummyConceptEntity.class, null, null)).hasSize(6);
+ assertThat(pfDao.getFiltered(DummyConceptEntity.class, "AAA0", null)).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyConceptEntity.class, "BBB0", null)).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyConceptEntity.class, "BBB0", VERSION003)).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyConceptEntity.class, null, VERSION003)).hasSize(6);
final PfTimestampKey atKey0 = new PfTimestampKey("AT-KEY0", VERSION001, TIMESTAMP0);
final PfTimestampKey atKey1 = new PfTimestampKey("AT-KEY1", VERSION001, TIMESTAMP1);
@@ -616,28 +617,25 @@ public class EntityTest {
pfDao.create(tkeyInfo2);
- assertEquals(1, pfDao
- .getFiltered(DummyTimestampEntity.class, "AT-KEY0", VERSION001, null, null, null, "DESC", 0).size());
- assertEquals(1,
- pfDao.getFiltered(DummyTimestampEntity.class, "AT-KEY0", null, null, null, null, "DESC", 0).size());
- assertEquals(3, pfDao
- .getFiltered(DummyTimestampEntity.class, null, VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 0)
- .size());
- assertEquals(1, pfDao
- .getFiltered(DummyTimestampEntity.class, "AT-KEY0", VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 0)
- .size());
- assertEquals(3, pfDao
- .getFiltered(DummyTimestampEntity.class, null, VERSION001, null, TIMESTAMP2, null, "DESC", 0).size());
- assertEquals(3, pfDao
- .getFiltered(DummyTimestampEntity.class, null, VERSION001, TIMESTAMP0, null, null, "DESC", 0).size());
- assertEquals(2,
- pfDao.getFiltered(DummyTimestampEntity.class, null, VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 2)
- .size());
+ assertThat(pfDao.getFiltered(DummyTimestampEntity.class,
+ PfFilterParameters.builder().name("AT-KEY0").version(VERSION001).build())).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyTimestampEntity.class, PfFilterParameters.builder().name("AT-KEY0").build()))
+ .hasSize(1);
+ assertThat(pfDao.getFiltered(DummyTimestampEntity.class, PfFilterParameters.builder().version(VERSION001)
+ .startTime(TIMESTAMP0).endTime(TIMESTAMP2).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyTimestampEntity.class, PfFilterParameters.builder().name("AT-KEY0")
+ .version(VERSION001).startTime(TIMESTAMP0).endTime(TIMESTAMP2).build())).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyTimestampEntity.class,
+ PfFilterParameters.builder().version(VERSION001).endTime(TIMESTAMP2).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyTimestampEntity.class,
+ PfFilterParameters.builder().version(VERSION001).startTime(TIMESTAMP0).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyTimestampEntity.class, PfFilterParameters.builder().version(VERSION001)
+ .startTime(TIMESTAMP0).endTime(TIMESTAMP2).sortOrder("DESC").recordNum(2).build())).hasSize(2);
Map<String, Object> filterMap = new HashMap<>();
filterMap.put("doubleValue", 200.1);
- assertEquals(1,
- pfDao.getFiltered(DummyTimestampEntity.class, null, null, null, null, filterMap, "DESC", 0).size());
+ assertThat(pfDao.getFiltered(DummyTimestampEntity.class,
+ PfFilterParameters.builder().filterMap(filterMap).build())).hasSize(1);
}
private void testgetFilteredOps2() {
@@ -656,29 +654,23 @@ public class EntityTest {
pfDao.create(gkeyInfo2);
- assertEquals(1, pfDao
- .getFiltered(DummyGeneratedIdEntity.class, "AT-KEY0", VERSION001, null, null, null, "DESC", 0).size());
- assertEquals(1,
- pfDao.getFiltered(DummyGeneratedIdEntity.class, "AT-KEY0", null, null, null, null, "DESC", 0).size());
- assertEquals(3, pfDao
- .getFiltered(DummyGeneratedIdEntity.class, null, VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 0)
- .size());
- assertEquals(1, pfDao
- .getFiltered(DummyGeneratedIdEntity.class, "AT-KEY0", VERSION001,
- TIMESTAMP0, TIMESTAMP2, null, "DESC", 0)
- .size());
- assertEquals(3, pfDao
- .getFiltered(DummyGeneratedIdEntity.class, null, VERSION001, null, TIMESTAMP2, null, "DESC", 0).size());
- assertEquals(3, pfDao
- .getFiltered(DummyGeneratedIdEntity.class, null, VERSION001,
- TIMESTAMP0, null, null, "DESC", 0).size());
- assertEquals(2,
- pfDao.getFiltered(DummyGeneratedIdEntity.class, null, VERSION001,
- TIMESTAMP0, TIMESTAMP2, null, "DESC", 2)
- .size());
-
- assertEquals(1,
- pfDao.getFiltered(DummyGeneratedIdEntity.class, null, null, null, null, filterMap, "DESC", 0).size());
+ assertThat(pfDao.getFiltered(DummyGeneratedIdEntity.class,
+ PfFilterParameters.builder().name("AT-KEY0").version(VERSION001).build())).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyGeneratedIdEntity.class,
+ PfFilterParameters.builder().name("AT-KEY0").build())).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyGeneratedIdEntity.class, PfFilterParameters.builder().version(VERSION001)
+ .startTime(TIMESTAMP0).endTime(TIMESTAMP2).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyGeneratedIdEntity.class, PfFilterParameters.builder().name("AT-KEY0")
+ .version(VERSION001).startTime(TIMESTAMP0).endTime(TIMESTAMP2).build())).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyGeneratedIdEntity.class,
+ PfFilterParameters.builder().version(VERSION001).endTime(TIMESTAMP2).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyGeneratedIdEntity.class,
+ PfFilterParameters.builder().version(VERSION001).startTime(TIMESTAMP0).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyGeneratedIdEntity.class, PfFilterParameters.builder().version(VERSION001)
+ .startTime(TIMESTAMP0).endTime(TIMESTAMP2).sortOrder("DESC").recordNum(2).build())).hasSize(2);
+
+ assertThat(pfDao.getFiltered(DummyGeneratedIdEntity.class,
+ PfFilterParameters.builder().filterMap(filterMap).build())).hasSize(1);
}
private void testgetFilteredOps3() {
@@ -700,33 +692,23 @@ public class EntityTest {
pfDao.create(rkeyInfo2);
- assertEquals(1, pfDao
- .getFiltered(DummyReferenceTimestampEntity.class,
- "Owner0", VERSION001, null, null, null, "DESC", 0).size());
- assertEquals(1,
- pfDao.getFiltered(DummyReferenceTimestampEntity.class,
- "Owner0", null, null, null, null, "DESC", 0).size());
- assertEquals(3, pfDao
- .getFiltered(DummyReferenceTimestampEntity.class,
- null, VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 0)
- .size());
- assertEquals(1, pfDao
- .getFiltered(DummyReferenceTimestampEntity.class,
- "Owner0", VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 0)
- .size());
- assertEquals(3, pfDao
- .getFiltered(DummyReferenceTimestampEntity.class, null,
- VERSION001, null, TIMESTAMP2, null, "DESC", 0).size());
- assertEquals(3, pfDao
- .getFiltered(DummyReferenceTimestampEntity.class, null,
- VERSION001, TIMESTAMP0, null, null, "DESC", 0).size());
- assertEquals(2,
- pfDao.getFiltered(DummyReferenceTimestampEntity.class,
- null, VERSION001, TIMESTAMP0, TIMESTAMP2, null, "DESC", 2)
- .size());
-
- assertEquals(1,
- pfDao.getFiltered(DummyReferenceTimestampEntity.class,
- null, null, null, null, filterMap, "DESC", 0).size());
+ assertThat(pfDao.getFiltered(DummyReferenceTimestampEntity.class,
+ PfFilterParameters.builder().name("Owner0").version(VERSION001).build())).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyReferenceTimestampEntity.class,
+ PfFilterParameters.builder().name("Owner0").build())).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyReferenceTimestampEntity.class, PfFilterParameters.builder()
+ .version(VERSION001).startTime(TIMESTAMP0).endTime(TIMESTAMP2).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyReferenceTimestampEntity.class, PfFilterParameters.builder().name("Owner0")
+ .version(VERSION001).startTime(TIMESTAMP0).endTime(TIMESTAMP2).build())).hasSize(1);
+ assertThat(pfDao.getFiltered(DummyReferenceTimestampEntity.class,
+ PfFilterParameters.builder().version(VERSION001).endTime(TIMESTAMP2).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyReferenceTimestampEntity.class,
+ PfFilterParameters.builder().version(VERSION001).startTime(TIMESTAMP0).build())).hasSize(3);
+ assertThat(pfDao.getFiltered(DummyReferenceTimestampEntity.class,
+ PfFilterParameters.builder().version(VERSION001).startTime(TIMESTAMP0).endTime(TIMESTAMP2)
+ .sortOrder("DESC").recordNum(2).build())).hasSize(2);
+
+ assertThat(pfDao.getFiltered(DummyReferenceTimestampEntity.class,
+ PfFilterParameters.builder().filterMap(filterMap).build())).hasSize(1);
}
}