This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving unit test coverage for Cerberus server (#445)
- Loading branch information
Showing
16 changed files
with
850 additions
and
18 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
...hena/src/test/java/ch/qos/logback/core/rolling/AuditLogsS3TimeBasedRollingPolicyTest.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,76 @@ | ||
package ch.qos.logback.core.rolling; | ||
|
||
import com.nike.cerberus.audit.logger.service.S3LogUploaderService; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class AuditLogsS3TimeBasedRollingPolicyTest { | ||
|
||
private AuditLogsS3TimeBasedRollingPolicy auditLogsS3TimeBasedRollingPolicy; | ||
|
||
@Test | ||
public void testLogUploaderServiceIfLogChunkFileS3QueueIsEmpty() { | ||
auditLogsS3TimeBasedRollingPolicy = | ||
new AuditLogsS3TimeBasedRollingPolicy("bucket", "bucketRegion"); | ||
S3LogUploaderService s3LogUploaderService = Mockito.mock(S3LogUploaderService.class); | ||
auditLogsS3TimeBasedRollingPolicy.setS3LogUploaderService(s3LogUploaderService); | ||
Mockito.verify(s3LogUploaderService, Mockito.never()).ingestLog(Mockito.anyString()); | ||
} | ||
|
||
@Test | ||
public void testRollOverIfAuditCopyIsNotEnabled() { | ||
auditLogsS3TimeBasedRollingPolicy = Mockito.spy(new AuditLogsS3TimeBasedRollingPolicy("", "")); | ||
Mockito.doNothing().when(auditLogsS3TimeBasedRollingPolicy).superRollOver(); | ||
S3LogUploaderService s3LogUploaderService = Mockito.mock(S3LogUploaderService.class); | ||
auditLogsS3TimeBasedRollingPolicy.setS3LogUploaderService(s3LogUploaderService); | ||
TimeBasedFileNamingAndTriggeringPolicy timeBasedFileNamingAndTriggeringPolicy = | ||
Mockito.spy(TimeBasedFileNamingAndTriggeringPolicy.class); | ||
auditLogsS3TimeBasedRollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy( | ||
timeBasedFileNamingAndTriggeringPolicy); | ||
auditLogsS3TimeBasedRollingPolicy.rollover(); | ||
Mockito.verify(timeBasedFileNamingAndTriggeringPolicy, Mockito.never()) | ||
.getElapsedPeriodsFileName(); | ||
Mockito.verify(s3LogUploaderService, Mockito.never()).ingestLog(Mockito.anyString()); | ||
} | ||
|
||
@Test | ||
public void testRollOverIfAuditCopyIsEnabled() { | ||
auditLogsS3TimeBasedRollingPolicy = | ||
Mockito.spy(new AuditLogsS3TimeBasedRollingPolicy("bucket", "region")); | ||
Mockito.doNothing().when(auditLogsS3TimeBasedRollingPolicy).superRollOver(); | ||
S3LogUploaderService s3LogUploaderService = Mockito.mock(S3LogUploaderService.class); | ||
auditLogsS3TimeBasedRollingPolicy.setS3LogUploaderService(s3LogUploaderService); | ||
TimeBasedFileNamingAndTriggeringPolicy timeBasedFileNamingAndTriggeringPolicy = | ||
Mockito.spy(TimeBasedFileNamingAndTriggeringPolicy.class); | ||
Mockito.when(timeBasedFileNamingAndTriggeringPolicy.getElapsedPeriodsFileName()) | ||
.thenReturn("elapsedfilename"); | ||
auditLogsS3TimeBasedRollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy( | ||
timeBasedFileNamingAndTriggeringPolicy); | ||
LinkedBlockingQueue<String> logChunkFileS3Queue = new LinkedBlockingQueue<>(); | ||
auditLogsS3TimeBasedRollingPolicy.setLogChunkFileS3Queue(logChunkFileS3Queue); | ||
auditLogsS3TimeBasedRollingPolicy.rollover(); | ||
Mockito.verify(timeBasedFileNamingAndTriggeringPolicy).getElapsedPeriodsFileName(); | ||
Mockito.verify(s3LogUploaderService).ingestLog("elapsedfilename.gz"); | ||
Assert.assertTrue(logChunkFileS3Queue.size() == 0); | ||
} | ||
|
||
@Test | ||
public void testRollOverIfAuditCopyIsEnabledAndS3UploaderIsNull() { | ||
auditLogsS3TimeBasedRollingPolicy = | ||
Mockito.spy(new AuditLogsS3TimeBasedRollingPolicy("bucket", "region")); | ||
Mockito.doNothing().when(auditLogsS3TimeBasedRollingPolicy).superRollOver(); | ||
TimeBasedFileNamingAndTriggeringPolicy timeBasedFileNamingAndTriggeringPolicy = | ||
Mockito.spy(TimeBasedFileNamingAndTriggeringPolicy.class); | ||
Mockito.when(timeBasedFileNamingAndTriggeringPolicy.getElapsedPeriodsFileName()) | ||
.thenReturn("elapsedfilename"); | ||
auditLogsS3TimeBasedRollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy( | ||
timeBasedFileNamingAndTriggeringPolicy); | ||
LinkedBlockingQueue<String> logChunkFileS3Queue = new LinkedBlockingQueue<>(); | ||
auditLogsS3TimeBasedRollingPolicy.setLogChunkFileS3Queue(logChunkFileS3Queue); | ||
auditLogsS3TimeBasedRollingPolicy.rollover(); | ||
Mockito.verify(timeBasedFileNamingAndTriggeringPolicy).getElapsedPeriodsFileName(); | ||
Assert.assertTrue(logChunkFileS3Queue.size() > 0); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...t-logger-athena/src/test/java/com/nike/cerberus/audit/logger/AthenaClientFactoryTest.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,28 @@ | ||
package com.nike.cerberus.audit.logger; | ||
|
||
import com.amazonaws.services.athena.AmazonAthena; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class AthenaClientFactoryTest { | ||
|
||
@Test | ||
public void testGetClientAlwaysReturnsSameAthenaInstance() { | ||
AthenaClientFactory athenaClientFactory = new AthenaClientFactory(); | ||
AmazonAthena clientInstance1 = athenaClientFactory.getClient("region-2"); | ||
AmazonAthena clientInstance2 = athenaClientFactory.getClient("region-2"); | ||
Assert.assertSame(clientInstance1, clientInstance2); | ||
} | ||
|
||
@Test | ||
public void testGetClientDoesNotThrowNPEWhenRegionIsEmptyString() { | ||
AthenaClientFactory athenaClientFactory = new AthenaClientFactory(); | ||
athenaClientFactory.getClient(""); | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void testGetClientThrowsNPEWhenRegionIsNull() { | ||
AthenaClientFactory athenaClientFactory = new AthenaClientFactory(); | ||
athenaClientFactory.getClient(null); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...audit-logger-athena/src/test/java/com/nike/cerberus/audit/logger/S3ClientFactoryTest.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,28 @@ | ||
package com.nike.cerberus.audit.logger; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class S3ClientFactoryTest { | ||
|
||
@Test | ||
public void testS3ClientFactoryAlwaysReturnSameInstance() { | ||
S3ClientFactory s3ClientFactory = new S3ClientFactory(); | ||
AmazonS3 s3Instance1 = s3ClientFactory.getClient("region-1"); | ||
AmazonS3 s3Instance2 = s3ClientFactory.getClient("region-1"); | ||
Assert.assertSame(s3Instance1, s3Instance2); | ||
} | ||
|
||
@Test | ||
public void testS3ClientFactoryDoesNotThrowsNPEWhenEmptyStringIsPassedAsRegion() { | ||
S3ClientFactory s3ClientFactory = new S3ClientFactory(); | ||
s3ClientFactory.getClient(""); | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void testS3ClientFactoryThrowsNPEWhenNullRegionIsPassed() { | ||
S3ClientFactory s3ClientFactory = new S3ClientFactory(); | ||
s3ClientFactory.getClient(null); | ||
} | ||
} |
Oops, something went wrong.