-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
api-tests/src/test/java/org/openmrs/module/reporting/evaluation/DeleteOldLogsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters