From 1c9d2d26b1f34567dc6d3e9c51a4fb78c9fc13d4 Mon Sep 17 00:00:00 2001 From: "ning.xi" Date: Wed, 11 Dec 2019 15:55:59 +0800 Subject: pdp statistics database provider implementation Issue-ID: POLICY-1629 Signed-off-by: ning.xi Change-Id: Ife65d50c862ed90c3c9a3cea91a2b9a8d874fa14 --- .../impl/DatabasePolicyModelsProviderTest.java | 87 ++++++++-------------- .../models/provider/impl/DummyBadProviderImpl.java | 36 +++++++-- .../impl/DummyPolicyModelsProviderTest.java | 4 +- 3 files changed, 63 insertions(+), 64 deletions(-) (limited to 'models-provider/src/test') 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 d5c03a2cd..f8a3490cc 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 @@ -29,6 +29,7 @@ import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Base64; +import java.util.Date; import java.util.List; import org.junit.Before; @@ -82,6 +83,8 @@ public class DatabasePolicyModelsProviderTest { private static final String VERSION_100 = "1.0.0"; + private static final Date TIMESTAMP = new Date(); + private static final Logger LOGGER = LoggerFactory.getLogger(DatabasePolicyModelsProviderTest.class); PolicyModelsProviderParameters parameters; @@ -327,66 +330,21 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage(NAME_IS_NULL); assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(null, null, null, null); - }).hasMessage(GROUP_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(null, null, null, new PdpStatistics()); - }).hasMessage(GROUP_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(null, null, INSTANCE, null); - }).hasMessage(GROUP_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(null, null, INSTANCE, new PdpStatistics()); - }).hasMessage(GROUP_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(null, "type", null, null); - }).hasMessage(GROUP_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(null, "type", null, new PdpStatistics()); - }).hasMessage(GROUP_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(null, "type", INSTANCE, null); + databaseProvider.getFilteredPdpStatistics(NAME, null, "sub", TIMESTAMP, TIMESTAMP); }).hasMessage(GROUP_IS_NULL); assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(null, "type", INSTANCE, new PdpStatistics()); - }).hasMessage(GROUP_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(NAME, null, null, null); - }).hasMessage(PDP_TYPE_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(NAME, null, null, new PdpStatistics()); - }).hasMessage(PDP_TYPE_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(NAME, null, INSTANCE, null); - }).hasMessage(PDP_TYPE_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(NAME, null, INSTANCE, new PdpStatistics()); - }).hasMessage(PDP_TYPE_IS_NULL); - - assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(NAME, "type", null, null); - }).hasMessage("pdpInstanceId is marked @NonNull but is null"); + databaseProvider.createPdpStatistics(null); + }).hasMessage("pdpStatisticsList is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(NAME, "type", null, new PdpStatistics()); - }).hasMessage("pdpInstanceId is marked @NonNull but is null"); + databaseProvider.updatePdpStatistics(null); + }).hasMessage("pdpStatisticsList is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.updatePdpStatistics(NAME, "type", INSTANCE, null); - }).hasMessage("pdpStatistics is marked @NonNull but is null"); + databaseProvider.deletePdpStatistics(null, TIMESTAMP); + }).hasMessage(NAME_IS_NULL); - databaseProvider.updatePdpStatistics(NAME, "type", INSTANCE, new PdpStatistics()); } } @@ -512,6 +470,13 @@ public class DatabasePolicyModelsProviderTest { pdpSubGroup.setPdpInstances(new ArrayList<>()); pdpSubGroup.getPdpInstances().add(pdp); + PdpStatistics pdpStatistics = new PdpStatistics(); + pdpStatistics.setPdpInstanceId("Pdp1"); + pdpStatistics.setTimeStamp(new Date()); + pdpStatistics.setPdpGroupName("DefaultGroup"); + ArrayList statisticsArrayList = new ArrayList<>(); + statisticsArrayList.add(pdpStatistics); + assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0) .getDesiredInstanceCount()); assertEquals(1, databaseProvider.getPdpGroups(GROUP).size()); @@ -534,9 +499,23 @@ public class DatabasePolicyModelsProviderTest { assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup(GROUP).getName()); - assertEquals(0, databaseProvider.getPdpStatistics(null).size()); + 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.updatePdpStatistics(GROUP, "type", "type-0", new PdpStatistics()); + databaseProvider.deletePdpStatistics("pdp1",null); } 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 21d13fd83..d809f66ba 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 @@ -21,14 +21,13 @@ package org.onap.policy.models.provider.impl; +import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Map; - import javax.ws.rs.core.Response; - import lombok.NonNull; - import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pdp.concepts.Pdp; @@ -225,13 +224,34 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public List getPdpStatistics(String name) throws PfModelException { - return Collections.emptyList(); + public List getPdpStatistics(final String name, final Date timestamp) throws PfModelException { + return new ArrayList<>(); } @Override - public void updatePdpStatistics(@NonNull String pdpGroupName, @NonNull String pdpType, - @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) { - // do nothing + public List getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup, + Date startTimeStamp, Date endTimeStamp) { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List createPdpStatistics(final List pdpStatisticsList) + throws PfModelException { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List updatePdpStatistics(final List pdpStatisticsList) + throws PfModelException { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List deletePdpStatistics(final String name, final Date timestamp) { + // Not implemented + return null; } } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java index e30cea940..737e0fc28 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java @@ -116,8 +116,8 @@ public class DummyPolicyModelsProviderTest { dummyProvider.updatePdpSubGroup("name", new PdpSubGroup()); dummyProvider.updatePdp("name", "type", new Pdp()); - dummyProvider.updatePdpStatistics("name", "type", "type-0", new PdpStatistics()); - assertTrue(dummyProvider.getPdpStatistics("name").isEmpty()); + dummyProvider.updatePdpStatistics(new ArrayList<>()); + assertTrue(dummyProvider.getPdpStatistics("name", null).isEmpty()); } } -- cgit 1.2.3-korg