|
24 | 24 | import java.nio.file.Files; |
25 | 25 | import java.util.Map; |
26 | 26 |
|
| 27 | +import org.assertj.core.api.Assertions; |
27 | 28 | import org.junit.Test; |
28 | 29 | import org.slf4j.Logger; |
29 | 30 | import org.slf4j.LoggerFactory; |
30 | 31 |
|
| 32 | +import org.apache.commons.lang3.StringUtils; |
31 | 33 | import org.apache.hadoop.fs.FileSystem; |
32 | 34 | import org.apache.hadoop.fs.Path; |
33 | 35 | import org.apache.hadoop.fs.s3a.AbstractS3ATestBase; |
34 | 36 | import org.apache.hadoop.fs.s3a.audit.mapreduce.S3AAuditLogMergerAndParser; |
| 37 | +import org.apache.hadoop.util.Preconditions; |
35 | 38 |
|
36 | 39 | /** |
37 | 40 | * This will implement different tests on S3AAuditLogMergerAndParser class. |
@@ -170,12 +173,14 @@ public void testParseAuditLog() { |
170 | 173 | public void testParseAuditLogEmptyAndNull() { |
171 | 174 | Map<String, String> parseAuditLogResultEmpty = |
172 | 175 | s3AAuditLogMergerAndParser.parseAuditLog(""); |
173 | | - assertTrue("the returned list should be empty for this test", |
174 | | - parseAuditLogResultEmpty.isEmpty()); |
| 176 | + Assertions.assertThat(parseAuditLogResultEmpty) |
| 177 | + .describedAs("Audit log map should be empty") |
| 178 | + .isEmpty(); |
175 | 179 | Map<String, String> parseAuditLogResultNull = |
176 | 180 | s3AAuditLogMergerAndParser.parseAuditLog(null); |
177 | | - assertTrue("the returned list should be empty for this test", |
178 | | - parseAuditLogResultNull.isEmpty()); |
| 181 | + Assertions.assertThat(parseAuditLogResultEmpty) |
| 182 | + .describedAs("Audit log map should be empty") |
| 183 | + .isEmpty(); |
179 | 184 | } |
180 | 185 |
|
181 | 186 | /** |
@@ -220,21 +225,30 @@ public void testParseReferrerHeaderEmptyAndNull() { |
220 | 225 | */ |
221 | 226 | @Test |
222 | 227 | public void testMergeAndParseAuditLogFiles() throws IOException { |
223 | | - sampleDir = Files.createTempDirectory("sampleDir").toFile(); |
224 | | - sampleFile = File.createTempFile("sampleFile", ".txt", sampleDir); |
225 | | - try (FileWriter fw = new FileWriter(sampleFile)) { |
226 | | - fw.write(SAMPLE_LOG_ENTRY); |
227 | | - fw.write(SAMPLE_LOG_ENTRY_1); |
228 | | - fw.flush(); |
229 | | - } |
| 228 | + // Getting the audit dir and file path from test/resources/ |
| 229 | + String auditLogDir = this.getClass().getClassLoader().getResource( |
| 230 | + "TestAuditLogs").toString(); |
| 231 | + String auditSingleFile = this.getClass().getClassLoader().getResource( |
| 232 | + "TestAuditLogs/sampleLog1").toString(); |
| 233 | + |
| 234 | + Preconditions.checkArgument(!StringUtils.isAnyBlank(auditLogDir, |
| 235 | + auditSingleFile), String.format("Audit path should not be empty. Check " |
| 236 | + + "test/resources. auditLogDir : %s, auditLogSingleFile :%s", |
| 237 | + auditLogDir, auditSingleFile)); |
| 238 | + Path auditDirPath = new Path(auditLogDir); |
| 239 | + Path auditFilePath = new Path(auditSingleFile); |
| 240 | + |
230 | 241 | sampleDestDir = Files.createTempDirectory("sampleDestDir").toFile(); |
231 | | - Path logsPath = new Path(sampleDir.toURI()); |
232 | 242 | Path destPath = new Path(sampleDestDir.toURI()); |
233 | | - FileSystem fileSystem = logsPath.getFileSystem(getConfiguration()); |
| 243 | + FileSystem fileSystem = auditFilePath.getFileSystem(getConfiguration()); |
234 | 244 | boolean mergeAndParseResult = |
235 | 245 | s3AAuditLogMergerAndParser.mergeAndParseAuditLogFiles(fileSystem, |
236 | | - logsPath, destPath); |
237 | | - assertTrue("the result should be true", mergeAndParseResult); |
| 246 | + auditDirPath, destPath); |
| 247 | + assertTrue("The merge and parse failed for the audit log", |
| 248 | + mergeAndParseResult); |
| 249 | + // 35 audit logs with referrer in each of the 2 sample files. |
| 250 | + assertEquals("", s3AAuditLogMergerAndParser.getAuditLogsParsed(), 36 + 36); |
| 251 | + assertEquals("", s3AAuditLogMergerAndParser.getReferrerHeaderLogParsed(), 36 + 36); |
238 | 252 | } |
239 | 253 |
|
240 | 254 | /** |
|
0 commit comments