Skip to content

Commit

Permalink
No error occurs in a unit test but does in web app accessed through t…
Browse files Browse the repository at this point in the history
…he UI
  • Loading branch information
kaweesi committed Oct 11, 2016
1 parent 71b8902 commit 77f0d89
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 47 deletions.
10 changes: 9 additions & 1 deletion api/pom.xml
Expand Up @@ -37,9 +37,17 @@
<groupId>org.openmrs.module</groupId>
<artifactId>calculation-api</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>serialization.xstream-api</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>rwandasphstudyreports-api</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>serialization.xstream-api</artifactId>
<artifactId>htmlwidgets-omod</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
Expand Down
Expand Up @@ -6,7 +6,6 @@
import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.openmrs.Concept;
import org.openmrs.Location;
import org.openmrs.Obs;
Expand All @@ -19,7 +18,6 @@
import org.openmrs.module.mohtracportal.service.MohTracPortalService;
import org.openmrs.module.reporting.definition.DefinitionSummary;
import org.openmrs.module.reporting.evaluation.parameter.Mapped;
import org.openmrs.module.reporting.report.Report;
import org.openmrs.module.reporting.report.ReportRequest;
import org.openmrs.module.reporting.report.ReportRequest.Priority;
import org.openmrs.module.reporting.report.definition.ReportDefinition;
Expand Down Expand Up @@ -198,14 +196,14 @@ public int executeMySQLCommand(String sql) {
}

@Override
public Report executeAndGetAdultArtMonthlyWhichIncludesAdultFollowUpReport() {
public ReportRequest executeAndGetAdultFollowUpReportRequest() {
DefinitionSummary lostToFollowUp = null;
Report report = null;
ReportRequest reportRequest = null;
List<DefinitionSummary> defs = Context.getService(ReportDefinitionService.class)
.getAllDefinitionSummaries(false);

for (DefinitionSummary ds : defs) {
if ("HIV-Adult ART Report-Monthly".equals(ds.getName())) {
if ("LostToFollowupPatients".equals(ds.getName())) {
lostToFollowUp = ds;
break;
}
Expand All @@ -216,33 +214,21 @@ public Report executeAndGetAdultArtMonthlyWhichIncludesAdultFollowUpReport() {
ReportDefinition def = Context.getService(ReportDefinitionService.class)
.getDefinitionByUuid(lostToFollowUp.getUuid());

if (rr != null)
if (rr == null) {
rr = new ReportRequest(new Mapped<ReportDefinition>(def, null), null,
new RenderingMode(new DefaultWebRenderer(), "Web", null, 100), Priority.NORMAL, null);
report = Context.getService(ReportService.class).runReport(rr);
}

return report;
}

@Override
public void getLostToFollowupFromReportHistory() {
try {
List<DefinitionSummary> defs = Context.getService(ReportDefinitionService.class)
.getAllDefinitionSummaries(false);
List<ReportRequest> history = Context.getService(ReportService.class).getReportRequests(null, null, null,
null);
List<ReportDefinition> artReportDef = Context.getService(ReportDefinitionService.class)
.getDefinitions("HIV-Adult ART Report-Monthly", true);
if (history != null) {
for (ReportRequest rq : history) {

}
rr.setStatus(ReportRequest.Status.REQUESTED);
rr.setPriority(ReportRequest.Priority.NORMAL);
rr.getReportDefinition().addParameterMapping("Health Center",
Context.getLocationService().getLocation(Integer.parseInt(Context.getAdministrationService()
.getGlobalProperty("mohtracportal.defaultLocationId"))).getName());
rr = Context.getService(ReportService.class).saveReportRequest(rr);
}
} catch (HibernateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
reportRequest = rr;
}

return reportRequest;
}

}
Expand Up @@ -14,6 +14,7 @@
import org.openmrs.module.mohtracportal.Sponsor;
import org.openmrs.module.mohtracportal.SponsorLocation;
import org.openmrs.module.reporting.report.Report;
import org.openmrs.module.reporting.report.ReportRequest;
import org.springframework.transaction.annotation.Transactional;

/**
Expand Down Expand Up @@ -95,8 +96,6 @@ public String getNumberOfRecordCreatedByObjectAndByUser(Integer userId,

public int executeMySQLCommand(String sql);

Report executeAndGetAdultArtMonthlyWhichIncludesAdultFollowUpReport();

void getLostToFollowupFromReportHistory();
ReportRequest executeAndGetAdultFollowUpReportRequest();

}
@@ -1,24 +1,91 @@
package org.openmrs.module.mohtracportal.service;

import java.util.List;
import java.util.Collection;
import java.util.Properties;

import org.hibernate.HibernateException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.api.context.Context;
import org.openmrs.module.reporting.definition.DefinitionSummary;
import org.openmrs.module.reporting.report.definition.service.ReportDefinitionService;
import org.openmrs.module.Module;
import org.openmrs.module.ModuleConstants;
import org.openmrs.module.ModuleFactory;
import org.openmrs.module.ModuleUtil;
import org.openmrs.module.reporting.report.Report;
import org.openmrs.module.reporting.report.ReportRequest;
import org.openmrs.module.reporting.report.service.ReportService;
import org.openmrs.module.rwandasphstudyreports.api.CDCReportsService;
import org.openmrs.test.BaseModuleContextSensitiveTest;

public class MohTracPortalServiceTest extends BaseModuleContextSensitiveTest {

@Override
public Boolean useInMemoryDatabase() {
return false;
}

@Before
public void setupForTest() throws Exception {
if (!Context.isSessionOpen()) {
Context.openSession();
}
Context.clearSession();
authenticate();
}

@Override
public Properties getRuntimeProperties() {
Properties props = super.getRuntimeProperties();

props.setProperty("connection.url",
"jdbc:mysql://localhost:3306/ecdmrs_pih?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8");
props.setProperty("connection.username", "ecdmrs_pih_user");
props.setProperty("connection.password", "cxOLDkN6K~OX");
props.setProperty("junit.username", "test");// OpenMRS username
props.setProperty("junit.password", "Password123");// OpenMRS password

props.setProperty(ModuleConstants.RUNTIMEPROPERTY_MODULE_LIST_TO_LOAD,
"mohtracportal-0.2.7-SNAPSHOT.omod htmlwidgets-1.7.2.omod calculation-1.2.omod serialization.xstream-0.2.7.omod reporting-0.9.7.omod rwandasphstudyreports-1.0-SNAPSHOT.omod");

return props;
}

@Before
public void init() {
// ModuleUtil.startup(getRuntimeProperties());
}

@Test
public void shouldSetupContext() {
Assert.assertNotNull(Context.getService(MohTracPortalService.class));
}

@Test(expected = HibernateException.class)
public void reportingBug() throws Exception {
Context.getService(ReportDefinitionService.class).getAllDefinitionSummaries(false);
/**
* @TODO weird to load all modules which rwandasphstudyreports depends on
* before loading it
*/
@Test
public void reportingBug() {
Assert.assertNotNull(Context.getService(CDCReportsService.class));

ModuleUtil.startup(getRuntimeProperties());

Collection<Module> loadedModules = ModuleFactory.getLoadedModules();

Assert.assertTrue(loadedModules.size() > 0);

/*
* this next line throws org.hibernate.HibernateException: Unable to
* locate named class
* org.openmrs.module.reporting.serializer.ReportingSerializer in the web application
*/
ReportRequest rr = Context.getService(MohTracPortalService.class).executeAndGetAdultFollowUpReportRequest();

ReportRequest req = Context.getService(ReportService.class).getReportRequestByUuid(rr.getUuid());
Report report = Context.getService(ReportService.class).runReport(rr);

Assert.assertNotNull(rr);
Assert.assertEquals(req.getUuid(), rr.getUuid());
Assert.assertEquals(report.getRequest().getUuid(), rr.getUuid());
}
}
Binary file added api/src/test/resources/calculation-1.2.omod
Binary file not shown.
Binary file added api/src/test/resources/htmlwidgets-1.7.2.omod
Binary file not shown.
Binary file not shown.
Binary file added api/src/test/resources/reporting-0.9.7.omod
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -4,7 +4,6 @@
package org.openmrs.module.mohtracportal.web.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -14,7 +13,7 @@
import org.openmrs.layout.web.LayoutSupport;
import org.openmrs.layout.web.address.AddressSupport;
import org.openmrs.module.mohtracportal.service.MohTracPortalService;
import org.openmrs.module.reporting.report.Report;
import org.openmrs.module.reporting.report.ReportRequest;
import org.openmrs.web.controller.layout.LayoutPortletController;
import org.springframework.web.servlet.ModelAndView;

Expand All @@ -36,9 +35,9 @@ protected LayoutSupport getLayoutSupportInstance() {
}

private void addLostToFollowUpReportToModel(ModelAndView mav) {
Report lostFollowUpreport = Context.getService(MohTracPortalService.class)
.executeAndGetAdultArtMonthlyWhichIncludesAdultFollowUpReport();
ReportRequest lostFollowUpreport = Context.getService(MohTracPortalService.class)
.executeAndGetAdultFollowUpReportRequest();

mav.addObject("lostToFollowup", lostFollowUpreport != null ? lostFollowUpreport : "");
}

Expand All @@ -53,9 +52,7 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons
// mohPortalObjects.put("authUser", Context.getAuthenticatedUser());
//
// request.setAttribute("mohPortalObjects", mohPortalObjects);
//addLostToFollowUpReportToModel(mav);
//Context.getService(MohTracPortalService.class).getLostToFollowupFromReportHistory();

addLostToFollowUpReportToModel(mav);
return mav;
}

Expand Down
2 changes: 2 additions & 0 deletions omod/src/main/resources/config.xml
Expand Up @@ -20,6 +20,8 @@
<require_modules>
<require_module version="${reportingVersion}">org.openmrs.module.reporting</require_module>
<require_module version="${serializationVersion}">org.openmrs.module.serialization.xstream</require_module>
<require_module>org.openmrs.module.htmlwigets</require_module>
<require_module version="${rwandasphstudyreportsVersion}">org.openmrs.module.rwandasphstudyreports</require_module>
</require_modules>
<!-- / Required Modules -->

Expand Down
13 changes: 13 additions & 0 deletions pom.xml
Expand Up @@ -73,6 +73,18 @@
<version>${serializationVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>rwandasphstudyreports-api</artifactId>
<version>${rwandasphstudyreportsVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>htmlwidgets-omod</artifactId>
<version>1.6.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -82,6 +94,7 @@
<calculationVersion>1.0</calculationVersion>
<reportingVersion>0.9.7</reportingVersion>
<serializationVersion>0.2.7</serializationVersion>
<rwandasphstudyreportsVersion>1.0-SNAPSHOT</rwandasphstudyreportsVersion>
</properties>

<build>
Expand Down

0 comments on commit 77f0d89

Please sign in to comment.