Skip to content

Commit

Permalink
Adding persistence components to SupplyChainValidationSummaryTest - n…
Browse files Browse the repository at this point in the history
…ot currently working
  • Loading branch information
iadgovuser62 committed Feb 6, 2024
1 parent ec3a077 commit 4f00013
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
7 changes: 5 additions & 2 deletions HIRS_AttestationCA/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.0.1'
implementation 'com.github.darrachequesne:spring-data-jpa-datatables:6.0.1'
implementation 'org.springframework.retry:spring-retry:2.0.0'
implementation 'org.springframework:spring-test:6.0.11'
implementation libs.springdatajpa

implementation libs.bouncycastle
Expand All @@ -45,13 +46,15 @@ dependencies {
implementation libs.protobuf.java
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
implementation 'org.hibernate:hibernate-core:5.6.15.Final'

testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.3'
testImplementation 'org.hamcrest:hamcrest:2.2'

testImplementation 'org.mockito:mockito-core:4.2.0'
testImplementation 'org.powermock:powermock-core:2.0.9'
testImplementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'org.powermock:powermock-core:1.6.3'
testImplementation 'org.powermock:powermock-api-mockito:1.6.3'

// spring management
compileOnly libs.lombok
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package hirs.attestationca.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.junit4.AbstractJUnit4SpringContextTests;

/**
* 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 AbstractJUnit4SpringContextTests {

/**
* Autowired session factory.
*/
@SuppressWarnings("checkstyle:visibilitymodifier")
@Autowired
protected SessionFactory sessionFactory;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package hirs.attestationca.persist.entity.userdefined;
import hirs.attestationca.persist.PersistenceConfiguration;
import hirs.attestationca.persist.SpringPersistenceTest;
import hirs.attestationca.persist.entity.ArchivableEntity;
import hirs.attestationca.persist.entity.manager.CertificateRepository;
import hirs.attestationca.persist.entity.manager.DeviceRepository;
import hirs.attestationca.persist.enums.AppraisalStatus;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;

import java.util.List;
import java.util.Collection;
Expand All @@ -17,9 +24,39 @@
* Tests the functionality in SupplyChainValidationSummary, as well as the persistence of
* SupplyChainValidationSummary and SupplyChainValidation.
*/
public class SupplyChainValidationSummaryTest {
private Device device = DeviceTest.getTestDevice("TestDevice");
private List<ArchivableEntity> certificates = CertificateTest.getAllTestCertificates();;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class SupplyChainValidationSummaryTest extends SpringPersistenceTest {
private Device device;
private List<ArchivableEntity> certificates;
private CertificateRepository certificateRepository;
private DeviceRepository deviceRepository;
/**
* Create a session factory to use for persistence testing and persist some certificates
* for use by these tests.
*
* @throws Exception if there is a problem deserializing certificates or creating test device
*/
@BeforeAll
public void setup() throws Exception {
certificates = CertificateTest.getAllTestCertificates();
for (ArchivableEntity cert : certificates) {
certificateRepository.save((Certificate) cert);
}

device = DeviceTest.getTestDevice("TestDevice");
deviceRepository.save(device);
}

/**
* Remove test certificates and close the session factory.
*/
@AfterAll
public void teardown() {
for (ArchivableEntity cert : certificates) {
certificateRepository.delete((Certificate) cert);
}
deviceRepository.delete(device);
}

public SupplyChainValidationSummaryTest() throws Exception {
}
Expand Down

0 comments on commit 4f00013

Please sign in to comment.