Commit a40350e6 authored by Wylem Bars's avatar Wylem Bars

PATREG-33 | Add tests for multiple in .feature + review JavaDoc

parent 7eb0407c
Pipeline #138185 failed with stages
in 4 minutes and 17 seconds
......@@ -122,6 +122,12 @@ public class PatientDAOImpl implements PatientDAO {
}
}
/**
* Read a {@link PatientDB} from database based on its UUID
*
* @param uuid value of the Patient's UUID
* @return the {@link PatientDB}
*/
private PatientDB readPatientDB(String uuid) {
TypedQuery<PatientDB> query = entityManager.createNamedQuery("PatientDB.findByUuid", PatientDB.class);
query.setParameter("uuid", uuid);
......
......@@ -26,6 +26,9 @@ public class PatientSearchApplication implements PatientSearchService {
this.patientDAO = patientDAO;
}
/**
* {@inheritDoc}
*/
@Override
public List<Patient> search(SearchCriteria searchCriteria) throws SearchException {
if (searchCriteria!= null){
......
Put here classes from business layer :
Business model, rules and constraints. Always true. Independent from the application.
\ No newline at end of file
......@@ -23,9 +23,9 @@ public class PatientDaoTest {
private static final String PERSISTENCE_UNIT_NAME_CONST = "PersistenceUnitTest";
PatientDAO patientDAO;
private PatientDAO patientDAO;
EntityManager entityManager;
private EntityManager entityManager;
/**
* Initialize Database to test the DAO implementation
......
......@@ -4,6 +4,9 @@ import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
/**
* Test implementation of a {@link Produces} annotated class. Used to inject {@link EntityManager} corresponding to test Datasource.
*/
public class TestEntityManagerProducer {
private static final String PERSISTENCE_UNIT_NAME_CONST = "PersistenceUnitTest";
......
......@@ -5,8 +5,14 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Tests for {@link EntityManagerProducer}
*/
public class EntityManagerProducerTest {
/**
* Test constructor of class {@link EntityManagerProducer}
*/
@Test
public void instantiationTest() {
EntityManagerProducer entityManagerProducer = new EntityManagerProducer();
......
package net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search;
import javax.persistence.criteria.*;
import javax.persistence.metamodel.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class FromTestModel implements From {
@Override
public Set<Join> getJoins() {
return new HashSet<>();
}
@Override
public boolean isCorrelated() {
return false;
}
@Override
public From getCorrelationParent() {
return null;
}
@Override
public MapJoin joinMap(String s, JoinType joinType) {
return null;
}
@Override
public ListJoin joinList(String s, JoinType joinType) {
return null;
}
@Override
public SetJoin joinSet(String s, JoinType joinType) {
return null;
}
@Override
public CollectionJoin joinCollection(String s, JoinType joinType) {
return null;
}
@Override
public Join join(String s, JoinType joinType) {
return null;
}
@Override
public MapJoin joinMap(String s) {
return null;
}
@Override
public ListJoin joinList(String s) {
return new JoinTestModel();
}
@Override
public SetJoin joinSet(String s) {
return null;
}
@Override
public CollectionJoin joinCollection(String s) {
return null;
}
@Override
public Join join(String s) {
return new JoinTestModel();
}
@Override
public MapJoin join(MapAttribute mapAttribute, JoinType joinType) {
return null;
}
@Override
public ListJoin join(ListAttribute listAttribute, JoinType joinType) {
return new JoinTestModel();
}
@Override
public SetJoin join(SetAttribute setAttribute, JoinType joinType) {
return null;
}
@Override
public CollectionJoin join(CollectionAttribute collectionAttribute, JoinType joinType) {
return null;
}
@Override
public MapJoin join(MapAttribute mapAttribute) {
return null;
}
@Override
public ListJoin join(ListAttribute listAttribute) {
return new JoinTestModel();
}
@Override
public SetJoin join(SetAttribute setAttribute) {
return null;
}
@Override
public CollectionJoin join(CollectionAttribute collectionAttribute) {
return null;
}
@Override
public Join join(SingularAttribute singularAttribute, JoinType joinType) {
return new JoinTestModel();
}
@Override
public Join join(SingularAttribute singularAttribute) {
return new JoinTestModel();
}
@Override
public Set<Fetch> getFetches() {
return null;
}
@Override
public Fetch fetch(String s, JoinType joinType) {
return null;
}
@Override
public Fetch fetch(String s) {
return null;
}
@Override
public Fetch fetch(PluralAttribute pluralAttribute, JoinType joinType) {
return null;
}
@Override
public Fetch fetch(PluralAttribute pluralAttribute) {
return null;
}
@Override
public Fetch fetch(SingularAttribute singularAttribute, JoinType joinType) {
return null;
}
@Override
public Fetch fetch(SingularAttribute singularAttribute) {
return null;
}
@Override
public Bindable getModel() {
return null;
}
@Override
public Path<?> getParentPath() {
return null;
}
@Override
public Expression<Class> type() {
return null;
}
@Override
public Path get(String s) {
return null;
}
@Override
public Expression get(MapAttribute mapAttribute) {
return null;
}
@Override
public Expression get(PluralAttribute pluralAttribute) {
return null;
}
@Override
public Path get(SingularAttribute singularAttribute) {
return null;
}
@Override
public Predicate isNull() {
return null;
}
@Override
public Predicate isNotNull() {
return null;
}
@Override
public Predicate in(Object... objects) {
return null;
}
@Override
public Expression as(Class aClass) {
return null;
}
@Override
public Predicate in(Expression expression) {
return null;
}
@Override
public Predicate in(Collection collection) {
return null;
}
@Override
public Predicate in(Expression[] expressions) {
return null;
}
@Override
public Selection alias(String s) {
return null;
}
@Override
public boolean isCompoundSelection() {
return false;
}
@Override
public List<Selection<?>> getCompoundSelectionItems() {
return null;
}
@Override
public Class getJavaType() {
return null;
}
@Override
public String getAlias() {
return null;
}
}
package net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search;
import javax.persistence.criteria.*;
import javax.persistence.metamodel.*;
public class JoinTestModel extends FromTestModel implements ListJoin {
@Override
public ListAttribute getModel() {
return null;
}
@Override
public ListJoin on(Expression restriction) {
return null;
}
@Override
public ListJoin on(Predicate... restrictions) {
return null;
}
@Override
public Predicate getOn() {
return null;
}
@Override
public Attribute getAttribute() {
return null;
}
@Override
public From getParent() {
return null;
}
@Override
public JoinType getJoinType() {
return null;
}
@Override
public Expression<Integer> index() {
return null;
}
}
......@@ -26,6 +26,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
*/
public class ContainerInjectionTest {
/**
* Initialize {@link PatientProcessingService}
*/
@Test
public void initializePatientProcessingService() {
SeContainer container = initializeContainer();
......@@ -36,6 +39,9 @@ public class ContainerInjectionTest {
assertNotNull(patientProcessingService);
}
/**
* Initialize {@link PatientFeedApplication}
*/
@Test
public void initializePatientProcessingApplication() {
SeContainer container = initializeContainer();
......@@ -46,6 +52,9 @@ public class ContainerInjectionTest {
assertNotNull(patientProcessingService);
}
/**
* Initialize {@link PatientSearchApplication}
*/
@Test
public void initializePatientSearchApplication() {
SeContainer container = initializeContainer();
......@@ -56,6 +65,11 @@ public class ContainerInjectionTest {
assertNotNull(patientProcessingService);
}
/**
* Initialize a {@link SeContainer} with all classes needed for the application to run with injection.
*
* @return the initialized container.
*/
private SeContainer initializeContainer(){
SeContainerInitializer initializer = SeContainerInitializer.newInstance()
.disableDiscovery().addBeanClasses(PatientProcessingService.class,
......
......@@ -26,9 +26,12 @@ public class PatientFeedProcessingServiceTest {
private PatientFeedProcessingService patientFeedProcessingService;
private TestPatientFeedServiceImpl testPatientFeedServiceImpl;
/**
* Initialize implementations to be tested before each test.
*/
@BeforeEach
public void setUp(){
testPatientFeedServiceImpl = new TestPatientFeedServiceImpl();
this.testPatientFeedServiceImpl = new TestPatientFeedServiceImpl();
this.patientFeedProcessingService = new PatientFeedProcessingService(testPatientFeedServiceImpl);
}
......
......@@ -16,11 +16,17 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Tests for class {@link PatientProcessingService}
*/
@Covers(requirements = {"SIMUSRV-001", "SIMUSRV-002"})
public class PatientProcessingServiceTest {
private PatientProcessingService patientProcessingService;
/**
* Initialize implementations to be tested before each test.
*/
@BeforeEach
public void setUp(){
this.patientProcessingService = new PatientProcessingService(new PatientFeedProcessingService(new TestPatientFeedServiceImpl()),
......
......@@ -17,14 +17,20 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Tests for {@link PatientSearchProcessingService}
*/
public class PatientSearchProcessingServiceTest {
private PatientSearchProcessingService patientSearchProcessingService;
private TestPatientSearchServiceImpl testPatientSearchService;
/**
* Initialize implementations to be tested before each test.
*/
@BeforeEach
public void setUp(){
testPatientSearchService = new TestPatientSearchServiceImpl();
this.testPatientSearchService = new TestPatientSearchServiceImpl();
this.patientSearchProcessingService = new PatientSearchProcessingService(testPatientSearchService);
}
......
......@@ -18,6 +18,9 @@ import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
/**
* Tests for {@link PatientFeedApplication}
*/
public class PatientFeedApplicationTest {
private static final String PERSISTENCE_UNIT_NAME_CONST = "PersistenceUnitTest";
......
......@@ -8,22 +8,36 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests for {@link PatientRetrieveApplication}
*/
public class PatientRetrieveApplicationTest {
private TestPatientDAO patientDAO;
private PatientRetrieveApplication patientRetrieveApplication;
/**
* Initialize implementations to be tested before each test.
*/
@BeforeEach
public void init(){
patientDAO = new TestPatientDAO();
patientRetrieveApplication = new PatientRetrieveApplication(patientDAO);
}
/**
* Check the retrieve in nominal case
*
* @throws PatientRetrieveException if an exception is thrown during the retrieve operation.
*/
@Test
public void retrieve_ok() throws PatientRetrieveException {
assertNotNull(patientRetrieveApplication.retrievePatient("uuid"));
}
/**
* Checsk the retrieve when a {@link PatientRetrieveException} is thrown.
*/
@Test
public void retrieve_PatientReadException() {
patientDAO.setRetrieveResult(TestPatientDAO.RetrieveResult.PATIENT_READ_EXCEPTION);
......@@ -31,6 +45,9 @@ public class PatientRetrieveApplicationTest {
assertThrows(PatientRetrieveException.class, () -> patientRetrieveApplication.retrievePatient("uuid"));
}
/**
* Checsk the retrieve when a {@link PatientNotFoundException} is thrown.
*/
@Test
public void retrieve_PatientNotFound() {
patientDAO.setRetrieveResult(TestPatientDAO.RetrieveResult.PATIENT_NOT_FOUND_EXCEPTION);
......
......@@ -20,6 +20,9 @@ public class PatientSearchApplicationTest {
PatientSearchApplication patientSearchApplication;
TestPatientDAO testPatientDAO;
/**
* Initialize implementations to be tested before each test.
*/
@BeforeEach
public void init(){