Skip to content

Commit

Permalink
R
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzy11 committed Apr 4, 2019
1 parent 8a95d46 commit 98aca5d
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.reporting.evaluation;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.module.reporting.ReportingConstants;
import org.openmrs.util.OpenmrsUtil;

public class DeleteOldLogsTest {

File baseDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(ReportingConstants.REPORT_RESULTS_DIRECTORY_NAME);

Path test= Paths.get(baseDir.getAbsolutePath(),"test.reportlog");
File test_file = test.toFile();

@Before
public void init() throws IOException {
test_file.createNewFile();
}

@Test
public void Should_DeleteLogFlesExceedingSevendays() throws IOException {
//Setting the file to exist over seven days
long exceedingDays = 8 ;
test_file.setLastModified(exceedingDays * (24 * 60 * 60 * 1000));

// asserting that the file exists befor the servlet DeleteOldLogs is called
Assert.assertTrue(test_file.exists());

DeleteOldLogFiles delete = new DeleteOldLogFiles ();
delete.deleteOldLogs();

//Asserting that the Log file will be deleted after seven days
Assert.assertFalse(test_file.exists());
}

@Test
public void Should_NotDeleteLogFilesBeforeSevenDayPass() throws IOException {

// asserting that the file exists befor the servlet DeleteOldLogs is called
Assert.assertTrue(test_file.exists());

DeleteOldLogFiles delete = new DeleteOldLogFiles ();
delete.deleteOldLogs();

//Asserting that the Log file will Not be deleted after seven days
Assert.assertTrue(test_file.exists());
}

}





Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,10 @@ public void purgeReportDesignsForReportDefinition_shouldDeleteAllAssociatedRepor
assertNull(rs.getReportDesignByUuid("d7a82b63-1066-4c1d-9b43-b405851fc467"));
assertNull(rs.getReportDesignByUuid("e7a82b63-1066-4c1d-9b43-b405851fc467"));
}

@Test
public void shoild_returnAllReportRequests() {
ReportService rs = Context.getService(ReportService.class);
Assert.assertEquals(3, rs.getAllReportRequests().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@


public class DeleteOldLogFiles extends HttpServlet {
// Servlet to delete old Logs on module startup

private static final long serialVersionUID = 1L;
// Servlet to delete old Logs on module startup
protected static final Log log = LogFactory.getLog(DeleteOldLogFiles.class);


public void deleteOldLogs(){
//maximum number of days to keep log files is 7
long alloweddays = 7;
long alloweddays = 7;
File baseDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(ReportingConstants.REPORT_RESULTS_DIRECTORY_NAME);
File[] fList = baseDir.listFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ public interface ReportService extends OpenmrsService {
@Transactional(readOnly = true)
public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition, Date requestOnOrAfter, Date requestOnOrBefore, Status...statuses);

@Transactional
/**
* @return all {@link ReportRequest} in the system
* @should retrieve all report requests
*/
@Transactional(readOnly = true)
public List<ReportRequest> getAllReportRequests();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition,
return reportDAO.getReportRequests(reportDefinition, requestOnOrAfter, requestOnOrBefore, mostRecentNum, statuses);
}


/**
* @see ReportService#getReportRequests()
*/
@Transactional(readOnly=true)
public List<ReportRequest> getAllReportRequests(){
return reportDAO.getAllReportRequests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ public List<String> getReportRequestUuids(String reportDefinitionUuid) {
return query.list();
}


/**
* @see ReportDAO#getReportAllRequests()
*/
public List<ReportRequest> getAllReportRequests(){
String hql = "from ReportRequest";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public List<ReportDesign> getReportDesigns(ReportDefinition reportDefinition, Cl
*/
public ReportRequest getReportRequestByUuid(String uuid);

/**
* @returns all the {@link ReportRequestst}
*/
public List<ReportRequest> getAllReportRequests();

/**
Expand Down

0 comments on commit 98aca5d

Please sign in to comment.