aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-audit/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'integrity-audit/src/test/java')
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java5
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java15
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java25
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java4
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java12
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java27
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java30
7 files changed, 55 insertions, 63 deletions
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java
index 99cf4b2a..ad154d33 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.
@@ -30,12 +30,10 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.common.ia.jpa.IaTestEntity;
import org.onap.policy.common.ia.jpa.IntegrityAuditEntity;
@@ -419,7 +417,6 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
/*
* Tests that comparison algorithm works for each entity in the database
*/
- @Ignore
@Test
public void testCompareAllDbEntities() throws Exception {
logger.info("testCompareAllDbEntities: Entering");
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java
index 220b0635..c48ec0e3 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java
@@ -2,7 +2,8 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,13 +25,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import com.google.re2j.Pattern;
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.EntityManagerFactory;
+import jakarta.persistence.Persistence;
import java.util.List;
import java.util.Properties;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -53,6 +53,7 @@ public class DbAuditTest extends IntegrityAuditTestBase {
private static Logger logger = FlexLogger.getLogger(DbAuditTest.class);
+ private static final Pattern COMMA_PAT = Pattern.compile(",");
private static final String RESOURCE_NAME = "pdp1";
private EntityManagerFactory emf2;
@@ -240,7 +241,7 @@ public class DbAuditTest extends IntegrityAuditTestBase {
assertFalse(dbglog.getExtracted().isEmpty());
String mismatchIndex = dbglog.getExtracted().get(dbglog.getExtracted().size() - 1);
- int mismatchEntries = mismatchIndex.trim().split(",").length;
+ int mismatchEntries = COMMA_PAT.split(mismatchIndex.trim()).length;
logger.info("mismatchTest: mismatchIndex found: '" + mismatchIndex + "'" + " mismatachEntries = "
+ mismatchEntries);
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java
index ef21e831..9f2103d7 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java
@@ -2,7 +2,8 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,26 +26,18 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-/*
- * All JUnits are designed to run in the local development environment
- * where they have write privileges and can execute time-sensitive
- * tasks.
- */
-
+import jakarta.persistence.PersistenceUnitUtil;
+import jakarta.persistence.Query;
+import jakarta.persistence.TypedQuery;
+import jakarta.persistence.criteria.CriteriaBuilder;
+import jakarta.persistence.criteria.CriteriaQuery;
+import jakarta.persistence.criteria.Root;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
-import javax.persistence.PersistenceUnitUtil;
-import javax.persistence.Query;
-import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
-
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -65,7 +58,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
private static final String SITE_B = "SiteB";
private static final String ENTITY_CLASS_NAME = "org.onap.policy.common.ia.jpa.IntegrityAuditEntity";
- private static String resourceName = "pdp0";
+ private static final String resourceName = "pdp0";
private DbDao dbDao;
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
index 959a4e7c..5944443e 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -24,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
-
import org.junit.AfterClass;
import org.junit.Test;
import org.onap.policy.common.utils.resources.TextFileUtils;
@@ -95,7 +95,7 @@ public class DefaultLoggingPatternTest {
TextFileUtils.getTextFileAsString("testingLogs/common-modules/integrity-audit/logging-pattern-test.log")
.substring(23);
String expectedLoggedString = TextFileUtils
- .getTextFileAsString("src/test/resources/" + loggerString + "-test.expectedlog").substring(23);
+ .getTextFileAsString("src/test/resources/" + loggerString + "-test.expectedlog").substring(23).trim();
assertThat(actualLoggedString).contains(expectedLoggedString);
}
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java
index c9ff6854..9550017e 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.
@@ -21,10 +21,10 @@
package org.onap.policy.common.ia;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import java.util.Properties;
-
import org.junit.Test;
public class IntegrityAuditTest {
@@ -41,7 +41,7 @@ public class IntegrityAuditTest {
StringBuilder badParams = new StringBuilder();
IntegrityAudit.parmsAreBad(null, SOMETHING, null, badParams);
- assertFalse("".equals(badParams.toString()));
+ assertNotEquals("", badParams.toString());
assertTrue(badParams.toString().contains(RESOURCE_NAME));
assertTrue(badParams.toString().contains(PROPERTIES));
@@ -51,14 +51,14 @@ public class IntegrityAuditTest {
props.put(IntegrityAuditProperties.DB_DRIVER, "test_db_driver");
IntegrityAudit.parmsAreBad(null, SOMETHING, props, badParams);
- assertFalse("".equals(badParams.toString()));
+ assertNotEquals("", badParams.toString());
assertTrue(badParams.toString().contains(RESOURCE_NAME));
assertFalse(badParams.toString().contains(PROPERTIES));
// Try with 0 null params
badParams = new StringBuilder();
IntegrityAudit.parmsAreBad("someting", SOMETHING, props, badParams);
- assertFalse("".equals(badParams.toString()));
+ assertNotEquals("", badParams.toString());
assertFalse(badParams.toString().contains(RESOURCE_NAME));
assertFalse(badParams.toString().contains(PROPERTIES));
@@ -66,7 +66,7 @@ public class IntegrityAuditTest {
props.put(IntegrityAuditProperties.NODE_TYPE, "bogus");
badParams = new StringBuilder();
IntegrityAudit.parmsAreBad("someting", SOMETHING, props, badParams);
- assertFalse("".equals(badParams.toString()));
+ assertNotEquals("", badParams.toString());
assertTrue(badParams.toString().contains("nodeType"));
}
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java
index 1866bba0..f5a32777 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java
@@ -2,7 +2,8 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +26,10 @@ import static org.junit.Assert.fail;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.EntityManagerFactory;
+import jakarta.persistence.EntityTransaction;
+import jakarta.persistence.Persistence;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -36,18 +41,14 @@ import java.util.Properties;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
import org.onap.policy.common.utils.jpa.EntityMgrCloser;
import org.onap.policy.common.utils.jpa.EntityMgrFactoryCloser;
import org.onap.policy.common.utils.jpa.EntityTransCloser;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.onap.policy.common.utils.time.CurrentTime;
import org.onap.policy.common.utils.time.TestTime;
-import org.powermock.reflect.Whitebox;
import org.slf4j.LoggerFactory;
+import org.springframework.test.util.ReflectionTestUtils;
/**
* All JUnits are designed to run in the local development environment where they have write
@@ -177,6 +178,7 @@ public class IntegrityAuditTestBase {
* @param dbUrl the URL to the DB
* @throws IOException if an IO error occurs
*/
+ @SuppressWarnings("unchecked")
protected static void setUpBeforeClass(String dbUrl) throws IOException {
// truncate the logs
@@ -188,7 +190,7 @@ public class IntegrityAuditTestBase {
IntegrityAuditTestBase.dbUrl = dbUrl;
// save data that we have to restore at the end of the test
- savedTime = Whitebox.getInternalState(AuditorTime.class, TIME_SUPPLY_FIELD);
+ savedTime = (Supplier<CurrentTime>) ReflectionTestUtils.getField(AuditorTime.class, TIME_SUPPLY_FIELD);
savedDebugLevel = debugLogger.getLevel();
savedErrorLevel = errorLogger.getLevel();
@@ -208,7 +210,7 @@ public class IntegrityAuditTestBase {
// done
em = emf.createEntityManager();
- Whitebox.setInternalState(AuditorTime.class, TIME_SUPPLY_FIELD, timeSupplier);
+ ReflectionTestUtils.setField(AuditorTime.class, TIME_SUPPLY_FIELD, timeSupplier);
debugLogger.setLevel(Level.DEBUG);
errorLogger.setLevel(Level.ERROR);
}
@@ -220,7 +222,7 @@ public class IntegrityAuditTestBase {
IntegrityAudit.setUnitTesting(false);
- Whitebox.setInternalState(AuditorTime.class, TIME_SUPPLY_FIELD, savedTime);
+ ReflectionTestUtils.setField(AuditorTime.class, TIME_SUPPLY_FIELD, savedTime);
debugLogger.setLevel(savedDebugLevel);
errorLogger.setLevel(savedErrorLevel);
@@ -243,7 +245,7 @@ public class IntegrityAuditTestBase {
// Clean up the DB
try (EntityTransCloser etc = new EntityTransCloser(em.getTransaction())) {
- EntityTransaction et = etc.getTransation();
+ EntityTransaction et = etc.getTransaction();
em.createQuery("Delete from IntegrityAuditEntity").executeUpdate();
@@ -290,7 +292,7 @@ public class IntegrityAuditTestBase {
EntityTransCloser etc = new EntityTransCloser(emc.getManager().getTransaction())) {
EntityManager entmgr = emc.getManager();
- EntityTransaction entrans = etc.getTransation();
+ EntityTransaction entrans = etc.getTransaction();
// Clean up the DB
entmgr.createQuery("Delete from " + tableName).executeUpdate();
@@ -304,8 +306,7 @@ public class IntegrityAuditTestBase {
* Verifies that items appear within the log, in order. A given item may appear more than once.
* In addition, the log may contain extra items; those are ignored.
*
- * @param textre regular expression used to extract an item from a line in the log. The first
- * "capture" group of the regular expression is assumed to contain the extracted item
+ * @param app where data has been logged
* @param items items that should be matched by the items extracted from the log, in order
* @throws IOException if an IO error occurs
* @throws AssertionError if the desired items were not all found
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java
index 4a4824c5..8a34909a 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java
@@ -2,7 +2,8 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021, 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,26 +21,25 @@
package org.onap.policy.common.ia.jpa;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.NamedQueries;
+import jakarta.persistence.NamedQuery;
+import jakarta.persistence.PrePersist;
+import jakarta.persistence.PreUpdate;
+import jakarta.persistence.Table;
+import jakarta.persistence.Temporal;
+import jakarta.persistence.TemporalType;
import java.io.Serializable;
import java.util.Date;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.PrePersist;
-import javax.persistence.PreUpdate;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-
@Entity
@Table(name = "IaTestEntity")
@NamedQueries({@NamedQuery(name = " IaTestEntity.findAll", query = "SELECT e FROM IaTestEntity e "),
- @NamedQuery(name = "IaTestEntity.deleteAll", query = "DELETE FROM IaTestEntity WHERE 1=1")})
+ @NamedQuery(name = "IaTestEntity.deleteAll", query = "DELETE FROM IaTestEntity WHERE 1=1")})
public class IaTestEntity implements Serializable {
private static final long serialVersionUID = 1L;