Java Code Examples for com.amazonaws.services.s3.model.ObjectMetadata.setLastModified()

The following are Jave code examples for showing how to use setLastModified() of the com.amazonaws.services.s3.model.ObjectMetadata class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: rxjava2-aws   File: SqsTest.java   View Source Code Vote up 4 votes
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneViaS3() throws UnsupportedEncodingException {
    final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
    final AmazonS3Client s3 = Mockito.mock(AmazonS3Client.class);
    final String queueName = "queue";
    final String s3Id = "123";
    Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
    final String receiptHandle = "abc";
    Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any())).thenReturn(
            new ReceiveMessageResult().withMessages(new Message().withReceiptHandle(receiptHandle).withBody(s3Id)));
    final String bucketName = "bucket";
    Mockito.when(s3.doesObjectExist(bucketName, s3Id)).thenAnswer(x -> true);
    final S3Object s3Object = mock(S3Object.class);
    Mockito.when(s3Object.getObjectContent())
            .thenReturn(new S3ObjectInputStream(new StringInputStream("body1"), null));
    final ObjectMetadata om = new ObjectMetadata();
    om.setLastModified(new Date(1001));
    Mockito.when(s3Object.getObjectMetadata()).thenReturn(om);
    Mockito.when(s3.getObject(bucketName, s3Id)).thenReturn(s3Object);
    Sqs.queueName(queueName) //
            .sqsFactory(() -> sqs) //
            .bucketName("bucket") //
            .s3Factory(() -> s3) //
            .messages() //
            .doOnNext(SqsMessage::deleteMessage) //
            .map(m -> m.message()) //
            .doOnError(Throwable::printStackTrace) //
            .take(1) //
            .test() //
            .awaitDone(10, TimeUnit.SECONDS) //
            .assertComplete() //
            .assertValues("body1");
    final InOrder inorder = Mockito.inOrder(sqs, s3, s3Object);
    inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
    inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(s3, Mockito.times(1)).doesObjectExist(bucketName, s3Id);
    inorder.verify(s3, Mockito.times(1)).getObject(bucketName, s3Id);
    inorder.verify(s3Object, Mockito.times(1)).getObjectContent();
    inorder.verify(s3Object, Mockito.times(1)).getObjectMetadata();
    inorder.verify(s3, Mockito.times(1)).deleteObject(bucketName, s3Id);
    inorder.verify(sqs, Mockito.times(1)).deleteMessage(queueName, receiptHandle);
    inorder.verify(sqs, Mockito.times(1)).shutdown();
    inorder.verify(s3, Mockito.times(1)).shutdown();
    inorder.verifyNoMoreInteractions();
}
 
Example 2
Project: rxjava2-aws   File: SqsTest.java   View Source Code Vote up 4 votes
@Test(timeout = 50000000)
public void testFirstCallToReceiveMessagesReturnsOneWithNoS3ObjectAndOneWithS3Object()
        throws UnsupportedEncodingException {
    final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
    final AmazonS3Client s3 = Mockito.mock(AmazonS3Client.class);
    final String queueName = "queue";
    final String s3Id = "123";
    final String s3Id2 = "124";
    Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
    final String receiptHandle = "abc";
    final String receiptHandle2 = "abc2";
    Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
            .thenReturn(new ReceiveMessageResult()
                    .withMessages(new Message().withReceiptHandle(receiptHandle).withBody(s3Id)))
            .thenReturn(new ReceiveMessageResult()
                    .withMessages(new Message().withReceiptHandle(receiptHandle2).withBody(s3Id2)));
    final String bucketName = "bucket";
    Mockito.when(s3.doesObjectExist(bucketName, s3Id)).thenReturn(false);
    Mockito.when(s3.doesObjectExist(bucketName, s3Id2)).thenReturn(true);
    final S3Object s3Object = mock(S3Object.class);
    Mockito.when(s3Object.getObjectContent())
            .thenReturn(new S3ObjectInputStream(new StringInputStream("body2"), null));
    final ObjectMetadata om = new ObjectMetadata();
    om.setLastModified(new Date(1001));
    Mockito.when(s3Object.getObjectMetadata()).thenReturn(om);
    Mockito.when(s3.getObject(bucketName, s3Id2)).thenReturn(s3Object);
    Sqs.queueName(queueName) //
            .sqsFactory(() -> sqs) //
            .bucketName("bucket") //
            .s3Factory(() -> s3) //
            .messages() //
            .doOnNext(SqsMessage::deleteMessage) //
            .map(m -> m.message()) //
            .doOnError(Throwable::printStackTrace) //
            .take(1) //
            .test() //
            .awaitDone(10, TimeUnit.SECONDS) //
            .assertComplete() //
            .assertValues("body2");
    final InOrder inorder = Mockito.inOrder(sqs, s3, s3Object);
    inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
    inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(s3, Mockito.times(1)).doesObjectExist(bucketName, s3Id);
    inorder.verify(sqs, Mockito.times(1)).deleteMessage(queueName, receiptHandle);
    inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(s3, Mockito.times(1)).doesObjectExist(bucketName, s3Id2);
    inorder.verify(s3, Mockito.times(1)).getObject(bucketName, s3Id2);
    inorder.verify(s3Object, Mockito.times(1)).getObjectContent();
    inorder.verify(s3Object, Mockito.times(1)).getObjectMetadata();
    inorder.verify(s3, Mockito.times(1)).deleteObject(bucketName, s3Id2);
    inorder.verify(sqs, Mockito.times(1)).deleteMessage(queueName, receiptHandle2);
    inorder.verify(sqs, Mockito.times(1)).shutdown();
    inorder.verify(s3, Mockito.times(1)).shutdown();
    inorder.verifyNoMoreInteractions();
}