com.amazonaws.services.s3.model.GetObjectMetadataRequest Java Examples

The following examples show how to use com.amazonaws.services.s3.model.GetObjectMetadataRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleStorageProtocolResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void testGetResourceWithExistingResource() {

	AmazonS3 amazonS3 = mock(AmazonS3.class);

	DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
	resourceLoader.addProtocolResolver(new SimpleStorageProtocolResolver(amazonS3));

	ObjectMetadata metadata = new ObjectMetadata();
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(metadata);

	String resourceName = "s3://bucket/object/";
	Resource resource = resourceLoader.getResource(resourceName);
	assertThat(resource).isNotNull();
}
 
Example #2
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void createRelative_existingObject_returnsRelativeCreatedFile() throws IOException {

	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(new ObjectMetadata());
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Act
	SimpleStorageResource subObject = simpleStorageResource
			.createRelative("subObject");

	// Assert
	assertThat(subObject.getFilename()).isEqualTo("object/subObject");
}
 
Example #3
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void getInputStream_existingObject_returnsInputStreamWithContent() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	ObjectMetadata objectMetadata = mock(ObjectMetadata.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(objectMetadata);

	S3Object s3Object = new S3Object();
	s3Object.setObjectMetadata(objectMetadata);
	s3Object.setObjectContent(new ByteArrayInputStream(new byte[] { 42 }));
	when(amazonS3.getObject(any(GetObjectRequest.class))).thenReturn(s3Object);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.exists()).isTrue();
	assertThat(simpleStorageResource.getInputStream().read()).isEqualTo(42);
}
 
Example #4
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void lastModified_withExistingResource_returnsLastModifiedDateOfResource()
		throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	ObjectMetadata objectMetadata = new ObjectMetadata();
	Date lastModified = new Date();
	objectMetadata.setLastModified(lastModified);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(objectMetadata);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.lastModified())
			.isEqualTo(lastModified.getTime());
}
 
Example #5
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void contentLength_withExistingResource_returnsContentLengthOfObjectMetaData()
		throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	ObjectMetadata objectMetadata = new ObjectMetadata();
	objectMetadata.setContentLength(1234L);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(objectMetadata);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.contentLength()).isEqualTo(1234L);
}
 
Example #6
Source File: SimpleStorageResource.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
private ObjectMetadata getObjectMetadata() {
	if (this.objectMetadata == null) {
		try {
			GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(
					this.bucketName, this.objectName);
			if (this.versionId != null) {
				metadataRequest.setVersionId(this.versionId);
			}
			this.objectMetadata = this.amazonS3.getObjectMetadata(metadataRequest);
		}
		catch (AmazonS3Exception e) {
			// Catch 404 (object not found) and 301 (bucket not found, moved
			// permanently)
			if (e.getStatusCode() == 404 || e.getStatusCode() == 301) {
				this.objectMetadata = null;
			}
			else {
				throw e;
			}
		}
	}
	return this.objectMetadata;
}
 
Example #7
Source File: S3WaitOperatorFactoryTest.java    From digdag with Apache License 2.0 6 votes vote down vote up
@Test
public void testSSEC()
        throws Exception
{
    Config config = newConfig();
    config.set("_command", BUCKET + "/" + KEY);
    when(taskRequest.getConfig()).thenReturn(config);

    when(s3Secrets.getSecretOptional("sse_c_key")).thenReturn(Optional.of(SSE_C_KEY));

    when(s3Client.getObjectMetadata(objectMetadataRequestCaptor.capture())).thenThrow(NOT_FOUND_EXCEPTION);

    Operator operator = factory.newOperator(newContext(projectPath, taskRequest));

    try {
        operator.run();
        fail();
    }
    catch (TaskExecutionException ignore) {
    }

    GetObjectMetadataRequest objectMetadataRequest = objectMetadataRequestCaptor.getValue();
    assertThat(objectMetadataRequest.getSSECustomerKey().getKey(), is(SSE_C_KEY));
    assertThat(objectMetadataRequest.getSSECustomerKey().getAlgorithm(), is("AES256"));
    assertThat(objectMetadataRequest.getSSECustomerKey().getMd5(), is(nullValue()));
}
 
Example #8
Source File: S3WaitOperatorFactoryTest.java    From digdag with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersionId()
        throws Exception
{
    Config config = newConfig();
    config.set("_command", BUCKET + "/" + KEY);
    config.set("version_id", VERSION_ID);
    when(taskRequest.getConfig()).thenReturn(config);

    when(s3Secrets.getSecretOptional("region")).thenReturn(Optional.of(REGION));

    when(s3Client.getObjectMetadata(objectMetadataRequestCaptor.capture())).thenThrow(NOT_FOUND_EXCEPTION);

    Operator operator = factory.newOperator(newContext(projectPath, taskRequest));

    try {
        operator.run();
        fail();
    }
    catch (TaskExecutionException ignore) {
    }

    GetObjectMetadataRequest objectMetadataRequest = objectMetadataRequestCaptor.getValue();

    assertThat(objectMetadataRequest.getVersionId(), is(VERSION_ID));
}
 
Example #9
Source File: SimpleStorageProtocolResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void testGetResourceWithVersionId() {
	AmazonS3 amazonS3 = mock(AmazonS3.class);

	SimpleStorageProtocolResolver resourceLoader = new SimpleStorageProtocolResolver(
			amazonS3);

	ObjectMetadata metadata = new ObjectMetadata();

	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(metadata);

	String resourceName = "s3://bucket/object^versionIdValue";
	Resource resource = resourceLoader.resolve(resourceName,
			new DefaultResourceLoader());
	assertThat(resource).isNotNull();
}
 
Example #10
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void matchNonGlobForbidden() {
  S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());

  AmazonS3Exception exception = new AmazonS3Exception("mock exception");
  exception.setStatusCode(403);
  S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/keyname");
  when(s3FileSystem
          .getAmazonS3Client()
          .getObjectMetadata(
              argThat(
                  new GetObjectMetadataRequestMatcher(
                      new GetObjectMetadataRequest(path.getBucket(), path.getKey())))))
      .thenThrow(exception);

  assertThat(
      s3FileSystem.matchNonGlobPath(path),
      MatchResultMatcher.create(MatchResult.Status.ERROR, new IOException(exception)));
}
 
Example #11
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void matchNonGlobNotFound() {
  S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());

  S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/nonexistentfile");
  AmazonS3Exception exception = new AmazonS3Exception("mock exception");
  exception.setStatusCode(404);
  when(s3FileSystem
          .getAmazonS3Client()
          .getObjectMetadata(
              argThat(
                  new GetObjectMetadataRequestMatcher(
                      new GetObjectMetadataRequest(path.getBucket(), path.getKey())))))
      .thenThrow(exception);

  MatchResult result = s3FileSystem.matchNonGlobPath(path);
  assertThat(
      result,
      MatchResultMatcher.create(MatchResult.Status.NOT_FOUND, new FileNotFoundException()));
}
 
Example #12
Source File: PathMatchingSimpleStorageResourcePatternResolverTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
private AmazonS3 prepareMockForTestWildcardInBucketName() {
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.listBuckets()).thenReturn(
			Arrays.asList(new Bucket("myBucketOne"), new Bucket("myBucketTwo"),
					new Bucket("anotherBucket"), new Bucket("myBuckez")));

	// Mocks for the '**' case
	ObjectListing objectListingWithOneFile = createObjectListingMock(
			Collections.singletonList(createS3ObjectSummaryWithKey("test.txt")),
			Collections.emptyList(), false);
	ObjectListing emptyObjectListing = createObjectListingMock(
			Collections.emptyList(), Collections.emptyList(), false);
	when(amazonS3.listObjects(
			argThat(new ListObjectsRequestMatcher("myBucketOne", null, null))))
					.thenReturn(objectListingWithOneFile);
	when(amazonS3.listObjects(
			argThat(new ListObjectsRequestMatcher("myBucketTwo", null, null))))
					.thenReturn(emptyObjectListing);
	when(amazonS3.listObjects(
			argThat(new ListObjectsRequestMatcher("anotherBucket", null, null))))
					.thenReturn(objectListingWithOneFile);
	when(amazonS3.listObjects(
			argThat(new ListObjectsRequestMatcher("myBuckez", null, null))))
					.thenReturn(emptyObjectListing);

	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(new ObjectMetadata());
	return amazonS3;
}
 
Example #13
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void lastModified_fileDoestNotExist_reportsError() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(null);

	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThatThrownBy(simpleStorageResource::lastModified)
			.isInstanceOf(FileNotFoundException.class)
			.hasMessageContaining("not found");
}
 
Example #14
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void contentLength_fileDoesNotExists_reportsError() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(null);
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThatThrownBy(simpleStorageResource::contentLength)
			.isInstanceOf(FileNotFoundException.class)
			.hasMessageContaining("not found");

}
 
Example #15
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getFileName_existingObject_returnsFileNameWithoutBucketNameFromParameterWithoutActuallyFetchingTheFile()
		throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(null);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.getFilename()).isEqualTo("object");
}
 
Example #16
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private GetObjectMetadataRequest createObjectMetadataRequest(
    S3ResourceId path, S3Options options) {
  GetObjectMetadataRequest getObjectMetadataRequest =
      new GetObjectMetadataRequest(path.getBucket(), path.getKey());
  getObjectMetadataRequest.setSSECustomerKey(options.getSSECustomerKey());
  return getObjectMetadataRequest;
}
 
Example #17
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void exists_withoutExistingObjectMetadata_returnsFalse() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(null);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Act
	assertThat(simpleStorageResource.exists()).isFalse();
}
 
Example #18
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void exists_withExistingObjectMetadata_returnsTrue() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(new ObjectMetadata());

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.exists()).isTrue();
}
 
Example #19
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private void assertGetObjectMetadata(
    S3FileSystem s3FileSystem,
    GetObjectMetadataRequest request,
    S3Options options,
    ObjectMetadata objectMetadata) {
  when(s3FileSystem
          .getAmazonS3Client()
          .getObjectMetadata(argThat(new GetObjectMetadataRequestMatcher(request))))
      .thenReturn(objectMetadata);
  assertEquals(
      getSSECustomerKeyMd5(options),
      s3FileSystem.getAmazonS3Client().getObjectMetadata(request).getSSECustomerKeyMd5());
}
 
Example #20
Source File: S3WaitOperatorFactoryTest.java    From digdag with Apache License 2.0 5 votes vote down vote up
@Test
public void testSSECWithAlgorithmAndMd5()
        throws Exception
{
    Config config = newConfig();
    config.set("_command", BUCKET + "/" + KEY);
    when(taskRequest.getConfig()).thenReturn(config);

    when(s3Secrets.getSecretOptional("sse_c_key")).thenReturn(Optional.of(SSE_C_KEY));
    when(s3Secrets.getSecretOptional("sse_c_key_algorithm")).thenReturn(Optional.of(SSE_C_KEY_ALGORITHM));
    when(s3Secrets.getSecretOptional("sse_c_key_md5")).thenReturn(Optional.of(SSE_C_KEY_MD5));

    when(s3Client.getObjectMetadata(objectMetadataRequestCaptor.capture())).thenThrow(NOT_FOUND_EXCEPTION);

    Operator operator = factory.newOperator(newContext(projectPath, taskRequest));

    try {
        operator.run();
        fail();
    }
    catch (TaskExecutionException ignore) {
    }

    GetObjectMetadataRequest objectMetadataRequest = objectMetadataRequestCaptor.getValue();
    assertThat(objectMetadataRequest.getSSECustomerKey().getKey(), is(SSE_C_KEY));
    assertThat(objectMetadataRequest.getSSECustomerKey().getAlgorithm(), is(SSE_C_KEY_ALGORITHM));
    assertThat(objectMetadataRequest.getSSECustomerKey().getMd5(), is(SSE_C_KEY_MD5));
}
 
Example #21
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void matchNonGlob() {
  S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());

  S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/filethatexists");
  long lastModifiedMillis = 1540000000000L;
  ObjectMetadata s3ObjectMetadata = new ObjectMetadata();
  s3ObjectMetadata.setContentLength(100);
  s3ObjectMetadata.setContentEncoding("read-seek-efficient");
  s3ObjectMetadata.setLastModified(new Date(lastModifiedMillis));
  when(s3FileSystem
          .getAmazonS3Client()
          .getObjectMetadata(
              argThat(
                  new GetObjectMetadataRequestMatcher(
                      new GetObjectMetadataRequest(path.getBucket(), path.getKey())))))
      .thenReturn(s3ObjectMetadata);

  MatchResult result = s3FileSystem.matchNonGlobPath(path);
  assertThat(
      result,
      MatchResultMatcher.create(
          ImmutableList.of(
              MatchResult.Metadata.builder()
                  .setSizeBytes(100)
                  .setLastModifiedMillis(lastModifiedMillis)
                  .setResourceId(path)
                  .setIsReadSeekEfficient(true)
                  .build())));
}
 
Example #22
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void matchNonGlobNotReadSeekEfficient() {
  S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());

  S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/filethatexists");
  long lastModifiedMillis = 1540000000000L;
  ObjectMetadata s3ObjectMetadata = new ObjectMetadata();
  s3ObjectMetadata.setContentLength(100);
  s3ObjectMetadata.setLastModified(new Date(lastModifiedMillis));
  s3ObjectMetadata.setContentEncoding("gzip");
  when(s3FileSystem
          .getAmazonS3Client()
          .getObjectMetadata(
              argThat(
                  new GetObjectMetadataRequestMatcher(
                      new GetObjectMetadataRequest(path.getBucket(), path.getKey())))))
      .thenReturn(s3ObjectMetadata);

  MatchResult result = s3FileSystem.matchNonGlobPath(path);
  assertThat(
      result,
      MatchResultMatcher.create(
          ImmutableList.of(
              MatchResult.Metadata.builder()
                  .setSizeBytes(100)
                  .setLastModifiedMillis(lastModifiedMillis)
                  .setResourceId(path)
                  .setIsReadSeekEfficient(false)
                  .build())));
}
 
Example #23
Source File: TestPrestoS3FileSystem.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyDirectory()
        throws Exception
{
    try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
        MockAmazonS3 s3 = new MockAmazonS3()
        {
            @Override
            public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest)
            {
                if (getObjectMetadataRequest.getKey().equals("empty-dir/")) {
                    ObjectMetadata objectMetadata = new ObjectMetadata();
                    objectMetadata.setContentType(S3_DIRECTORY_OBJECT_CONTENT_TYPE);
                    return objectMetadata;
                }
                return super.getObjectMetadata(getObjectMetadataRequest);
            }
        };
        fs.initialize(new URI("s3n://test-bucket/"), new Configuration(false));
        fs.setS3Client(s3);

        FileStatus fileStatus = fs.getFileStatus(new Path("s3n://test-bucket/empty-dir/"));
        assertTrue(fileStatus.isDirectory());

        fileStatus = fs.getFileStatus(new Path("s3n://test-bucket/empty-dir"));
        assertTrue(fileStatus.isDirectory());
    }
}
 
Example #24
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void matchNonGlobNullContentEncoding() {
  S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());

  S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/filethatexists");
  long lastModifiedMillis = 1540000000000L;
  ObjectMetadata s3ObjectMetadata = new ObjectMetadata();
  s3ObjectMetadata.setContentLength(100);
  s3ObjectMetadata.setLastModified(new Date(lastModifiedMillis));
  s3ObjectMetadata.setContentEncoding(null);
  when(s3FileSystem
          .getAmazonS3Client()
          .getObjectMetadata(
              argThat(
                  new GetObjectMetadataRequestMatcher(
                      new GetObjectMetadataRequest(path.getBucket(), path.getKey())))))
      .thenReturn(s3ObjectMetadata);

  MatchResult result = s3FileSystem.matchNonGlobPath(path);
  assertThat(
      result,
      MatchResultMatcher.create(
          ImmutableList.of(
              MatchResult.Metadata.builder()
                  .setSizeBytes(100)
                  .setLastModifiedMillis(lastModifiedMillis)
                  .setResourceId(path)
                  .setIsReadSeekEfficient(true)
                  .build())));
}
 
Example #25
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matches(GetObjectMetadataRequest obj) {
  if (!(obj instanceof GetObjectMetadataRequest)) {
    return false;
  }
  GetObjectMetadataRequest actual = (GetObjectMetadataRequest) obj;
  return actual.getBucketName().equals(expected.getBucketName())
      && actual.getKey().equals(expected.getKey());
}
 
Example #26
Source File: TestListS3.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteUserMetadata() {
    runner.setProperty(ListS3.REGION, "eu-west-1");
    runner.setProperty(ListS3.BUCKET, "test-bucket");
    runner.setProperty(ListS3.WRITE_USER_METADATA, "true");

    Date lastModified = new Date();
    ObjectListing objectListing = new ObjectListing();
    S3ObjectSummary objectSummary1 = new S3ObjectSummary();
    objectSummary1.setBucketName("test-bucket");
    objectSummary1.setKey("a");
    objectSummary1.setLastModified(lastModified);
    objectListing.getObjectSummaries().add(objectSummary1);

    Mockito.when(mockS3Client.listObjects(Mockito.any(ListObjectsRequest.class))).thenReturn(objectListing);

    runner.run();

    ArgumentCaptor<GetObjectMetadataRequest> captureRequest = ArgumentCaptor.forClass(GetObjectMetadataRequest.class);
    Mockito.verify(mockS3Client, Mockito.times(1)).getObjectMetadata(captureRequest.capture());
    GetObjectMetadataRequest request = captureRequest.getValue();

    assertEquals("test-bucket", request.getBucketName());
    assertEquals("a", request.getKey());

    Mockito.verify(mockS3Client, Mockito.never()).listVersions(Mockito.any());
}
 
Example #27
Source File: MockAmazonS3.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest)
{
    this.getObjectMetadataRequest = getObjectMetadataRequest;
    if (getObjectMetadataHttpCode != HTTP_OK) {
        AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode);
        exception.setStatusCode(getObjectMetadataHttpCode);
        throw exception;
    }
    return null;
}
 
Example #28
Source File: PathMatchingSimpleStorageResourcePatternResolverTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
private AmazonS3 prepareMockForTestTruncatedListings() {
	AmazonS3 amazonS3 = mock(AmazonS3.class);

	// Without prefix calls
	ObjectListing objectListingWithoutPrefixPart1 = createObjectListingMock(
			Arrays.asList(createS3ObjectSummaryWithKey("fooOne/barOne/test.txt"),
					createS3ObjectSummaryWithKey("fooOne/bazOne/test.txt"),
					createS3ObjectSummaryWithKey("fooTwo/barTwo/test.txt")),
			Collections.emptyList(), true);
	when(amazonS3.listObjects(
			argThat(new ListObjectsRequestMatcher("myBucket", null, null))))
					.thenReturn(objectListingWithoutPrefixPart1);

	ObjectListing objectListingWithoutPrefixPart2 = createObjectListingMock(
			Arrays.asList(createS3ObjectSummaryWithKey("fooThree/baz/test.txt"),
					createS3ObjectSummaryWithKey("foFour/barFour/test.txt")),
			Collections.emptyList(), false);
	when(amazonS3.listNextBatchOfObjects(objectListingWithoutPrefixPart1))
			.thenReturn(objectListingWithoutPrefixPart2);

	// With prefix calls
	ObjectListing objectListingWithPrefixPart1 = createObjectListingMock(
			Collections.emptyList(), Arrays.asList("dooOne/", "dooTwo/"), true);
	when(amazonS3.listObjects(
			argThat(new ListObjectsRequestMatcher("myBucket", null, "/"))))
					.thenReturn(objectListingWithPrefixPart1);

	ObjectListing objectListingWithPrefixPart2 = createObjectListingMock(
			Collections.emptyList(), Collections.singletonList("fooOne/"), false);
	when(amazonS3.listNextBatchOfObjects(objectListingWithPrefixPart1))
			.thenReturn(objectListingWithPrefixPart2);

	ObjectListing objectListingWithPrefixFooOne = createObjectListingMock(
			Collections.emptyList(), Collections.singletonList("fooOne/barOne/"),
			false);
	when(amazonS3.listObjects(
			argThat(new ListObjectsRequestMatcher("myBucket", "fooOne/", "/"))))
					.thenReturn(objectListingWithPrefixFooOne);

	ObjectListing objectListingWithPrefixFooOneBarOne = createObjectListingMock(
			Collections.singletonList(
					createS3ObjectSummaryWithKey("fooOne/barOne/test.txt")),
			Collections.emptyList(), false);
	when(amazonS3.listObjects(argThat(
			new ListObjectsRequestMatcher("myBucket", "fooOne/barOne/", "/"))))
					.thenReturn(objectListingWithPrefixFooOneBarOne);

	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(new ObjectMetadata());

	return amazonS3;
}
 
Example #29
Source File: MockAmazonS3.java    From presto with Apache License 2.0 4 votes vote down vote up
public GetObjectMetadataRequest getGetObjectMetadataRequest()
{
    return getObjectMetadataRequest;
}
 
Example #30
Source File: AmazonS3Mock.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest)
    throws AmazonClientException, AmazonServiceException {
  // TODO Auto-generated method stub
  return null;
}