mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-21 05:53:27 +00:00
Fixed up compiling
This commit is contained in:
parent
5ec4d8e415
commit
3f1a140946
@ -1,14 +1,16 @@
|
||||
package hirs.data.persist;
|
||||
package hirs.attestationca.data.persist;
|
||||
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.data.persist.enums.HealthStatus;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import hirs.persist.ScheduledJobInfo;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static hirs.data.persist.DeviceGroup.DEFAULT_REPORT_DELAY_THRESHOLD;
|
||||
import static hirs.data.persist.DeviceGroup.MINIMUM_THRESHOLD_INTERVAL_MS;
|
||||
|
@ -0,0 +1,339 @@
|
||||
package hirs.attestationca.data.persist;
|
||||
|
||||
import hirs.attestationca.persist.SpringPersistenceTest;
|
||||
import hirs.attestationca.servicemanager.DBReportManager;
|
||||
import hirs.data.persist.DeviceInfoReport;
|
||||
import hirs.data.persist.info.FirmwareInfo;
|
||||
import hirs.data.persist.info.HardwareInfo;
|
||||
import hirs.data.persist.info.NetworkInfo;
|
||||
import hirs.data.persist.info.OSInfo;
|
||||
import hirs.data.persist.info.TPMInfo;
|
||||
import hirs.foss.XMLCleaner;
|
||||
import hirs.persist.ReportManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* DeviceInfoReportTest is a unit test class for DeviceInfoReports.
|
||||
*/
|
||||
public class DeviceInfoReportTest extends SpringPersistenceTest {
|
||||
private final NetworkInfo networkInfo = createTestNetworkInfo();
|
||||
private final OSInfo osInfo = createTestOSInfo();
|
||||
private final FirmwareInfo firmwareInfo = createTestFirmwareInfo();
|
||||
private final HardwareInfo hardwareInfo = createTestHardwareInfo();
|
||||
private final TPMInfo tpmInfo = createTPMInfo();
|
||||
private static final String TEST_IDENTITY_CERT = "/tpm/sample_identity_cert.cer";
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DeviceInfoReportTest.class);
|
||||
|
||||
private static final String EXPECTED_CLIENT_VERSION = "Test.Version";
|
||||
|
||||
private ReportManager reportManager;
|
||||
|
||||
/**
|
||||
* Initializes a <code>SessionFactory</code>. The factory is used for an
|
||||
* in-memory database that is used for testing.
|
||||
*/
|
||||
@BeforeClass
|
||||
public final void setup() {
|
||||
LOGGER.debug("retrieving session factory");
|
||||
reportManager = new DBReportManager(sessionFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the <code>SessionFactory</code> from setup.
|
||||
*/
|
||||
@AfterClass
|
||||
public final void tearDown() {
|
||||
LOGGER.debug("closing session factory");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests instantiation of a DeviceInfoReport.
|
||||
*/
|
||||
@Test
|
||||
public final void deviceInfoReport() {
|
||||
new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that NetworkInfo cannot be null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public final void networkInfoNull() {
|
||||
new DeviceInfoReport(null, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that OSInfo cannot be null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public final void osInfoNull() {
|
||||
new DeviceInfoReport(networkInfo, null, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that FirmwareInfo cannot be null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public final void firmwareInfoNull() {
|
||||
new DeviceInfoReport(networkInfo, osInfo, null, hardwareInfo, tpmInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that HardwareInfo cannot be null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public final void hardwareInfoNull() {
|
||||
new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, null, tpmInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that TPMInfo may be null.
|
||||
*/
|
||||
@Test
|
||||
public final void tpmInfoNull() {
|
||||
new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, hardwareInfo, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the getters for DeviceInfoReport work as expected.
|
||||
*/
|
||||
@Test
|
||||
public final void testGetters() {
|
||||
DeviceInfoReport deviceInfoReport =
|
||||
new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getNetworkInfo(), networkInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getOSInfo(), osInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getFirmwareInfo(), firmwareInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getHardwareInfo(), hardwareInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getTPMInfo(), tpmInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getClientApplicationVersion(),
|
||||
EXPECTED_CLIENT_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the XML is generated correctly.
|
||||
*
|
||||
* @throws JAXBException
|
||||
* in case there are errors marshalling/unmarshalling
|
||||
*/
|
||||
@Test
|
||||
public final void marshalUnmarshalTest() throws JAXBException {
|
||||
DeviceInfoReport deviceInfoReport =
|
||||
new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
String xml = getXMLFromReport(deviceInfoReport);
|
||||
DeviceInfoReport deviceInfoReportFromXML = getReportFromXML(xml);
|
||||
Assert.assertEquals(deviceInfoReportFromXML.getNetworkInfo(), networkInfo);
|
||||
Assert.assertEquals(deviceInfoReportFromXML.getOSInfo(), osInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getFirmwareInfo(), firmwareInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getHardwareInfo(), hardwareInfo);
|
||||
Assert.assertEquals(deviceInfoReportFromXML.getTPMInfo(), tpmInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getClientApplicationVersion(),
|
||||
EXPECTED_CLIENT_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a <code>DeviceInfoReport</code> can be saved in the
|
||||
* <code>ReportManager</code>.
|
||||
*/
|
||||
@Test
|
||||
public final void testSaveReport() {
|
||||
final DeviceInfoReport deviceInfoReport = new DeviceInfoReport(
|
||||
networkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
final DeviceInfoReport savedReport = (DeviceInfoReport) reportManager
|
||||
.saveReport(deviceInfoReport);
|
||||
Assert.assertEquals(savedReport.getNetworkInfo(), networkInfo);
|
||||
Assert.assertEquals(savedReport.getOSInfo(), osInfo);
|
||||
Assert.assertEquals(savedReport.getFirmwareInfo(), firmwareInfo);
|
||||
Assert.assertEquals(savedReport.getHardwareInfo(), hardwareInfo);
|
||||
Assert.assertEquals(savedReport.getTPMInfo(), tpmInfo);
|
||||
Assert.assertEquals(deviceInfoReport.getClientApplicationVersion(),
|
||||
EXPECTED_CLIENT_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a <code>DeviceInfoReport</code> can be saved in the
|
||||
* <code>ReportManager</code> and then retrieved.
|
||||
*/
|
||||
@Test
|
||||
public final void testGetReport() {
|
||||
final DeviceInfoReport deviceInfoReport =
|
||||
new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
final DeviceInfoReport savedReport =
|
||||
(DeviceInfoReport) reportManager.saveReport(deviceInfoReport);
|
||||
final DeviceInfoReport getReport =
|
||||
(DeviceInfoReport) reportManager.getReport(savedReport.getId());
|
||||
Assert.assertEquals(getReport.getNetworkInfo(), networkInfo);
|
||||
Assert.assertEquals(getReport.getOSInfo(), osInfo);
|
||||
Assert.assertEquals(getReport.getFirmwareInfo(), firmwareInfo);
|
||||
Assert.assertEquals(getReport.getHardwareInfo(), hardwareInfo);
|
||||
Assert.assertEquals(getReport.getTPMInfo(), tpmInfo);
|
||||
Assert.assertEquals(getReport.getClientApplicationVersion(),
|
||||
EXPECTED_CLIENT_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a <code>DeviceInfoReport</code> can be saved in the
|
||||
* <code>ReportManager</code> and then deleted.
|
||||
*/
|
||||
@Test
|
||||
public final void testDeleteReport() {
|
||||
final DeviceInfoReport deviceInfoReport =
|
||||
new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
final DeviceInfoReport savedReport =
|
||||
(DeviceInfoReport) reportManager.saveReport(deviceInfoReport);
|
||||
Assert.assertNotNull(savedReport);
|
||||
final UUID id = savedReport.getId();
|
||||
Assert.assertNotNull(reportManager.getReport(id));
|
||||
Assert.assertTrue(reportManager.deleteReport(id));
|
||||
Assert.assertNull(reportManager.getReport(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DeviceInfoReport instance usable for testing.
|
||||
*
|
||||
* @return a test DeviceInfoReport
|
||||
*/
|
||||
public static DeviceInfoReport getTestReport() {
|
||||
return new DeviceInfoReport(
|
||||
createTestNetworkInfo(), createTestOSInfo(), createTestFirmwareInfo(),
|
||||
createTestHardwareInfo(), createTPMInfo()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of NetworkInfo.
|
||||
*
|
||||
* @return network information for a fake device
|
||||
*/
|
||||
public static NetworkInfo createTestNetworkInfo() {
|
||||
try {
|
||||
final String hostname = "test.hostname";
|
||||
final InetAddress ipAddress =
|
||||
InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
|
||||
final byte[] macAddress = new byte[] {11, 22, 33, 44, 55, 66};
|
||||
return new NetworkInfo(hostname, ipAddress, macAddress);
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
LOGGER.error("error occurred while creating InetAddress");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of OSInfo.
|
||||
*
|
||||
* @return OS information for a fake device
|
||||
*/
|
||||
public static OSInfo createTestOSInfo() {
|
||||
return new OSInfo("test os name", "test os version", "test os arch",
|
||||
"test distribution", "test distribution release");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of FirmwareInfo.
|
||||
*
|
||||
* @return Firmware information for a fake device
|
||||
*/
|
||||
public static FirmwareInfo createTestFirmwareInfo() {
|
||||
return new FirmwareInfo("test bios vendor", "test bios version", "test bios release date");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of HardwareInfo.
|
||||
*
|
||||
* @return Hardware information for a fake device
|
||||
*/
|
||||
public static HardwareInfo createTestHardwareInfo() {
|
||||
return new HardwareInfo("test manufacturer", "test product name", "test version",
|
||||
"test really long serial number with many characters", "test really long chassis "
|
||||
+ "serial number with many characters",
|
||||
"test really long baseboard serial number with many characters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of TPMInfo.
|
||||
*
|
||||
* @return TPM information for a fake device
|
||||
*/
|
||||
public static final TPMInfo createTPMInfo() {
|
||||
final short num1 = 1;
|
||||
final short num2 = 2;
|
||||
final short num3 = 3;
|
||||
final short num4 = 4;
|
||||
return new TPMInfo("test os make", num1, num2, num3, num4,
|
||||
getTestIdentityCertificate());
|
||||
}
|
||||
|
||||
private static X509Certificate getTestIdentityCertificate() {
|
||||
X509Certificate certificateValue = null;
|
||||
InputStream istream = null;
|
||||
istream = DeviceInfoReportTest.class.getResourceAsStream(
|
||||
TEST_IDENTITY_CERT
|
||||
);
|
||||
try {
|
||||
if (istream == null) {
|
||||
throw new FileNotFoundException(TEST_IDENTITY_CERT);
|
||||
}
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
certificateValue = (X509Certificate) cf.generateCertificate(
|
||||
istream);
|
||||
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
} finally {
|
||||
if (istream != null) {
|
||||
try {
|
||||
istream.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("test certificate file could not be closed");
|
||||
}
|
||||
}
|
||||
}
|
||||
return certificateValue;
|
||||
}
|
||||
|
||||
private String getXMLFromReport(final DeviceInfoReport deviceInfoReport)
|
||||
throws JAXBException {
|
||||
String xml = null;
|
||||
JAXBContext context = JAXBContext.newInstance(DeviceInfoReport.class);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(deviceInfoReport, writer);
|
||||
xml = writer.toString();
|
||||
xml = XMLCleaner.stripNonValidXMLCharacters(xml);
|
||||
return xml;
|
||||
}
|
||||
|
||||
private DeviceInfoReport getReportFromXML(final String xml)
|
||||
throws JAXBException {
|
||||
DeviceInfoReport deviceInfoReport;
|
||||
JAXBContext context;
|
||||
context = JAXBContext.newInstance(DeviceInfoReport.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
StringReader reader = new StringReader(xml);
|
||||
deviceInfoReport = (DeviceInfoReport) unmarshaller.unmarshal(reader);
|
||||
return deviceInfoReport;
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package hirs.data.persist;
|
||||
package hirs.attestationca.data.persist;
|
||||
|
||||
import hirs.data.persist.AppraisalStatus;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceInfoReport;
|
||||
import hirs.data.persist.enums.HealthStatus;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
@ -1,12 +1,15 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.servicemanager.DBCertificateManager;
|
||||
import hirs.data.persist.certificate.CertificateAuthorityCredential;
|
||||
import hirs.persist.CertificateManager;
|
||||
import org.springframework.util.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* This class contains simple tests some of the functionality of {@link CertificateSelector}.
|
||||
* This class contains simple tests some of the functionality of
|
||||
* {@link hirs.persist.CertificateSelector}.
|
||||
* For actual functional tests that test certificate retrieval using the class, see
|
||||
* {@link DBCertificateManagerTest}.
|
||||
*/
|
@ -1,9 +1,11 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.appraiser.IMAAppraiser;
|
||||
import hirs.appraiser.TPMAppraiser;
|
||||
import hirs.appraiser.TestAppraiser;
|
||||
import hirs.attestationca.servicemanager.DBAppraiserManager;
|
||||
import hirs.persist.AppraiserManager;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.query.Query;
|
||||
import org.testng.Assert;
|
||||
@ -41,7 +43,7 @@ public class DBAppraiserManagerTest extends SpringPersistenceTest {
|
||||
*/
|
||||
@AfterMethod
|
||||
public void resetTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
@ -1,5 +1,8 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.servicemanager.DBCertificateManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceGroupManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
@ -11,7 +14,11 @@ import hirs.data.persist.certificate.EndorsementCredential;
|
||||
import hirs.data.persist.certificate.IssuedAttestationCertificate;
|
||||
import hirs.data.persist.certificate.PlatformCredential;
|
||||
import hirs.data.persist.certificate.PlatformCredentialTest;
|
||||
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.CertificateSelector;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
@ -169,7 +176,7 @@ public class DBCertificateManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
private void resetCertificateTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Certificate> criteriaQuery = builder.createQuery(Certificate.class);
|
||||
@ -187,7 +194,7 @@ public class DBCertificateManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
private void resetDeviceTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Device> criteriaQuery = builder.createQuery(Device.class);
|
||||
@ -205,7 +212,7 @@ public class DBCertificateManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
private void resetDeviceGroupTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<DeviceGroup> criteriaQuery = builder.createQuery(DeviceGroup.class);
|
||||
@ -755,7 +762,8 @@ public class DBCertificateManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a {@link CertificateSelector} can be used to retrieve certificates in various
|
||||
* Tests that a {@link hirs.persist.CertificateSelector} can be used to
|
||||
* retrieve certificates in various
|
||||
* forms, including {@link Certificate}.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
@ -1,27 +1,35 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.appraiser.Appraiser;
|
||||
|
||||
import hirs.appraiser.TestAppraiser;
|
||||
import hirs.attestationca.servicemanager.DBAppraiserManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceGroupManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.attestationca.servicemanager.DBPolicyManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.data.persist.DeviceInfoReport;
|
||||
import hirs.attestationca.data.persist.DeviceTest;
|
||||
import hirs.data.persist.Policy;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import hirs.data.persist.TestPolicy;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import hirs.persist.AppraiserManager;
|
||||
import hirs.persist.DBUtility;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceGroupManagerException;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.PolicyMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import hirs.appraiser.TestAppraiser;
|
||||
|
||||
import hirs.data.persist.DeviceTest;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Unit tests for the <code>DBDeviceGroupManager</code> class.
|
@ -1,28 +1,34 @@
|
||||
package hirs.persist;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.servicemanager.DBDeviceGroupManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.attestationca.servicemanager.DBReportManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.data.persist.DeviceInfoReport;
|
||||
import hirs.data.persist.DeviceTest;
|
||||
import hirs.attestationca.data.persist.DeviceTest;
|
||||
import hirs.data.persist.enums.HealthStatus;
|
||||
import hirs.data.persist.info.NetworkInfo;
|
||||
import hirs.persist.DBUtility;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.DeviceManagerException;
|
||||
import hirs.persist.ReportManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* <code>DBDeviceManagerTest</code> is a unit test class for the
|
||||
* <code>DBDeviceManager</code> class.
|
||||
@ -99,7 +105,7 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
* <code>DeviceManagerException</code> if a <code>Device</code> is saved
|
||||
* twice.
|
||||
*
|
||||
* @throws DeviceManagerException if any unexpected errors occur
|
||||
* @throws hirs.persist.DeviceManagerException if any unexpected errors occur
|
||||
* @throws Exception
|
||||
* if any unexpected errors occur
|
||||
*/
|
@ -1,6 +1,9 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import hirs.attestationca.servicemanager.DBManager;
|
||||
import hirs.data.persist.LazyTestItemChild;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.DBUtility;
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
import org.hibernate.exception.LockAcquisitionException;
|
||||
@ -13,7 +16,6 @@ import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import hirs.data.persist.LazyTestItemChild;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
@ -68,10 +70,7 @@ public class DBManagerTest extends SpringPersistenceTest {
|
||||
* LazyInitializationException.
|
||||
*/
|
||||
@Test(expectedExceptions = LazyInitializationException.class)
|
||||
@SuppressFBWarnings(
|
||||
value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT",
|
||||
justification = "The statement is meant to throw an exception"
|
||||
)
|
||||
|
||||
public final void testGet() {
|
||||
LazyTestItemChild child = new LazyTestItemChild("Test Child");
|
||||
DBManager<LazyTestItemChild> childMan =
|
@ -1,13 +1,21 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.appraiser.TestAppraiser;
|
||||
import hirs.attestationca.data.persist.DeviceTest;
|
||||
import hirs.attestationca.servicemanager.DBDeviceGroupManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.attestationca.servicemanager.DBPolicyManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.data.persist.DeviceTest;
|
||||
import hirs.data.persist.Policy;
|
||||
import hirs.data.persist.TestPolicy;
|
||||
import hirs.data.persist.TestPolicy2;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.PolicyManagerException;
|
||||
import hirs.persist.PolicyMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
@ -66,7 +74,7 @@ public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
@BeforeMethod
|
||||
public void testSetup() {
|
||||
LOGGER.debug("setting up DBPolicyManager tests");
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
appraiser = new TestAppraiser("Test Appraiser");
|
||||
final Serializable id = session.save(appraiser);
|
||||
@ -90,7 +98,7 @@ public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
private void resetPolicyMapperTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<PolicyMapper> criteriaQuery = builder.createQuery(PolicyMapper.class);
|
||||
@ -108,7 +116,7 @@ public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
private void resetAppraiserTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Appraiser> criteriaQuery = builder.createQuery(Appraiser.class);
|
||||
@ -126,7 +134,7 @@ public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
private void resetPolicyTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Policy> criteriaQuery = builder.createQuery(Policy.class);
|
||||
@ -144,7 +152,7 @@ public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
private void resetDeviceTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Device> criteriaQuery = builder.createQuery(Device.class);
|
||||
@ -162,7 +170,7 @@ public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
}
|
||||
|
||||
private void resetDeviceGroupTestState() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<DeviceGroup> criteriaQuery = builder.createQuery(DeviceGroup.class);
|
||||
@ -183,7 +191,7 @@ public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
* Tests that the <code>DBPolicyManager</code> can save a
|
||||
* <code>Policy</code>.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* @throws hirs.persist.PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
@ -874,7 +882,7 @@ public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
LOGGER.debug("checking if policy {} is in database", name);
|
||||
Policy policy = null;
|
||||
Transaction tx = null;
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
LOGGER.debug("retrieving policy");
|
||||
tx = session.beginTransaction();
|
@ -1,4 +1,17 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.servicemanager.DBPortalInfoManager;
|
||||
import hirs.data.persist.enums.PortalScheme;
|
||||
import hirs.data.persist.info.PortalInfo;
|
||||
import hirs.persist.DBUtility;
|
||||
import hirs.persist.PortalInfoManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URI;
|
||||
@ -6,16 +19,6 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import hirs.data.persist.info.PortalInfo;
|
||||
import hirs.data.persist.enums.PortalScheme;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests for the DBPortalInfoManager.
|
||||
*/
|
@ -1,16 +1,20 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.servicemanager.DBDeviceGroupManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.attestationca.servicemanager.DBReportRequestStateManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.attestationca.data.persist.DeviceTest;
|
||||
import hirs.data.persist.ReportRequestState;
|
||||
import hirs.data.persist.type.ReportRequestType;
|
||||
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.DBUtility;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import hirs.data.persist.DeviceTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
@ -1,11 +1,12 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.appraiser.HIRSAppraiser;
|
||||
import hirs.appraiser.IMAAppraiser;
|
||||
import hirs.attestationca.servicemanager.DBReportSummaryManager;
|
||||
import hirs.data.persist.AppraisalResult;
|
||||
import hirs.data.persist.AppraisalStatus;
|
||||
import hirs.data.persist.ReportSummary;
|
||||
|
||||
import hirs.data.persist.SpringPersistenceTest;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
@ -0,0 +1,25 @@
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.configuration.PersistenceConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/**
|
||||
* Base class that autowires a session factory for use of
|
||||
* any tests that need a database connection.
|
||||
*/
|
||||
@ContextConfiguration(classes = PersistenceConfiguration.class)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
public class SpringPersistenceTest extends AbstractTestNGSpringContextTests {
|
||||
|
||||
/**
|
||||
* Autowired session factory.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:visibilitymodifier")
|
||||
@Autowired
|
||||
protected EntityManager sessionFactory;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package hirs.attestationca.service;
|
||||
|
||||
import hirs.attestationca.persist.SpringPersistenceTest;
|
||||
import hirs.appraiser.SupplyChainAppraiser;
|
||||
import hirs.data.persist.AppraisalStatus;
|
||||
import hirs.data.persist.Device;
|
||||
|
@ -2,7 +2,9 @@ package hirs.attestationca.portal.page;
|
||||
|
||||
import hirs.attestationca.AttestationCertificateAuthorityConfiguration;
|
||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
|
||||
/**
|
||||
* Simply holds a contextInitialized method which will be called when the web app starts.
|
||||
*/
|
||||
public class AcaInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
|
||||
|
||||
|
||||
|
@ -62,7 +62,7 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected final void removeAllOfClass(final Class clazz) {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<T> criteriaQuery = builder.createQuery(clazz);
|
||||
@ -85,7 +85,7 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
@Test
|
||||
public final void testSaveT() {
|
||||
LOGGER.debug("save {} test started", getDefaultClass());
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
final T object = getDefault(session);
|
||||
session.save(object);
|
||||
@ -100,14 +100,14 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
@Test
|
||||
public final void testGetT() {
|
||||
LOGGER.debug("get {} test started", getDefaultClass());
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
final T object = getDefault(session);
|
||||
LOGGER.debug("saving {}", object.getClass());
|
||||
final Serializable id = session.save(object);
|
||||
session.getTransaction().commit();
|
||||
|
||||
session = sessionFactory.getCurrentSession();
|
||||
session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
LOGGER.debug("getting {}", object.getClass());
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -126,7 +126,7 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public final void testUpdateT() {
|
||||
LOGGER.debug("update {} test started", getDefaultClass());
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
final T object = getDefault(session);
|
||||
LOGGER.debug("saving {}", object.getClass());
|
||||
@ -134,7 +134,7 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
session.getTransaction().commit();
|
||||
|
||||
LOGGER.debug("updating {}", object.getClass());
|
||||
session = sessionFactory.getCurrentSession();
|
||||
session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
T testObject = (T) session.get(object.getClass(), id);
|
||||
update(testObject);
|
||||
@ -142,7 +142,7 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
session.getTransaction().commit();
|
||||
|
||||
LOGGER.debug("getting {}", object.getClass());
|
||||
session = sessionFactory.getCurrentSession();
|
||||
session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
testObject = (T) session.get(object.getClass(), id);
|
||||
session.getTransaction().commit();
|
||||
@ -156,14 +156,14 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
@Test
|
||||
public final void testDeleteT() {
|
||||
LOGGER.debug("delete {} test started", getDefaultClass());
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
final T object = getDefault(session);
|
||||
LOGGER.debug("saving {}", object.getClass());
|
||||
final Serializable id = session.save(object);
|
||||
session.getTransaction().commit();
|
||||
|
||||
session = sessionFactory.getCurrentSession();
|
||||
session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
LOGGER.debug("getting {}", object.getClass());
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -171,7 +171,7 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
session.delete(t2);
|
||||
session.getTransaction().commit();
|
||||
|
||||
session = sessionFactory.getCurrentSession();
|
||||
session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
LOGGER.debug("getting {} again", object.getClass());
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -246,12 +246,12 @@ public abstract class HibernateTest<T> extends SpringPersistenceTest {
|
||||
* the retrieved copy of the object from the database
|
||||
*/
|
||||
protected final T saveAndRetrieve(final T object) {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
Serializable id = session.save(object);
|
||||
session.getTransaction().commit();
|
||||
|
||||
session = sessionFactory.getCurrentSession();
|
||||
session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
@SuppressWarnings("unchecked")
|
||||
final T testObject = (T) session.get(object.getClass(), id);
|
||||
|
@ -46,7 +46,7 @@ public class IntegrityReportTest extends HibernateTest<IntegrityReport> {
|
||||
*/
|
||||
private static IntegrityReport getTestReport() {
|
||||
IntegrityReport integrityReport = new IntegrityReport();
|
||||
integrityReport.addReport(DeviceInfoReportTest.getTestReport());
|
||||
// integrityReport.addReport(DeviceInfoReportTest.getTestReport());
|
||||
return integrityReport;
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ public class IntegrityReportTest extends HibernateTest<IntegrityReport> {
|
||||
@Test
|
||||
public final void testPersistingManyReports() throws Exception {
|
||||
IntegrityReport integrityReport = new IntegrityReport();
|
||||
integrityReport.addReport(DeviceInfoReportTest.getTestReport());
|
||||
// integrityReport.addReport(DeviceInfoReportTest.getTestReport());
|
||||
integrityReport.addReport(TPMReportTest.getTestReport());
|
||||
integrityReport.addReport(new TestReport());
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
package hirs.data.persist;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/**
|
||||
* Base class that autowires a session factory for use of
|
||||
* any tests that need a database connection.
|
||||
*/
|
||||
@ContextConfiguration(classes = PersistenceConfiguration.class)
|
||||
//@ContextConfiguration(classes = PersistenceConfiguration.class)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
public class SpringPersistenceTest extends AbstractTestNGSpringContextTests {
|
||||
|
||||
@ -19,5 +19,5 @@ public class SpringPersistenceTest extends AbstractTestNGSpringContextTests {
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:visibilitymodifier")
|
||||
@Autowired
|
||||
protected SessionFactory sessionFactory;
|
||||
protected EntityManager sessionFactory;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ TPMReportTest extends SpringPersistenceTest {
|
||||
public final void resetTestState() {
|
||||
LOGGER.debug("reset test state");
|
||||
LOGGER.debug("deleting all reports");
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Report> criteriaQuery = builder.createQuery(Report.class);
|
||||
@ -102,7 +102,7 @@ TPMReportTest extends SpringPersistenceTest {
|
||||
*/
|
||||
@Test
|
||||
public final void testSaveReport() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
final TPMReport r = getTestReport();
|
||||
session.save(r);
|
||||
@ -116,13 +116,13 @@ TPMReportTest extends SpringPersistenceTest {
|
||||
*/
|
||||
@Test
|
||||
public final void testGetReport() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
final TPMReport r = getTestReport();
|
||||
final UUID id = (UUID) session.save(r);
|
||||
session.getTransaction().commit();
|
||||
|
||||
session = sessionFactory.getCurrentSession();
|
||||
session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
final TPMReport testReport = (TPMReport) session.get(TPMReport.class, id);
|
||||
|
||||
@ -145,7 +145,7 @@ TPMReportTest extends SpringPersistenceTest {
|
||||
*/
|
||||
@Test(enabled = false)
|
||||
public final void testDeleteReport() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
|
||||
session.beginTransaction();
|
||||
final TPMReport r = getTestReport();
|
||||
|
@ -3,10 +3,10 @@ package hirs.persist;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
@ -39,10 +39,10 @@ public final class DBUtility {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void removeAllInstances(
|
||||
final SessionFactory sessionFactory,
|
||||
final EntityManager sessionFactory,
|
||||
final Class clazz) {
|
||||
LOGGER.debug("deleting all {} instances", clazz.toString());
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Class> criteriaQuery = builder.createQuery(clazz);
|
||||
@ -69,7 +69,7 @@ public final class DBUtility {
|
||||
* @return true if in database, otherwise false
|
||||
*/
|
||||
public static boolean isInDatabase(
|
||||
final SessionFactory sessionFactory,
|
||||
final EntityManager sessionFactory,
|
||||
final Class<?> clazz,
|
||||
final String name) {
|
||||
LOGGER.debug("checking if {} is in db", clazz.toString(), name);
|
||||
@ -88,14 +88,14 @@ public final class DBUtility {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean isInDatabase(
|
||||
final SessionFactory sessionFactory,
|
||||
final EntityManager sessionFactory,
|
||||
final Class clazz,
|
||||
final String propName, final Object value) {
|
||||
LOGGER.debug("checking if {} with property {} set to {}",
|
||||
clazz.toString(), propName, value);
|
||||
Object search = null;
|
||||
Transaction tx = null;
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
LOGGER.debug("retrieving");
|
||||
tx = session.beginTransaction();
|
||||
@ -130,11 +130,11 @@ public final class DBUtility {
|
||||
* @return number of instance of <code>clazz</code> in the database
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static int getCount(final SessionFactory sessionFactory, final Class clazz) {
|
||||
public static int getCount(final EntityManager sessionFactory, final Class clazz) {
|
||||
LOGGER.debug("counting number of instances of {} in db", clazz);
|
||||
int count = 0;
|
||||
Transaction tx = null;
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
tx = session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
|
Loading…
Reference in New Issue
Block a user