Skip to content

Commit 98aca5d

Browse files
committed
R
1 parent 8a95d46 commit 98aca5d

File tree

7 files changed

+94
-4
lines changed

7 files changed

+94
-4
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.reporting.evaluation;
11+
12+
import java.io.File;
13+
import java.io.IOException;
14+
import java.nio.file.Path;
15+
import java.nio.file.Paths;
16+
17+
import org.junit.Assert;
18+
import org.junit.Before;
19+
import org.junit.Test;
20+
import org.openmrs.module.reporting.ReportingConstants;
21+
import org.openmrs.util.OpenmrsUtil;
22+
23+
public class DeleteOldLogsTest {
24+
25+
File baseDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(ReportingConstants.REPORT_RESULTS_DIRECTORY_NAME);
26+
27+
Path test= Paths.get(baseDir.getAbsolutePath(),"test.reportlog");
28+
File test_file = test.toFile();
29+
30+
@Before
31+
public void init() throws IOException {
32+
test_file.createNewFile();
33+
}
34+
35+
@Test
36+
public void Should_DeleteLogFlesExceedingSevendays() throws IOException {
37+
//Setting the file to exist over seven days
38+
long exceedingDays = 8 ;
39+
test_file.setLastModified(exceedingDays * (24 * 60 * 60 * 1000));
40+
41+
// asserting that the file exists befor the servlet DeleteOldLogs is called
42+
Assert.assertTrue(test_file.exists());
43+
44+
DeleteOldLogFiles delete = new DeleteOldLogFiles ();
45+
delete.deleteOldLogs();
46+
47+
//Asserting that the Log file will be deleted after seven days
48+
Assert.assertFalse(test_file.exists());
49+
}
50+
51+
@Test
52+
public void Should_NotDeleteLogFilesBeforeSevenDayPass() throws IOException {
53+
54+
// asserting that the file exists befor the servlet DeleteOldLogs is called
55+
Assert.assertTrue(test_file.exists());
56+
57+
DeleteOldLogFiles delete = new DeleteOldLogFiles ();
58+
delete.deleteOldLogs();
59+
60+
//Asserting that the Log file will Not be deleted after seven days
61+
Assert.assertTrue(test_file.exists());
62+
}
63+
64+
}
65+
66+
67+
68+
69+

api-tests/src/test/java/org/openmrs/module/reporting/report/service/ReportServiceTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,10 @@ public void purgeReportDesignsForReportDefinition_shouldDeleteAllAssociatedRepor
521521
assertNull(rs.getReportDesignByUuid("d7a82b63-1066-4c1d-9b43-b405851fc467"));
522522
assertNull(rs.getReportDesignByUuid("e7a82b63-1066-4c1d-9b43-b405851fc467"));
523523
}
524+
525+
@Test
526+
public void shoild_returnAllReportRequests() {
527+
ReportService rs = Context.getService(ReportService.class);
528+
Assert.assertEquals(3, rs.getAllReportRequests().size());
529+
}
524530
}

api/src/main/java/org/openmrs/module/reporting/evaluation/DeleteOldLogFiles.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525

2626

2727
public class DeleteOldLogFiles extends HttpServlet {
28-
// Servlet to delete old Logs on module startup
28+
29+
private static final long serialVersionUID = 1L;
30+
// Servlet to delete old Logs on module startup
2931
protected static final Log log = LogFactory.getLog(DeleteOldLogFiles.class);
3032

3133

3234
public void deleteOldLogs(){
3335
//maximum number of days to keep log files is 7
34-
long alloweddays = 7;
36+
long alloweddays = 7;
3537
File baseDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(ReportingConstants.REPORT_RESULTS_DIRECTORY_NAME);
3638
File[] fList = baseDir.listFiles();
3739

api/src/main/java/org/openmrs/module/reporting/report/service/ReportService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ public interface ReportService extends OpenmrsService {
133133
@Transactional(readOnly = true)
134134
public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition, Date requestOnOrAfter, Date requestOnOrBefore, Status...statuses);
135135

136-
@Transactional
136+
/**
137+
* @return all {@link ReportRequest} in the system
138+
* @should retrieve all report requests
139+
*/
140+
@Transactional(readOnly = true)
137141
public List<ReportRequest> getAllReportRequests();
138142

139143

api/src/main/java/org/openmrs/module/reporting/report/service/ReportServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition,
223223
return reportDAO.getReportRequests(reportDefinition, requestOnOrAfter, requestOnOrBefore, mostRecentNum, statuses);
224224
}
225225

226+
227+
/**
228+
* @see ReportService#getReportRequests()
229+
*/
226230
@Transactional(readOnly=true)
227231
public List<ReportRequest> getAllReportRequests(){
228232
return reportDAO.getAllReportRequests();

api/src/main/java/org/openmrs/module/reporting/report/service/db/HibernateReportDAO.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ public List<String> getReportRequestUuids(String reportDefinitionUuid) {
256256
return query.list();
257257
}
258258

259-
259+
/**
260+
* @see ReportDAO#getReportAllRequests()
261+
*/
260262
public List<ReportRequest> getAllReportRequests(){
261263
String hql = "from ReportRequest";
262264
Query query = sessionFactory.getCurrentSession().createQuery(hql);

api/src/main/java/org/openmrs/module/reporting/report/service/db/ReportDAO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public List<ReportDesign> getReportDesigns(ReportDefinition reportDefinition, Cl
118118
*/
119119
public ReportRequest getReportRequestByUuid(String uuid);
120120

121+
/**
122+
* @returns all the {@link ReportRequestst}
123+
*/
121124
public List<ReportRequest> getAllReportRequests();
122125

123126
/**

0 commit comments

Comments
 (0)