I am writing test case to test DynamodbMapper functionality as given below:
def batchSaveInDDB[T](itemList: List[T]): List[FailedBatch] = AWSSession.dynamoDBMapperDaxEnabled.batchSave(itemList)
This is how mapper created:
object DynamoDBResource extends Logger {
@throws(classOf[AmazonDynamoDBException])
def getDynamoDBMapperDAXEnabled(region: String): DynamoDBMapper = {
new DynamoDBMapper(getDaxClient(region,
"*****************"))
}
def getAWSCredentialsProvider(): AWSCredentialsProvider = {
new EC2ContainerCredentialsProviderWrapper()
}
def getDaxClient(region: String, clusterEndpoint: String): AmazonDynamoDB = {
AmazonDaxClientBuilder
.standard()
.withRegion(region)
.withCredentials(getAWSCredentialsProvider())
.withEndpointConfiguration(clusterEndpoint)
.build()
}}
Test case:
@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[AmazonDaxClientBuilder]))
class MockDynamodbDax extends FlatSpec with Matchers{
def init(): Unit = {
val amazonDaxClientBuilder: AmazonDaxClientBuilder =
PowerMockito.mock(classOf[AmazonDaxClientBuilder])
PowerMockito.mockStatic(classOf[AmazonDaxClientBuilder])
when(AmazonDaxClientBuilder.standard()).thenReturn(amazonDaxClientBuilder)
when(amazonDaxClientBuilder.withCredentials(any(classOf[AWSCredentialsProvider])))
.thenReturn(amazonDaxClientBuilder)
when(amazonDaxClientBuilder.withEndpointConfiguration(anyString()))
.thenReturn(amazonDaxClientBuilder) }
"DDBOperations" should "throw NullPointerException for null data save" in {
init()
the[RuntimeException] thrownBy {
DDBOperations.batchSaveInDDB(null)
} should have message null
}
"DDBOperations" should "not save duplicate keys and return as FailedBatch" in {
init()
val employeeDataList = new ArrayList[AnytimePayEmployeeJobData]
employeeDataList.add(getEmployeeJobData(TEST_EMP_ID_1, EFF_END_DATE_1))
employeeDataList.add(getEmployeeJobData(TEST_EMP_ID_1, EFF_END_DATE_2))
val upsertsFailedBatches: List[FailedBatch] = DDBOperations.batchSaveInDDB(employeeDataList)
assert(upsertsFailedBatches.size() == FAILED_RECORDS_COUNT)}}
I am getting this exceptions:
should throw NullPointerException for null data save * FAILED * (17 milliseconds) [scalatest] java.lang.IllegalArgumentException: Cannot subclass final class class com.amazon.dax.client.dynamodbv2.AmazonDaxClientBuilder