summaryrefslogtreecommitdiffstats
path: root/models-provider/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'models-provider/src/test')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java120
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java45
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java44
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java18
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyStatisticsPersistenceTest.java87
5 files changed, 4 insertions, 310 deletions
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 561ef5daa..ff3dae81a 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020, 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,14 +22,11 @@
package org.onap.policy.models.provider.impl;
-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;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -37,22 +34,16 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.pap.concepts.PolicyAudit;
-import org.onap.policy.models.pap.concepts.PolicyAudit.AuditAction;
-import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
-import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpState;
-import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
@@ -84,10 +75,6 @@ public class DatabasePolicyModelsProviderTest {
private static final String VERSION_100 = "1.0.0";
- private static final Instant TIMESTAMP = Instant.EPOCH;
-
- private static final String ORDER = "DESC";
-
private PolicyModelsProviderParameters parameters;
private PolicyModelsProvider databaseProvider;
@@ -282,18 +269,6 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.deletePdpGroup(null);
}).hasMessageMatching(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createPdpStatistics(null);
- }).hasMessageMatching("^pdpStatisticsList is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null);
- }).hasMessageMatching("^pdpStatisticsList is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
- databaseProvider.deletePdpStatistics(null, TIMESTAMP);
- }).hasMessageMatching(NAME_IS_NULL);
-
databaseProvider.close();
}
@@ -413,68 +388,6 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("delete of PDP group \"name:0.0.0\" failed, PDP group does not exist");
assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup(GROUP).getName());
-
- List<PdpStatistics> statisticsArrayList = makePdpStatisticsList();
-
- assertThat(databaseProvider.getFilteredPdpStatistics(PdpFilterParameters.builder().build())).isEmpty();
- assertThat(databaseProvider.createPdpStatistics(statisticsArrayList)).hasSize(1);
- assertThat(databaseProvider.updatePdpStatistics(statisticsArrayList)).hasSize(1);
- }
-
- @Test
- public void testProviderMethodsStatistics() throws PfModelException {
- databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
- databaseProvider.createPdpStatistics(makePdpStatisticsList());
-
- assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(PdpFilterParameters.builder().build()).get(0)
- .getPdpInstanceId());
- assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().group(GROUP).build()).get(0).getPdpInstanceId());
- assertEquals(0, databaseProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().group(GROUP).startTime(Instant.now()).build()).size());
- assertEquals(NAME, databaseProvider
- .getFilteredPdpStatistics(PdpFilterParameters.builder().group(GROUP).endTime(TIMESTAMP).build())
- .get(0).getPdpInstanceId());
- assertEquals(0, databaseProvider.getFilteredPdpStatistics(PdpFilterParameters.builder().group(GROUP)
- .startTime(Instant.now()).endTime(Instant.now()).build()).size());
-
- assertEquals(NAME, databaseProvider
- .getFilteredPdpStatistics(PdpFilterParameters.builder().name(NAME).group(GROUP).build()).get(0)
- .getPdpInstanceId());
- assertEquals(0, databaseProvider.getFilteredPdpStatistics(PdpFilterParameters.builder().name(NAME).group(GROUP)
- .startTime(Instant.now()).endTime(Instant.now()).build()).size());
-
- assertEquals(NAME,
- databaseProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type").build())
- .get(0).getPdpInstanceId());
-
- assertEquals(0, databaseProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type")
- .startTime(Instant.now()).endTime(Instant.now()).build()).size());
-
- assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type")
- .sortOrder(ORDER).recordNum(1).build()).get(0).getPdpInstanceId());
- assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type")
- .sortOrder(ORDER).recordNum(5).build()).get(0).getPdpInstanceId());
- assertEquals(0, databaseProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type")
- .startTime(Instant.now()).endTime(Instant.now())
- .sortOrder(ORDER).recordNum(5).build()).size());
-
- assertEquals(NAME, databaseProvider.deletePdpStatistics(NAME, null).get(0).getPdpInstanceId());
- assertThat(databaseProvider.getFilteredPdpStatistics(PdpFilterParameters.builder().build())).isEmpty();
-
- assertThat(databaseProvider.getAllPolicyStatus()).isEmpty();
- assertThat(databaseProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy", null)))
- .isEmpty();
- assertThat(databaseProvider.getGroupPolicyStatus(GROUP)).isEmpty();
- assertThatCode(() -> databaseProvider.cudPolicyStatus(null, null, null))
- .doesNotThrowAnyException();
-
- databaseProvider.close();
}
@Test
@@ -551,27 +464,6 @@ public class DatabasePolicyModelsProviderTest {
}
@Test
- public void testCreateAuditRecords() throws PfModelException {
- PolicyAudit audit = PolicyAudit.builder().action(AuditAction.DEPLOYMENT).pdpGroup(GROUP).pdpType(GROUP)
- .policy(new ToscaConceptIdentifier(NAME, VERSION_100)).user("user").build();
-
- databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
-
- databaseProvider.createAuditRecords(List.of(audit));
- List<PolicyAudit> createdAudits = databaseProvider.getAuditRecords(AuditFilter.builder().recordNum(10).build());
- assertThat(createdAudits).hasSize(1);
-
- List<PolicyAudit> emptyList = databaseProvider
- .getAuditRecords(AuditFilter.builder().action(AuditAction.UNDEPLOYMENT).recordNum(10).build());
- assertThat(emptyList).isEmpty();
-
- assertThatThrownBy(() -> databaseProvider.createAuditRecords(null))
- .hasMessageContaining("audits is marked non-null but is null");
-
- databaseProvider.close();
- }
-
- @Test
public void testToscaNodeTemplateHandling() throws PfModelException {
databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
@@ -596,16 +488,6 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.close();
}
- private List<PdpStatistics> makePdpStatisticsList() {
- PdpStatistics pdpStatistics = new PdpStatistics();
- pdpStatistics.setPdpInstanceId(NAME);
- pdpStatistics.setTimeStamp(TIMESTAMP);
- pdpStatistics.setPdpGroupName(GROUP);
- pdpStatistics.setPdpSubGroupName("type");
- List<PdpStatistics> statisticsArrayList = List.of(pdpStatistics);
- return statisticsArrayList;
- }
-
private ToscaServiceTemplate makeNodeTemplate() {
ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
serviceTemplate.setToscaDefinitionsVersion("sample:1.1.0");
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 410ecf26a..84331e905 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020, 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +22,6 @@
package org.onap.policy.models.provider.impl;
-import java.time.Instant;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -33,15 +31,11 @@ import lombok.NonNull;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.pap.concepts.PolicyAudit;
-import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
-import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
@@ -242,32 +236,6 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException {
- // Not implemented
- return null;
- }
-
- @Override
- public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
- throws PfModelException {
- // Not implemented
- return new ArrayList<>();
- }
-
- @Override
- public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
- throws PfModelException {
- // Not implemented
- return new ArrayList<>();
- }
-
- @Override
- public List<PdpStatistics> deletePdpStatistics(final String name, final Instant timestamp) {
- // Not implemented
- return null;
- }
-
- @Override
public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
// Not implemented
return null;
@@ -297,15 +265,4 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
// Not implemented
return null;
}
-
- @Override
- public void createAuditRecords(List<PolicyAudit> auditRecords) {
- // Not implemented
- }
-
- @Override
- public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter) {
- // Not implemented
- return null;
- }
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
index dcc436a05..4b8f1b866 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2022 Nordix Foundation.
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020, 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
package org.onap.policy.models.provider.impl;
-import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -34,15 +33,11 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.pap.concepts.PolicyAudit;
-import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
-import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
@@ -250,32 +245,6 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException {
- // Not implemented
- return new ArrayList<>();
- }
-
- @Override
- public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
- throws PfModelException {
- // Not implemented
- return new ArrayList<>();
- }
-
- @Override
- public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
- throws PfModelException {
- // Not implemented
- return new ArrayList<>();
- }
-
- @Override
- public List<PdpStatistics> deletePdpStatistics(final String name, final Instant timestamp) {
- // Not implemented
- return new ArrayList<>();
- }
-
- @Override
public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
// Not implemented
return new ArrayList<>();
@@ -300,17 +269,6 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
// Not implemented
}
- @Override
- public void createAuditRecords(List<PolicyAudit> auditRecords) {
- // Not implemented
- }
-
- @Override
- public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter) {
- // Not implemented
- return new ArrayList<>();
- }
-
/**
* Return a ToscaServicetemplate dummy response.
*
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 ca4c2e573..628aef96e 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020, 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,15 +30,12 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.time.Instant;
import java.util.ArrayList;
import org.junit.Test;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
@@ -112,17 +109,6 @@ public class DummyPolicyModelsProviderTest {
dummyProvider.updatePdpSubGroup("name", new PdpSubGroup());
dummyProvider.updatePdp("name", "type", new Pdp());
- dummyProvider.updatePdpStatistics(new ArrayList<>());
- assertThat(dummyProvider.getFilteredPdpStatistics(PdpFilterParameters.builder().name("name").build()))
- .isEmpty();
-
- assertTrue(
- dummyProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().name("name")
- .startTime(Instant.now()).endTime(Instant.now()).build()).isEmpty());
- assertTrue(dummyProvider.createPdpStatistics(null).isEmpty());
- assertTrue(dummyProvider.updatePdpStatistics(null).isEmpty());
- assertTrue(dummyProvider.deletePdpStatistics(null, Instant.now()).isEmpty());
assertThat(dummyProvider.getAllPolicyStatus()).isEmpty();
assertThat(dummyProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy",
@@ -130,8 +116,6 @@ public class DummyPolicyModelsProviderTest {
assertThat(dummyProvider.getGroupPolicyStatus("name")).isEmpty();
assertThatCode(() -> dummyProvider.cudPolicyStatus(null, null,
null)).doesNotThrowAnyException();
- assertThatCode(() -> dummyProvider.createAuditRecords(null)).doesNotThrowAnyException();
- assertThat(dummyProvider.getAuditRecords(AuditFilter.builder().recordNum(10).build())).isEmpty();
}
@Test
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyStatisticsPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyStatisticsPersistenceTest.java
deleted file mode 100644
index abc08846a..000000000
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyStatisticsPersistenceTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.provider.impl;
-
-import static org.assertj.core.api.Assertions.assertThatCode;
-
-import java.time.Instant;
-import java.util.Arrays;
-import org.junit.Test;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.pdp.concepts.PdpStatistics;
-import org.onap.policy.models.provider.PolicyModelsProvider;
-import org.onap.policy.models.provider.PolicyModelsProviderFactory;
-import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-
-/**
- * Test persistence of PDP statistics to and from the database.
- */
-public class PolicyStatisticsPersistenceTest {
-
- @Test
- public void testPdpStatiscticsPersistence() throws PfModelException {
- // Try the test on three providers
- for (int i = 0; i < 3; i++) {
- try (PolicyModelsProvider databaseProvider = setupProvider()) {
- testPdpStatiscticsPersistenceOneProvider(databaseProvider);
- }
- }
- }
-
- public void testPdpStatiscticsPersistenceOneProvider(PolicyModelsProvider databaseProvider) {
- PdpStatistics pdpStatistics = new PdpStatistics();
- pdpStatistics.setPdpInstanceId("TheInstance");
- pdpStatistics.setTimeStamp(Instant.now());
-
- // Try creating three identical statistics instances
- for (int i = 0; i < 3; i++) {
- assertThatCode(() -> databaseProvider.createPdpStatistics(Arrays.asList(pdpStatistics)))
- .doesNotThrowAnyException();
- }
-
- // Try creating three statistics instances with timestams incremented
- for (int i = 0; i < 3; i++) {
- pdpStatistics.setTimeStamp(pdpStatistics.getTimeStamp().plusSeconds(1));
-
- assertThatCode(() -> databaseProvider.createPdpStatistics(Arrays.asList(pdpStatistics)))
- .doesNotThrowAnyException();
- }
- }
-
- private PolicyModelsProvider setupProvider() throws PfModelException {
- PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
-
- if (System.getProperty("USE-MARIADB") != null) {
- parameters.setDatabaseDriver("org.mariadb.jdbc.Driver");
- parameters.setDatabaseUrl("jdbc:mariadb://localhost:3306/policy");
- } else {
- parameters.setDatabaseDriver("org.h2.Driver");
- parameters.setDatabaseUrl("jdbc:h2:mem:PolicyStatisticsPersistenceTest");
- }
-
- parameters.setDatabaseUser("policy");
- parameters.setDatabasePassword("P01icY");
- parameters.setPersistenceUnit("ToscaConceptTest");
-
- return new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
- }
-}