aboutsummaryrefslogtreecommitdiffstats
path: root/models-provider
diff options
context:
space:
mode:
authorning.xi <ning.xi@est.tech>2019-12-26 21:37:52 +0800
committerning.xi <ning.xi@est.tech>2020-01-08 11:15:36 +0800
commit86374588a6103114b1f0f335a1b65da1ad0817a5 (patch)
tree5256c00f48e6c145bbf670db64e7dbc9e2dbe14d /models-provider
parentf69b6681486e4d1c5859f649a3293488c1859712 (diff)
update Db provider to support query number
Issue-ID: POLICY-1629 Signed-off-by: ning.xi <ning.xi@est.tech> Change-Id: I42c9542adc44d52b760a70e710ab4cc6fa8a1b3b
Diffstat (limited to 'models-provider')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java6
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java5
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java2
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java58
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java4
5 files changed, 48 insertions, 27 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
index 2e1c71426..767a0fb6f 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -364,11 +364,13 @@ public interface PolicyModelsProvider extends AutoCloseable {
* @param pdpSubGroup pdpSubGroupType name to filter statistics
* @param startTimeStamp startTimeStamp to filter statistics
* @param endTimeStamp endTimeStamp to filter statistics
+ * @param sortOrder sortOrder to query database
+ * @param getRecordNum Total query count from database
* @return the PDP statistics found
* @throws PfModelException on errors getting policies
*/
public List<PdpStatistics> getFilteredPdpStatistics(String name, @NonNull String pdpGroupName, String pdpSubGroup,
- Date startTimeStamp, Date endTimeStamp) throws PfModelException;
+ Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException;
/**
* Creates PDP statistics.
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
index d154910bb..08c01b68f 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
@@ -337,10 +337,11 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
@Override
public List<PdpStatistics> getFilteredPdpStatistics(final String name, @NonNull final String pdpGroupName,
- final String pdpSubGroup, final Date startTimeStamp, final Date endTimeStamp) throws PfModelException {
+ final String pdpSubGroup, final Date startTimeStamp, final Date endTimeStamp, final String sortOrder,
+ final int getRecordNum) throws PfModelException {
assertInitialized();
return new PdpStatisticsProvider().getFilteredPdpStatistics(pfDao, name, pdpGroupName, pdpSubGroup,
- startTimeStamp, endTimeStamp);
+ startTimeStamp, endTimeStamp, sortOrder, getRecordNum);
}
@Override
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
index c0a6e2c2a..3d1c9f61c 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
@@ -236,7 +236,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
@Override
public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup,
- Date startTimeStamp, Date endTimeStamp) {
+ Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) {
// Not implemented
return new ArrayList<>();
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
index 02481ca12..fd566a52f 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
@@ -31,7 +31,6 @@ import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.List;
-
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.models.pdp.concepts.Pdp;
@@ -81,6 +80,8 @@ public class DatabasePolicyModelsProviderTest {
private static final Date TIMESTAMP = new Date();
+ private static final String ORDER = "DESC";
+
private static final Logger LOGGER = LoggerFactory.getLogger(DatabasePolicyModelsProviderTest.class);
PolicyModelsProviderParameters parameters;
@@ -326,7 +327,7 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> {
- databaseProvider.getFilteredPdpStatistics(NAME, null, "sub", TIMESTAMP, TIMESTAMP);
+ databaseProvider.getFilteredPdpStatistics(NAME, null, "sub", TIMESTAMP, TIMESTAMP, ORDER, 0);
}).hasMessageMatching(GROUP_IS_NULL);
assertThatThrownBy(() -> {
@@ -467,9 +468,10 @@ public class DatabasePolicyModelsProviderTest {
pdpSubGroup.getPdpInstances().add(pdp);
PdpStatistics pdpStatistics = new PdpStatistics();
- pdpStatistics.setPdpInstanceId("Pdp1");
+ pdpStatistics.setPdpInstanceId(NAME);
pdpStatistics.setTimeStamp(new Date());
- pdpStatistics.setPdpGroupName("DefaultGroup");
+ pdpStatistics.setPdpGroupName(GROUP);
+ pdpStatistics.setPdpSubGroupName("type");
ArrayList<PdpStatistics> statisticsArrayList = new ArrayList<>();
statisticsArrayList.add(pdpStatistics);
@@ -496,22 +498,38 @@ public class DatabasePolicyModelsProviderTest {
assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup(GROUP).getName());
assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
-
- databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, null);
- databaseProvider.getFilteredPdpStatistics(null, GROUP, null, new Date(), null);
- databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, new Date());
- databaseProvider.getFilteredPdpStatistics(null, GROUP, null, new Date(), new Date());
-
- databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, null, null);
- databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, new Date(), new Date());
-
- databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null);
- databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", new Date(), new Date());
-
- databaseProvider.createPdpStatistics(statisticsArrayList);
- databaseProvider.updatePdpStatistics(statisticsArrayList);
-
- databaseProvider.deletePdpStatistics("pdp1", null);
+ assertEquals(1, databaseProvider.createPdpStatistics(statisticsArrayList).size());
+ assertEquals(1, databaseProvider.updatePdpStatistics(statisticsArrayList).size());
+
+ assertEquals(NAME, databaseProvider.getPdpStatistics(null, null).get(0).getPdpInstanceId());
+ assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, null, ORDER, 0).get(0)
+ .getPdpInstanceId());
+ assertEquals(0,
+ databaseProvider.getFilteredPdpStatistics(null, GROUP, null, new Date(), null, ORDER, 0).size());
+ assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, new Date(), ORDER, 0)
+ .get(0).getPdpInstanceId());
+ assertEquals(0, databaseProvider
+ .getFilteredPdpStatistics(null, GROUP, null, new Date(), new Date(), ORDER, 0).size());
+
+ assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, null, null, ORDER, 0).get(0)
+ .getPdpInstanceId());
+ assertEquals(0, databaseProvider
+ .getFilteredPdpStatistics(NAME, GROUP, null, new Date(), new Date(), ORDER, 0).size());
+
+ assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null, ORDER, 0)
+ .get(0).getPdpInstanceId());
+ assertEquals(0, databaseProvider
+ .getFilteredPdpStatistics(NAME, GROUP, "type", new Date(), new Date(), ORDER, 0).size());
+
+ assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null, ORDER, 1)
+ .get(0).getPdpInstanceId());
+ assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null, ORDER, 5)
+ .get(0).getPdpInstanceId());
+ assertEquals(0, databaseProvider
+ .getFilteredPdpStatistics(NAME, GROUP, "type", new Date(), new Date(), ORDER, 5).size());
+
+ assertEquals(NAME, databaseProvider.deletePdpStatistics(NAME, null).get(0).getPdpInstanceId());
+ assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
} catch (Exception exc) {
LOGGER.warn("test should not throw an exception", exc);
fail("test should not throw an exception");
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
index d809f66ba..73940a6b3 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -230,7 +230,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup,
- Date startTimeStamp, Date endTimeStamp) {
+ Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) {
// Not implemented
return new ArrayList<>();
}