-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FM2-652 - Update unit and integration tests to remove test conflicts and fix resulting failures #555
FM2-652 - Update unit and integration tests to remove test conflicts and fix resulting failures #555
Changes from all commits
01ba800
d703738
d063290
7f58602
66f7a5f
d736f9d
4bd8690
53aa3c2
d1f6f11
acc9584
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
import java.util.Optional; | ||
|
||
import ca.uhn.fhir.rest.param.StringAndListParam; | ||
import lombok.AccessLevel; | ||
import lombok.Setter; | ||
import org.hibernate.Criteria; | ||
import org.hibernate.transform.DistinctRootEntityResultTransformer; | ||
|
@@ -38,7 +37,7 @@ | |
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Setter(AccessLevel.PACKAGE) | ||
@Setter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For mocking |
||
public class FhirConceptDaoImpl extends BaseFhirDao<Concept> implements FhirConceptDao { | ||
|
||
@Autowired | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Setter; | ||
import org.openmrs.Concept; | ||
import org.openmrs.ConceptMap; | ||
|
@@ -26,7 +25,7 @@ | |
|
||
@Component | ||
@Transactional | ||
@Setter(AccessLevel.PACKAGE) | ||
@Setter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For mocking |
||
public class FhirConceptServiceImpl implements FhirConceptService { | ||
|
||
@Autowired | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Setter; | ||
import org.openmrs.ConceptSource; | ||
import org.openmrs.Duration; | ||
|
@@ -28,7 +27,7 @@ | |
|
||
@Component | ||
@Transactional | ||
@Setter(AccessLevel.PACKAGE) | ||
@Setter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For mocking |
||
public class FhirConceptSourceServiceImpl implements FhirConceptSourceService { | ||
|
||
@Autowired | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,8 +50,9 @@ public Type toFhirResource(@Nonnull Obs obs) { | |
|
||
// IMPORTANT boolean values are stored as a coded value, so for this to | ||
// work, we must check for a boolean value before a general coded value | ||
if (obs.getValueBoolean() != null) { | ||
return new BooleanType(obs.getValueBoolean()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows mocking out the |
||
Boolean valueBoolean = getValueBoolean(obs); | ||
if (valueBoolean != null) { | ||
return new BooleanType(valueBoolean); | ||
} else if (obs.getValueCoded() != null) { | ||
return conceptTranslator.toFhirResource(obs.getValueCoded()); | ||
} else if (obs.getValueDrug() != null) { | ||
|
@@ -99,11 +100,25 @@ public Obs toOpenmrsType(@Nonnull Obs obs, @Nonnull Type resource) { | |
} else if (resource instanceof Quantity) { | ||
obs.setValueNumeric(((Quantity) resource).getValue().doubleValue()); | ||
} else if (resource instanceof BooleanType) { | ||
obs.setValueBoolean(((BooleanType) resource).getValue()); | ||
setValueBoolean(obs, ((BooleanType) resource).getValue()); | ||
} else if (resource instanceof StringType) { | ||
obs.setValueText(((StringType) resource).getValue()); | ||
} | ||
|
||
return obs; | ||
} | ||
|
||
/** | ||
* @return the valueBoolean of the given obs | ||
*/ | ||
protected Boolean getValueBoolean(Obs obs) { | ||
return obs.getValueBoolean(); | ||
} | ||
|
||
/** | ||
* sets the valueBoolean property of the given obs to the given value | ||
*/ | ||
protected void setValueBoolean(Obs obs, Boolean valueBoolean) { | ||
obs.setValueBoolean(valueBoolean); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,16 @@ | |
*/ | ||
package org.openmrs.module.fhir2; | ||
|
||
import org.mockito.Mockito; | ||
import org.openmrs.module.fhir2.api.util.LocalDateTimeFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.junit.Before; | ||
import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder; | ||
import org.openmrs.test.BaseModuleContextSensitiveTest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@Configuration | ||
public class MockedCalendarFactoryConfiguration { | ||
@ContextConfiguration(classes = { TestFhirSpringConfiguration.class }, inheritLocations = false) | ||
public abstract class BaseFhirContextSensitiveTest extends BaseModuleContextSensitiveTest { | ||
|
||
@Bean | ||
@Primary | ||
public LocalDateTimeFactory getCalendarFactory() { | ||
return Mockito.mock(LocalDateTimeFactory.class); | ||
@Before | ||
public void setupBaseFhirContextSensitive() { | ||
FhirGlobalPropertyHolder.reset(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This came through odd, but I removed the MockedCalendarFactoryConfiguration class and took a different approach in the tests that required it. And then I set up a base class for all of the context-sensitive tests in order to ensure the FhirGlobalPropertyHolder is reset before each test. I believe this FhirGlobalPropertyHolder, in the end, was likely the primary cause of all of the issues, but I still think it's worth cleaning out any mocks from context sensitive tests, and trying to avoid static mocks if at all possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's very likely the case... |
||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,25 +14,19 @@ | |
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.hibernate.SessionFactory; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.openmrs.Allergen; | ||
import org.openmrs.AllergenType; | ||
import org.openmrs.Allergy; | ||
import org.openmrs.AllergyReaction; | ||
import org.openmrs.Concept; | ||
import org.openmrs.module.fhir2.TestFhirSpringConfiguration; | ||
import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; | ||
import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; | ||
import org.openmrs.module.fhir2.api.dao.FhirAllergyIntoleranceDao; | ||
import org.openmrs.module.fhir2.api.dao.FhirConceptDao; | ||
import org.openmrs.test.BaseModuleContextSensitiveTest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) | ||
public class FhirAllergyIntoleranceDaoImplTest extends BaseModuleContextSensitiveTest { | ||
public class FhirAllergyIntoleranceDaoImplTest extends BaseFhirContextSensitiveTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many of the changes that follow will have similar change to this - remove the context configuration and set the base class to the new BaseFhirContextSensitiveTest (which has the context configuration), and update imports. |
||
|
||
private static final String ALLERGY_INTOLERANCE_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirAllergyIntoleranceDaoImplTest_initial_data.xml"; | ||
|
||
|
@@ -43,22 +37,13 @@ public class FhirAllergyIntoleranceDaoImplTest extends BaseModuleContextSensitiv | |
private static final String CODED_REACTION_UUID = "5087AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; | ||
|
||
@Autowired | ||
@Qualifier("sessionFactory") | ||
private SessionFactory sessionFactory; | ||
|
||
@Mock | ||
private FhirGlobalPropertyService globalPropertyService; | ||
|
||
private FhirAllergyIntoleranceDaoImpl allergyDao; | ||
private FhirAllergyIntoleranceDao allergyDao; | ||
|
||
@Autowired | ||
private FhirConceptDao conceptDao; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
allergyDao = new FhirAllergyIntoleranceDaoImpl(); | ||
allergyDao.setSessionFactory(sessionFactory); | ||
allergyDao.setGlobalPropertyService(globalPropertyService); | ||
executeDataSet(ALLERGY_INTOLERANCE_INITIAL_DATA_XML); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once I got the build to pass, the e2e tests failed as this syntax was now wrong. This fixes it.