summaryrefslogtreecommitdiffstats
path: root/models-provider/src/test
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2021-06-03 10:37:35 +0100
committeradheli.tavares <adheli.tavares@est.tech>2021-06-03 12:50:14 +0100
commitd72a2ab96255ccc7a9c3a3506eab5509cbcf9ac9 (patch)
treeff63a01bc3ca1bf5c8430b98ed0437c3dafec246 /models-provider/src/test
parent443f9f35fe733fdb88b51ab9c574949f5dd4c03c (diff)
Exposing the Audit provider through Models provider.
Change-Id: I4a3a28b6dbbfbad533a69cf46c545ece7e0b147e Issue-ID: POLICY-2899 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'models-provider/src/test')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java30
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java13
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java2
-rw-r--r--models-provider/src/test/resources/META-INF/persistence.xml1
4 files changed, 46 insertions, 0 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 9e8ba0bbc..4356e4b1d 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
@@ -36,6 +36,9 @@ 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;
@@ -538,6 +541,33 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.close();
}
+ @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(null, 10);
+ assertThat(createdAudits).hasSize(1);
+
+ createdAudits = databaseProvider.getAuditRecords(AuditFilter.builder().build(), 10);
+ assertThat(createdAudits).hasSize(1);
+
+ List<PolicyAudit> emptyList =
+ databaseProvider.getAuditRecords(AuditFilter.builder().action(AuditAction.UNDEPLOYMENT).build(), 10);
+ assertThat(emptyList).isEmpty();
+
+ assertThatThrownBy(() -> databaseProvider.createAuditRecords(null))
+ .hasMessageContaining("audits is marked non-null but is null");
+
+ assertThatThrownBy(() -> databaseProvider.getAuditRecords(null, null))
+ .hasMessageContaining("numRecords is marked non-null but is null");
+
+ databaseProvider.close();
+ }
+
private List<PdpStatistics> makePdpStatisticsList() {
PdpStatistics pdpStatistics = new PdpStatistics();
pdpStatistics.setPdpInstanceId(NAME);
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 4daeaba4c..34cdbff0f 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
@@ -31,6 +31,8 @@ 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.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;
@@ -264,4 +266,15 @@ 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, @NonNull Integer numRecords) {
+ // 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 67a1449f6..de320724a 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
@@ -126,6 +126,8 @@ public class DummyPolicyModelsProviderTest {
assertThat(dummyProvider.getGroupPolicyStatus("name")).isEmpty();
assertThatCode(() -> dummyProvider.cudPolicyStatus(null, null,
null)).doesNotThrowAnyException();
+ assertThatCode(() -> dummyProvider.createAuditRecords(null)).doesNotThrowAnyException();
+ assertThat(dummyProvider.getAuditRecords(null, 10)).isEmpty();
}
@Test
diff --git a/models-provider/src/test/resources/META-INF/persistence.xml b/models-provider/src/test/resources/META-INF/persistence.xml
index 249b29aae..3b4d95656 100644
--- a/models-provider/src/test/resources/META-INF/persistence.xml
+++ b/models-provider/src/test/resources/META-INF/persistence.xml
@@ -27,6 +27,7 @@
<class>org.onap.policy.models.base.PfConceptKey</class>
<class>org.onap.policy.models.dao.converters.CDataConditioner</class>
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
+ <class>org.onap.policy.models.pap.persistence.concepts.JpaPolicyAudit</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpPolicyStatus</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>