/** * Verify that buckets can be created and listed */ @Test public void shouldCreateBucketAndListAllBuckets() { // the returned creation date might strip off the millisecond-part, resulting in rounding down // and account for a clock-skew in the Docker container of up to a minute. final Date creationDate = new Date((System.currentTimeMillis() / 1000) * 1000 - 60000); final Bucket bucket = s3Client.createBucket(BUCKET_NAME); assertThat( String.format("Bucket name should match '%s'!", BUCKET_NAME), bucket.getName(), equalTo(BUCKET_NAME)); final List<Bucket> buckets = s3Client.listBuckets().stream().filter(b -> BUCKET_NAME.equals(b.getName())) .collect(Collectors.toList()); assertThat("Expecting one bucket", buckets, hasSize(1)); final Bucket createdBucket = buckets.get(0); assertThat(createdBucket.getCreationDate(), greaterThanOrEqualTo(creationDate)); final Owner bucketOwner = createdBucket.getOwner(); assertThat(bucketOwner.getDisplayName(), equalTo("s3-mock-file-store")); assertThat(bucketOwner.getId(), equalTo("123")); }
@Test public void checkNewlyAddedBuckets() { Instant addedTime1 = LocalDateTime.of(2015, 10, 15, 12, 25).toInstant(ZoneOffset.UTC); Instant addedTime2 = LocalDateTime.of(2015, 10, 15, 13, 30).toInstant(ZoneOffset.UTC); when(clock.instant()).thenReturn(addedTime1, addedTime2); s3.createBucket("new_bucket_1"); s3.createBucket("new_bucket_2"); List<Bucket> buckets = s3.listBuckets(); assertThat(buckets).hasSize(2); assertThat(getBucketWithName("new_bucket_1", buckets).getCreationDate()).isEqualTo(Date.from(addedTime1)); assertThat(getBucketWithName("new_bucket_2", buckets).getCreationDate()).isEqualTo(Date.from(addedTime2)); buckets.forEach(bucket -> { Owner owner = bucket.getOwner(); assertThat(owner.getDisplayName()).isEqualTo("test"); assertThat(owner.getId()).isNotEmpty(); }); }
@Override public void readFields(DataInput in) throws IOException { this.setBucketName(Text.readString(in)); this.setKey(Text.readString(in)); this.setETag(Text.readString(in)); this.setStorageClass(Text.readString(in)); // Set owner Owner owner = new Owner(); owner.setId(Text.readString(in)); owner.setDisplayName(Text.readString(in)); this.setOwner(owner); this.setSize(in.readLong()); this.setLastModified(new Date(in.readLong())); }
@Override public List<Bucket> listBuckets() throws AmazonClientException, AmazonServiceException { ArrayList<Bucket> list = new ArrayList<Bucket>(); Bucket bucket = new Bucket("camel-bucket"); bucket.setOwner(new Owner("Camel", "camel")); bucket.setCreationDate(new Date()); list.add(bucket); return list; }
@Override public Bucket createBucket(CreateBucketRequest createBucketRequest) throws AmazonClientException, AmazonServiceException { if ("nonExistingBucket".equals(createBucketRequest.getBucketName())) { nonExistingBucketCreated = true; } Bucket bucket = new Bucket(); bucket.setName(createBucketRequest.getBucketName()); bucket.setCreationDate(new Date()); bucket.setOwner(new Owner("c2efc7302b9011ba9a78a92ac5fd1cd47b61790499ab5ddf5a37c31f0638a8fc ", "Christian Mueller")); return bucket; }
@Override public Owner getS3AccountOwner(GetS3AccountOwnerRequest getS3AccountOwnerRequest) throws SdkClientException, AmazonServiceException { getS3AccountOwnerRequest = beforeClientExecution(getS3AccountOwnerRequest); rejectNull(getS3AccountOwnerRequest, "The request object parameter getS3AccountOwnerRequest must be specified."); Request<GetS3AccountOwnerRequest> request = createRequest(null, null, getS3AccountOwnerRequest, HttpMethodName.GET); return invoke(request, new Unmarshallers.ListBucketsOwnerUnmarshaller(), null, null); }
/** * Converts the specified AccessControlList object to an XML fragment that * can be sent to Amazon S3. * * @param acl * The AccessControlList to convert to XML. * * @return an XML representation of the Access Control List object, suitable * to send in a request to Amazon S3. */ public byte[] convertToXmlByteArray(AccessControlList acl) throws SdkClientException { Owner owner = acl.getOwner(); if (owner == null) { throw new SdkClientException("Invalid AccessControlList: missing an S3Owner"); } XmlWriter xml = new XmlWriter(); xml.start("AccessControlPolicy", "xmlns", Constants.XML_NAMESPACE); xml.start("Owner"); if (owner.getId() != null) { xml.start("ID").value(owner.getId()).end(); } if (owner.getDisplayName() != null) { xml.start("DisplayName").value(owner.getDisplayName()).end(); } xml.end(); xml.start("AccessControlList"); for (Grant grant : acl.getGrantsAsList()) { xml.start("Grant"); convertToXml(grant.getGrantee(), xml); xml.start("Permission").value(grant.getPermission().toString()).end(); xml.end(); } xml.end(); xml.end(); return xml.getBytes(); }
private List<S3ObjectSummary> getObjectsInBucket(Date... dates) { List<S3ObjectSummary> list = new ArrayList<S3ObjectSummary>(); for (Date date : dates) { S3ObjectSummary s3Object = new S3ObjectSummary(); s3Object.setKey("dummy-key"); s3Object.setLastModified(date); s3Object.setOwner(new Owner("123", "username")); list.add(s3Object); } return list; }
public S3ImageStore(String accessKey, String secretKey, String bucketName) { this.bucketName = bucketName; this.myAccessKeyID = accessKey; this.mySecretKey = secretKey; AWSCredentials myCredentials = new BasicAWSCredentials( myAccessKeyID, mySecretKey); s3Client = new AmazonS3Client(myCredentials); Owner o = s3Client.getS3AccountOwner(); log.info("using S3 as "+o.getDisplayName()); List<Bucket> bl =s3Client.listBuckets(); for(Bucket b : bl) { log.info(" bucket:"+b.getName()); } }
@Override public Owner getS3AccountOwner() throws AmazonClientException, AmazonServiceException { return delegate.getS3AccountOwner(); }
@Override public Owner getS3AccountOwner(GetS3AccountOwnerRequest getS3AccountOwnerRequest) throws AmazonClientException, AmazonServiceException { return delegate.getS3AccountOwner(getS3AccountOwnerRequest); }
/** * Get the owner's display name */ public String getOwnerName() { Owner owner = s3Summary.getOwner(); return owner != null ? owner.getDisplayName() : null; }
/** * Get the owner's Id. */ public String getOwnerId() { Owner owner = s3Summary.getOwner(); return owner != null ? owner.getId() : null; }
@Override public Owner getS3AccountOwner() throws AmazonClientException, AmazonServiceException { throw new UnsupportedOperationException(); }
@Override public Owner getS3AccountOwner() throws SdkClientException, AmazonServiceException { return getS3AccountOwner(new GetS3AccountOwnerRequest()); }
@Override public Owner getS3AccountOwner() throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().getS3AccountOwner()); }
@Override public Owner getS3AccountOwner(GetS3AccountOwnerRequest getS3AccountOwnerRequest) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().getS3AccountOwner(getS3AccountOwnerRequest)); }
protected OwnerAssert(Owner actual) { super(actual, OwnerAssert.class); }
@Test public void incorrectOwnerDisplayName() { assertThatThrownBy(() -> assertThat(mock(Owner.class)).hasDisplayName("test")) .hasMessageContaining("have displayName"); }
@Override public Owner getS3AccountOwner() throws AmazonClientException { return null; }
@Override public Owner getS3AccountOwner() throws AmazonClientException, AmazonServiceException { // TODO Auto-generated method stub return null; }
/** * Tests S3Object serialization and deserialization */ @Test public void testReadWrite() { S3ObjectSummaryWritable objIn = new S3ObjectSummaryWritable(); S3ObjectSummaryWritable objOut = new S3ObjectSummaryWritable(); // serialized object ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); // serialized object reader ByteArrayInputStream bais = null; DataInputStream dis = null; //Date Date date = new Date(); //Owner Owner owner = new Owner("id", "displayName"); objIn.setBucketName("bucketName"); objIn.setKey("key"); objIn.setETag("eTag"); objIn.setLastModified(date); objIn.setSize(12345); objIn.setStorageClass("storageClass"); objIn.setOwner(owner); try { objIn.write(dos); // create input reader bais = new ByteArrayInputStream(baos.toByteArray()); dis = new DataInputStream(bais); objOut.readFields(dis); Assert.assertEquals(objIn.getBucketName(), objOut.getBucketName()); Assert.assertEquals(objIn.getETag(), objOut.getETag()); Assert.assertEquals(objIn.getLastModified(), objOut.getLastModified()); Assert.assertEquals(objIn.getSize(), objOut.getSize()); Assert.assertEquals(objIn.getStorageClass(), objOut.getStorageClass()); Assert.assertEquals(objIn.getOwner(), objOut.getOwner()); } catch (IOException e) { e.printStackTrace(); fail("Exeception while writing data to out stream."); } }