Skip to content

Commit b1c0110

Browse files
committed
Fix test errors
1 parent 128b24a commit b1c0110

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

api-tests/src/test/java/org/openmrs/module/reporting/cohort/definition/evaluator/VisitCohortDefinitionEvaluatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import static org.hamcrest.core.Is.is;
3333
import static org.junit.Assert.assertThat;
3434

35-
public class VisitCohortDefinitionEvaluatorTest extends BaseModuleContextSensitiveTest {;
35+
public class VisitCohortDefinitionEvaluatorTest extends BaseModuleContextSensitiveTest {
3636

3737
@Autowired
3838
LocationService locationService;
@@ -68,7 +68,7 @@ public void setUp() throws Exception {
6868
@Test
6969
public void testEvaluateWithNoProperties() throws Exception {
7070
Cohort c = cohortDefinitionService.evaluate(cd, null);
71-
assertThat(c.size(), is(2));
71+
assertThat(c.size(), is(3));
7272
}
7373

7474
@Test

api-tests/src/test/java/org/openmrs/module/reporting/data/converter/PrivilegedDataConverterTest.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import org.junit.Test;
1717
import org.openmrs.api.context.Context;
1818
import org.openmrs.test.BaseModuleContextSensitiveTest;
19+
import org.openmrs.test.SkipBaseSetup;
1920

21+
@SkipBaseSetup
2022
public class PrivilegedDataConverterTest extends BaseModuleContextSensitiveTest {
2123

2224
public static final String INPUT = "input";
@@ -27,15 +29,24 @@ public class PrivilegedDataConverterTest extends BaseModuleContextSensitiveTest
2729

2830
@Before
2931
public void setUp() throws Exception {
30-
Context.addProxyPrivilege(HAS_PRIV);
31-
// Context.removeProxyPrivilege(DOES_NOT_HAVE_PRIV);
32+
initializeInMemoryDatabase();
33+
executeDataSet("org/openmrs/module/reporting/include/PrivilegeTest.xml");
34+
Context.logout();
35+
Context.authenticate("test", "test");
3236
}
3337

3438
@Test
35-
public void testConvertWithPrivilege() throws Exception {
36-
PrivilegedDataConverter converter = new PrivilegedDataConverter(HAS_PRIV);
37-
converter.setReplacement(REPLACEMENT);
38-
assertThat((String) converter.convert(INPUT), is(INPUT));
39+
public void testConvertWithPrivilege() {
40+
try {
41+
Context.addProxyPrivilege(HAS_PRIV);
42+
Context.hasPrivilege(HAS_PRIV);
43+
PrivilegedDataConverter converter = new PrivilegedDataConverter(HAS_PRIV);
44+
converter.setReplacement(REPLACEMENT);
45+
assertThat((String) converter.convert(INPUT), is(INPUT));
46+
}
47+
finally {
48+
Context.removeProxyPrivilege(HAS_PRIV);
49+
}
3950
}
4051

4152
@Test

api-tests/src/test/java/org/openmrs/module/reporting/data/visit/evaluator/VisitIdDataEvaluatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void evaluate_shouldReturnVisitIdsForThePatientsGivenAnEvaluationContext(
4949
VisitIdDataDefinition d = new VisitIdDataDefinition();
5050
EvaluationContext context = new EvaluationContext();
5151
EvaluatedVisitData ed = Context.getService(VisitDataService.class).evaluate(d, context);
52-
Assert.assertEquals(5, ed.getData().size()); // one visit in the sample data has been voided
52+
Assert.assertEquals(6, ed.getData().size()); // one visit in the sample data has been voided
5353
for (Integer eId : ed.getData().keySet()) {
5454
Assert.assertEquals(eId, ed.getData().get(eId));
5555
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!--
3+
4+
This Source Code Form is subject to the terms of the Mozilla Public License,
5+
v. 2.0. If a copy of the MPL was not distributed with this file, You can
6+
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
7+
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
8+
9+
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
10+
graphic logo is a trademark of OpenMRS Inc.
11+
12+
-->
13+
<dataset>
14+
<person person_id="3" gender="" birthdate="1975-06-30" birthdate_estimated="false" dead="false" date_created="2005-01-01 00:00:00.0" voided="false" uuid="6adb7c42-cfd2-4301-b53b-ff17c5654ffa"/>
15+
<users user_id="3" person_id="3" system_id="1-8" username="test" password="4a1750c8607d0fa237de36c6305715c223415189" salt="c788c6ad82a157b712392ca695dfcf2eed193d7f" secret_question="" creator="1" date_created="2005-01-01 00:00:00.0" changed_by="1" date_changed="2007-09-20 21:54:12.0" retired="false" retire_reason="" uuid="1010d442-e134-11de-babe-001e378eb67f"/>
16+
<user_role user_id="1" role="Authenticated"/>
17+
</dataset>

api/src/main/java/org/openmrs/module/reporting/config/ReportLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static void saveReportDefinition(ReportDefinition reportDefinition) {
9191
public static void saveReportDesigns(ReportDefinition reportDefinition, List<ReportDesign> reportDesigns) {
9292
// purging a ReportDesign doesn't trigger any extra logic, so we can just purge-and-recreate here
9393
List<ReportDesign> existingDesigns = Context.getService(ReportService.class).getReportDesigns(reportDefinition, null, true);
94-
if (existingDesigns.size() > 0) {
94+
if (!existingDesigns.isEmpty()) {
9595
log.debug("Deleting " + existingDesigns.size() + " old designs for " + reportDefinition.getName());
9696
for (ReportDesign design : existingDesigns) {
9797
Context.getService(ReportService.class).purgeReportDesign(design);

api/src/main/java/org/openmrs/module/reporting/serializer/ReportingSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.commons.logging.LogFactory;
2222
import org.openmrs.api.context.Context;
2323
import org.openmrs.module.reporting.evaluation.parameter.Mapped;
24+
import org.openmrs.module.reporting.evaluation.parameter.Parameter;
2425
import org.openmrs.module.serialization.xstream.XStreamShortSerializer;
2526
import org.openmrs.module.serialization.xstream.mapper.CGLibMapper;
2627
import org.openmrs.module.serialization.xstream.mapper.HibernateCollectionMapper;
@@ -90,7 +91,7 @@ public Object unmarshal(HierarchicalStreamReader reader, Object root) {
9091

9192
xstream.registerConverter(new ReportDefinitionConverter(mapper, converterLookup));
9293

93-
xstream.allowTypes(new Class[] { Mapped.class });
94+
xstream.allowTypes(new Class[] { Mapped.class, Parameter.class });
9495
}
9596

9697
@Override

0 commit comments

Comments
 (0)