com.amazonaws.services.s3.model.PutObjectResult Java Examples
The following examples show how to use
com.amazonaws.services.s3.model.PutObjectResult.
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: S3ReconcilerTest.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
@Override protected void starting(Description description) { super.starting(description); outputPath = new File( "target" + Path.SEPARATOR + description.getClassName() + Path.SEPARATOR + description.getMethodName()) .getPath(); Attribute.AttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap(); attributes.put(DAG.DAGContext.APPLICATION_ID, description.getClassName()); attributes.put(DAG.DAGContext.APPLICATION_PATH, outputPath); context = mockOperatorContext(1, attributes); underTest = new S3Reconciler(); underTest.setAccessKey(""); underTest.setSecretKey(""); underTest.setup(context); MockitoAnnotations.initMocks(this); PutObjectResult result = new PutObjectResult(); result.setETag(outputPath); when(s3clientMock.putObject((PutObjectRequest)any())).thenReturn(result); underTest.setS3client(s3clientMock); }
Example #2
Source File: DeleteMultipleObjectsVersionEnabledBucket.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
private static void uploadAndDeleteObjectsWithVersions() { System.out.println("Uploading and deleting objects with versions specified."); // Upload three sample objects. ArrayList<KeyVersion> keys = new ArrayList<KeyVersion>(); for (int i = 0; i < 3; i++) { String keyName = "delete object without version ID example " + i; PutObjectResult putResult = S3_CLIENT.putObject(VERSIONED_BUCKET_NAME, keyName, "Object number " + i + " to be deleted."); // Gather the new object keys with version IDs. keys.add(new KeyVersion(keyName, putResult.getVersionId())); } // Delete the specified versions of the sample objects. DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(VERSIONED_BUCKET_NAME) .withKeys(keys) .withQuiet(false); // Verify that the object versions were successfully deleted. DeleteObjectsResult delObjRes = S3_CLIENT.deleteObjects(multiObjectDeleteRequest); int successfulDeletes = delObjRes.getDeletedObjects().size(); System.out.println(successfulDeletes + " objects successfully deleted"); }
Example #3
Source File: S3Utils.java From exhibitor with Apache License 2.0 | 6 votes |
public static ObjectMetadata simpleUploadFile(S3Client client, byte[] bytes, String bucket, String key) throws Exception { byte[] md5 = md5(bytes, bytes.length); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); metadata.setLastModified(new Date()); metadata.setContentMD5(S3Utils.toBase64(md5)); PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, new ByteArrayInputStream(bytes), metadata); PutObjectResult putObjectResult = client.putObject(putObjectRequest); if ( !putObjectResult.getETag().equals(S3Utils.toHex(md5)) ) { throw new Exception("Unable to match MD5 for config"); } return metadata; }
Example #4
Source File: TestPutS3Object.java From nifi with Apache License 2.0 | 6 votes |
private void prepareTest(String filename) { runner.setProperty(PutS3Object.REGION, "ap-northeast-1"); runner.setProperty(PutS3Object.BUCKET, "test-bucket"); runner.assertValid(); Map<String, String> ffAttributes = new HashMap<>(); ffAttributes.put("filename", filename); ffAttributes.put("tagS3PII", "true"); runner.enqueue("Test Content", ffAttributes); PutObjectResult putObjectResult = new PutObjectResult(); putObjectResult.setExpirationTime(new Date()); putObjectResult.setMetadata(new ObjectMetadata()); putObjectResult.setVersionId("test-version"); putObjectResult.setETag("test-etag"); Mockito.when(mockS3Client.putObject(Mockito.any(PutObjectRequest.class))).thenReturn(putObjectResult); MultipartUploadListing uploadListing = new MultipartUploadListing(); Mockito.when(mockS3Client.listMultipartUploads(Mockito.any(ListMultipartUploadsRequest.class))).thenReturn(uploadListing); }
Example #5
Source File: AwsSdkTest.java From s3proxy with Apache License 2.0 | 6 votes |
@Test public void testConditionalGet() throws Exception { assumeTrue(!blobStoreType.equals("b2")); String blobName = "blob-name"; ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(BYTE_SOURCE.size()); PutObjectResult result = client.putObject(containerName, blobName, BYTE_SOURCE.openStream(), metadata); S3Object object = client.getObject( new GetObjectRequest(containerName, blobName) .withMatchingETagConstraint(result.getETag())); try (InputStream is = object.getObjectContent()) { assertThat(is).isNotNull(); ByteStreams.copy(is, ByteStreams.nullOutputStream()); } object = client.getObject( new GetObjectRequest(containerName, blobName) .withNonmatchingETagConstraint(result.getETag())); assertThat(object).isNull(); }
Example #6
Source File: S3DataManagerTest.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void testUploadLocalSourceWithNoSSEAlgorithm() throws Exception { File file = new File(mockWorkspaceDir + "/source-file"); FileUtils.write(file, "contents"); PutObjectResult mockedResponse = new PutObjectResult(); mockedResponse.setVersionId("some-version-id"); when(s3Client.putObject(any(PutObjectRequest.class))).thenReturn(mockedResponse); S3DataManager d = new S3DataManager(s3Client, s3InputBucketName, s3InputKeyName, "", file.getPath(), ""); ArgumentCaptor<PutObjectRequest> savedPutObjectRequest = ArgumentCaptor.forClass(PutObjectRequest.class); UploadToS3Output result = d.uploadSourceToS3(listener, testWorkSpace); assertEquals(result.getSourceLocation(), s3InputBucketName + "/" + s3InputKeyName); verify(s3Client).putObject(savedPutObjectRequest.capture()); assertEquals(savedPutObjectRequest.getValue().getBucketName(), s3InputBucketName); assertEquals(savedPutObjectRequest.getValue().getKey(), s3InputKeyName); assertEquals(savedPutObjectRequest.getValue().getMetadata().getContentMD5(), S3DataManager.getZipMD5(file)); assertEquals(savedPutObjectRequest.getValue().getMetadata().getContentLength(), file.length()); assertNull(savedPutObjectRequest.getValue().getMetadata().getSSEAlgorithm()); }
Example #7
Source File: MultipartUploadLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void whenUploadingFileWithTransferManager_thenVerifyUploadRequested() { File file = mock(File.class); PutObjectResult s3Result = mock(PutObjectResult.class); when(amazonS3.putObject(anyString(), anyString(), (File) any())).thenReturn(s3Result); when(file.getName()).thenReturn(KEY_NAME); PutObjectRequest request = new PutObjectRequest(BUCKET_NAME, KEY_NAME, file); request.setGeneralProgressListener(progressListener); Upload upload = tm.upload(request); assertThat(upload).isNotNull(); verify(amazonS3).putObject(request); }
Example #8
Source File: S3OneComponentDaoImpl.java From singleton with Eclipse Public License 2.0 | 6 votes |
/** * update the component bundle file to remote S3 server */ @Override public boolean update(String productName, String version, String component, String locale, Map<String, String> messages) throws DataException { if (StringUtils.isEmpty(component)) { component = ConstantsFile.DEFAULT_COMPONENT; } String filePath = S3Utils.genProductVersionS3Path(productName, version) + component + ConstantsChar.BACKSLASH + ResourceFilePathGetter.getLocalizedJSONFileName(locale); Map<String, Object> json = new HashMap<String, Object>(); json.put(ConstantsKeys.COMPONENT, component); json.put(ConstantsKeys.lOCALE, locale); json.put(ConstantsKeys.MESSAGES, messages); String content; try { content = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(json); } catch (JsonProcessingException e) { throw new DataException( ConstantsKeys.FATA_ERROR + "Failed to convert content to file: " + filePath + ".", e); } PutObjectResult putResult = s3Client.getS3Client().putObject(config.getBucketName(), filePath, content); return (putResult != null); }
Example #9
Source File: WarehouseExport.java From usergrid with Apache License 2.0 | 6 votes |
private void copyToS3( String fileName ) { String bucketName = ( String ) properties.get( BUCKET_PROPNAME ); String accessId = ( String ) properties.get( ACCESS_ID_PROPNAME ); String secretKey = ( String ) properties.get( SECRET_KEY_PROPNAME ); Properties overrides = new Properties(); overrides.setProperty( "s3" + ".identity", accessId ); overrides.setProperty( "s3" + ".credential", secretKey ); final Iterable<? extends Module> MODULES = ImmutableSet .of( new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule() ); AWSCredentials credentials = new BasicAWSCredentials(accessId, secretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol( Protocol.HTTP); AmazonS3Client s3Client = new AmazonS3Client(credentials, clientConfig); s3Client.createBucket( bucketName ); File uploadFile = new File( fileName ); PutObjectResult putObjectResult = s3Client.putObject( bucketName, uploadFile.getName(), uploadFile ); logger.info("Uploaded file etag={}", putObjectResult.getETag()); }
Example #10
Source File: AmazonS3Mock.java From Scribengin with GNU Affero General Public License v3.0 | 6 votes |
@Override public PutObjectResult putObject(String bucketName, String key, File file) throws AmazonClientException, AmazonServiceException { throwException(putObjectException); List<String> keys = files.get(bucketName); if (keys == null) { throw new AmazonClientException("Bucket do not exist"); } keys.add(key); files.put(bucketName, keys); PutObjectResult result = new PutObjectResult(); try { result.setContentMd5(new String(Md5Utils.md5AsBase64(file))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
Example #11
Source File: MockAmazonS3.java From crate with Apache License 2.0 | 6 votes |
@Override public PutObjectResult putObject(final PutObjectRequest request) throws AmazonClientException { assertThat(request.getBucketName(), equalTo(bucket)); assertThat(request.getMetadata().getSSEAlgorithm(), serverSideEncryption ? equalTo("AES256") : nullValue()); assertThat(request.getCannedAcl(), notNullValue()); assertThat(request.getCannedAcl().toString(), cannedACL != null ? equalTo(cannedACL) : equalTo("private")); assertThat(request.getStorageClass(), storageClass != null ? equalTo(storageClass) : equalTo("STANDARD")); final String blobName = request.getKey(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { Streams.copy(request.getInputStream(), out); blobs.put(blobName, out.toByteArray()); } catch (IOException e) { throw new AmazonClientException(e); } return new PutObjectResult(); }
Example #12
Source File: S3FileTransferImplTest.java From genie with Apache License 2.0 | 6 votes |
/** * Test the putFile method for valid s3 path. * * @throws GenieException If there is any problem */ @Test public void testPutFileMethodValidS3Path() throws GenieException { final PutObjectResult putObjectResult = Mockito.mock(PutObjectResult.class); Mockito.when(this.s3Client.putObject(Mockito.any(), Mockito.any(), Mockito.any(File.class))) .thenReturn(putObjectResult); final ArgumentCaptor<String> bucketArgument = ArgumentCaptor.forClass(String.class); final ArgumentCaptor<String> keyArgument = ArgumentCaptor.forClass(String.class); s3FileTransfer.putFile(LOCAL_PATH, S3_PATH); Mockito .verify(this.s3Client) .putObject(bucketArgument.capture(), keyArgument.capture(), Mockito.any(File.class)); Assert.assertEquals(S3_BUCKET, bucketArgument.getValue()); Assert.assertEquals(S3_KEY, keyArgument.getValue()); Mockito .verify(this.uploadTimer, Mockito.times(1)) .record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); Mockito .verify(this.registry, Mockito.times(1)) .timer(Mockito.eq(S3FileTransferImpl.UPLOAD_TIMER_NAME), this.tagsCaptor.capture()); Assert.assertEquals(SUCCESS_TAGS, this.tagsCaptor.getValue()); }
Example #13
Source File: S3StringWriter.java From micro-server with Apache License 2.0 | 5 votes |
/** * * Writes String data to defined S3 bucket with provided key. Calling * map / flatMap on the returned try instance will catch any exceptions, any * exceptions thrown will convert a Success to a Failure * * This call is blocking. * * @param key * To read * @return Data as String */ public Try<PutObjectResult, Throwable> put(String key, String value) { return Try.withCatch(() -> { byte[] bytes = value.getBytes("UTF-8"); ByteArrayInputStream stream = new ByteArrayInputStream( bytes); ObjectMetadata md = createMetadata(bytes.length); return client.putObject(bucket, key, stream, md); }); }
Example #14
Source File: S3AFastOutputStream.java From hadoop with Apache License 2.0 | 5 votes |
private void putObject() throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Executing regular upload for bucket '{}' key '{}'", bucket, key); } final ObjectMetadata om = createDefaultMetadata(); om.setContentLength(buffer.size()); final PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, new ByteArrayInputStream(buffer.toByteArray()), om); putObjectRequest.setCannedAcl(cannedACL); putObjectRequest.setGeneralProgressListener(progressListener); ListenableFuture<PutObjectResult> putObjectResult = executorService.submit(new Callable<PutObjectResult>() { @Override public PutObjectResult call() throws Exception { return client.putObject(putObjectRequest); } }); //wait for completion try { putObjectResult.get(); } catch (InterruptedException ie) { LOG.warn("Interrupted object upload:" + ie, ie); Thread.currentThread().interrupt(); } catch (ExecutionException ee) { throw new IOException("Regular upload failed", ee.getCause()); } }
Example #15
Source File: UploadThread.java From aws-photosharing-example with Apache License 2.0 | 5 votes |
@Override public void run() { ObjectMetadata meta_data = new ObjectMetadata(); if (p_content_type != null) meta_data.setContentType(p_content_type); meta_data.setContentLength(p_size); PutObjectRequest putObjectRequest = new PutObjectRequest(p_bucket_name, p_s3_key, p_file_stream, meta_data); putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead); PutObjectResult res = s3Client.putObject(putObjectRequest); }
Example #16
Source File: S3DataManagerTest.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 5 votes |
private S3DataManager createDefaultSource(String localSourcePath, String workspaceSubdir) { this.s3ARNs.put("main", "ARN1/bucket/thing.zip"); //put one item in s3ARNs so exception doesn't happen. PutObjectResult mockedResponse = new PutObjectResult(); mockedResponse.setVersionId("some-version-id"); when(s3Client.putObject(any(PutObjectRequest.class))).thenReturn(mockedResponse); return new S3DataManager(s3Client, s3InputBucketName, s3InputKeyName, sseAlgorithm, localSourcePath, workspaceSubdir); }
Example #17
Source File: AthenaAuditWriterTest.java From emodb with Apache License 2.0 | 5 votes |
@BeforeMethod public void setUp() { _s3 = mock(AmazonS3.class); when(_s3.putObject(eq(BUCKET), anyString(), any(File.class))).then(invocationOnMock -> { // The file will be deleted after the put object returns successfully, so capture the contents now File file = (File) invocationOnMock.getArguments()[2]; try (FileInputStream fileIn = new FileInputStream(file); GzipCompressorInputStream in = new GzipCompressorInputStream(fileIn); BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) { Map<String, Object> auditJson = JsonHelper.fromJson(line, new TypeReference<Map<String, Object>>() {}); _uploadedAudits.put((String) invocationOnMock.getArguments()[1], auditJson); } } PutObjectResult result = new PutObjectResult(); result.setETag(file.getName()); return result; }); _tempStagingDir = Files.createTempDir(); // Start with some default time; individual tests can override as necessary _now = Instant.from(ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC)); _clock = mock(Clock.class); when(_clock.millis()).then(ignore -> _now.toEpochMilli()); when(_clock.instant()).then(ignore -> _now); }
Example #18
Source File: S3Repository.java From hawkbit-extensions with Eclipse Public License 1.0 | 5 votes |
@Override protected AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes, final String contentType, final String tempFile) throws IOException { final File file = new File(tempFile); final S3Artifact s3Artifact = createS3Artifact(tenant, base16Hashes, contentType, file); final String key = objectKey(tenant, base16Hashes.getSha1()); LOG.info("Storing file {} with length {} to AWS S3 bucket {} with key {}", file.getName(), file.length(), s3Properties.getBucketName(), key); if (existsByTenantAndSha1(tenant, base16Hashes.getSha1())) { LOG.debug("Artifact {} already exists on S3 bucket {}, don't need to upload twice", key, s3Properties.getBucketName()); return s3Artifact; } try (final InputStream inputStream = new BufferedInputStream(new FileInputStream(file), RequestClientOptions.DEFAULT_STREAM_BUFFER_SIZE)) { final ObjectMetadata objectMetadata = createObjectMetadata(base16Hashes.getMd5(), contentType, file); final PutObjectResult result = amazonS3.putObject(s3Properties.getBucketName(), key, inputStream, objectMetadata); LOG.debug("Artifact {} stored on S3 bucket {} with server side Etag {} and MD5 hash {}", key, s3Properties.getBucketName(), result.getETag(), result.getContentMd5()); return s3Artifact; } catch (final AmazonClientException e) { throw new ArtifactStoreException("Failed to store artifact into S3 ", e); } }
Example #19
Source File: AthenaAuditWriter.java From emodb with Apache License 2.0 | 5 votes |
/** * This method takes all log files prepared by {@link #prepareClosedLogFilesForTransfer()} and initiates their * transfer to S3. The transfer itself is performed asynchronously. */ private void transferLogFilesToS3() { if (_fileTransfersEnabled) { // Find all closed log files in the staging directory and move them to S3 for (final File logFile : _stagingDir.listFiles((dir, name) -> name.startsWith(_logFilePrefix) && name.endsWith(COMPRESSED_FILE_SUFFIX))) { // Extract the date portion of the file name and is it to partition the file in S3 String auditDate = logFile.getName().substring(_logFilePrefix.length() + 1, _logFilePrefix.length() + 9); String dest = String.format("%s/date=%s/%s", _s3AuditRoot, auditDate, logFile.getName()); _fileTransferService.submit(() -> { // Since file transfers are done in a single thread, there shouldn't be any concurrency issues, // but verify the same file wasn't submitted previously and is already transferred. if (logFile.exists()) { try { PutObjectResult result = _s3.putObject(_s3Bucket, dest, logFile); _log.debug("Audit log copied: {}, ETag={}", logFile, result.getETag()); if (!logFile.delete()) { _log.warn("Failed to delete file after copying to s3: {}", logFile); } } catch (Exception e) { // Log the error, try again on the next iteration _rateLimitedLog.error(e, "Failed to copy log file {}", logFile); } } }); } } }
Example #20
Source File: COSAPIClient.java From stocator with Apache License 2.0 | 5 votes |
/** * PUT an object directly (i.e. not via the transfer manager). * @param putObjectRequest the request * @return the upload initiated * @throws IOException on problems */ PutObjectResult putObject(PutObjectRequest putObjectRequest) throws IOException { try { PutObjectResult result = mClient.putObject(putObjectRequest); return result; } catch (AmazonClientException e) { throw translateException("put", putObjectRequest.getKey(), e); } }
Example #21
Source File: SimpleStorageResourceTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void writeFile_forNewFile_writesFileContent() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3, "bucketName", "objectName", new SyncTaskExecutor()); String messageContext = "myFileContent"; when(amazonS3.putObject(eq("bucketName"), eq("objectName"), any(InputStream.class), any(ObjectMetadata.class))) .thenAnswer((Answer<PutObjectResult>) invocation -> { assertThat(invocation.getArguments()[0]) .isEqualTo("bucketName"); assertThat(invocation.getArguments()[1]) .isEqualTo("objectName"); byte[] content = new byte[messageContext.length()]; assertThat(((InputStream) invocation.getArguments()[2]) .read(content)).isEqualTo(content.length); assertThat(new String(content)).isEqualTo(messageContext); return new PutObjectResult(); }); OutputStream outputStream = simpleStorageResource.getOutputStream(); // Act outputStream.write(messageContext.getBytes()); outputStream.flush(); outputStream.close(); // Assert }
Example #22
Source File: S3DaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testGetAmazonS3AssertS3EndpointIsSet() { S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations"); S3Operations mockS3Operations = mock(S3Operations.class); ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations); try { String s3BucketName = "s3BucketName"; String s3KeyPrefix = "s3KeyPrefix"; String s3Endpoint = "s3Endpoint"; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix); s3FileTransferRequestParamsDto.setS3Endpoint(s3Endpoint); when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() { @Override public PutObjectResult answer(InvocationOnMock invocation) throws Throwable { AmazonS3Client amazonS3Client = invocation.getArgument(1); assertEquals(new URI("https://" + s3Endpoint), ReflectionTestUtils.getField(amazonS3Client, "endpoint")); return new PutObjectResult(); } }); s3Dao.createDirectory(s3FileTransferRequestParamsDto); } finally { ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations); } }
Example #23
Source File: S3DaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testPrepareMetadataAssertSetKmsHeaders() { S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations"); S3Operations mockS3Operations = mock(S3Operations.class); ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations); try { String s3BucketName = "s3BucketName"; String s3KeyPrefix = "s3KeyPrefix"; String kmsKeyId = "kmsKeyId"; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix); s3FileTransferRequestParamsDto.setKmsKeyId(kmsKeyId); when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() { @Override public PutObjectResult answer(InvocationOnMock invocation) throws Throwable { PutObjectRequest putObjectRequest = invocation.getArgument(0); ObjectMetadata metadata = putObjectRequest.getMetadata(); assertEquals("aws:kms", metadata.getSSEAlgorithm()); assertEquals(kmsKeyId, metadata.getRawMetadata().get(Headers.SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID)); return new PutObjectResult(); } }); s3Dao.createDirectory(s3FileTransferRequestParamsDto); } finally { ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations); } }
Example #24
Source File: S3DaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testCreateDirectoryAssertAddTrailingSlashOnlyIfNotPresent() { S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations"); S3Operations mockS3Operations = mock(S3Operations.class); ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations); try { String s3BucketName = "s3BucketName"; String s3KeyPrefix = "s3KeyPrefix/"; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix); when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() { @Override public PutObjectResult answer(InvocationOnMock invocation) throws Throwable { PutObjectRequest putObjectRequest = invocation.getArgument(0); assertEquals(s3BucketName, putObjectRequest.getBucketName()); assertEquals(s3KeyPrefix, putObjectRequest.getKey()); PutObjectResult putObjectResult = new PutObjectResult(); return putObjectResult; } }); s3Dao.createDirectory(s3FileTransferRequestParamsDto); } finally { ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations); } }
Example #25
Source File: S3DaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testCreateDirectoryAssertCallsPutObject() { S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations"); S3Operations mockS3Operations = mock(S3Operations.class); ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations); try { String s3BucketName = "s3BucketName"; String s3KeyPrefix = "s3KeyPrefix"; String expectedS3KeyPrefix = s3KeyPrefix + "/"; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix); when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() { @Override public PutObjectResult answer(InvocationOnMock invocation) throws Throwable { PutObjectRequest putObjectRequest = invocation.getArgument(0); assertEquals(s3BucketName, putObjectRequest.getBucketName()); assertEquals(expectedS3KeyPrefix, putObjectRequest.getKey()); PutObjectResult putObjectResult = new PutObjectResult(); return putObjectResult; } }); s3Dao.createDirectory(s3FileTransferRequestParamsDto); } finally { ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations); } }
Example #26
Source File: DummyS3Client.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public PutObjectResult putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata) throws SdkClientException { checkBucketExists(bucketName); Set<String> keys = objMap.get(bucketName); keys.add(key); return new PutObjectResult(); }
Example #27
Source File: S3DaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testGetAmazonS3AssertProxyIsNotSetWhenProxyHostIsBlank() { S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations"); S3Operations mockS3Operations = mock(S3Operations.class); ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations); try { String s3BucketName = "s3BucketName"; String s3KeyPrefix = "s3KeyPrefix"; String httpProxyHost = ""; Integer httpProxyPort = 1234; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix); s3FileTransferRequestParamsDto.setHttpProxyHost(httpProxyHost); s3FileTransferRequestParamsDto.setHttpProxyPort(httpProxyPort); when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() { @Override public PutObjectResult answer(InvocationOnMock invocation) throws Throwable { AmazonS3Client amazonS3Client = invocation.getArgument(1); ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonS3Client, "clientConfiguration"); assertNull(clientConfiguration.getProxyHost()); return new PutObjectResult(); } }); s3Dao.createDirectory(s3FileTransferRequestParamsDto); } finally { ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations); } }
Example #28
Source File: S3DaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testGetAmazonS3AssertProxyIsNotSetWhenProxyPortIsNull() { S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations"); S3Operations mockS3Operations = mock(S3Operations.class); ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations); try { String s3BucketName = "s3BucketName"; String s3KeyPrefix = "s3KeyPrefix"; String httpProxyHost = "httpProxyHost"; Integer httpProxyPort = null; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix); s3FileTransferRequestParamsDto.setHttpProxyHost(httpProxyHost); s3FileTransferRequestParamsDto.setHttpProxyPort(httpProxyPort); when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() { @Override public PutObjectResult answer(InvocationOnMock invocation) throws Throwable { AmazonS3Client amazonS3Client = invocation.getArgument(1); ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonS3Client, "clientConfiguration"); assertNull(clientConfiguration.getProxyHost()); return new PutObjectResult(); } }); s3Dao.createDirectory(s3FileTransferRequestParamsDto); } finally { ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations); } }
Example #29
Source File: S3DaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testGetAmazonS3AssertProxyIsSet() { S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations"); S3Operations mockS3Operations = mock(S3Operations.class); ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations); try { String s3BucketName = "s3BucketName"; String s3KeyPrefix = "s3KeyPrefix"; String httpProxyHost = "httpProxyHost"; Integer httpProxyPort = 1234; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix); s3FileTransferRequestParamsDto.setHttpProxyHost(httpProxyHost); s3FileTransferRequestParamsDto.setHttpProxyPort(httpProxyPort); when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() { @Override public PutObjectResult answer(InvocationOnMock invocation) throws Throwable { AmazonS3Client amazonS3Client = invocation.getArgument(1); ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonS3Client, "clientConfiguration"); assertEquals(httpProxyHost, clientConfiguration.getProxyHost()); assertEquals(httpProxyPort.intValue(), clientConfiguration.getProxyPort()); return new PutObjectResult(); } }); s3Dao.createDirectory(s3FileTransferRequestParamsDto); } finally { ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations); } }
Example #30
Source File: S3DaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testGetAmazonS3AssertV4SigningAlwaysPresent() { S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations"); S3Operations mockS3Operations = mock(S3Operations.class); ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations); try { String s3BucketName = "s3BucketName"; String s3KeyPrefix = "s3KeyPrefix"; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix); when(mockS3Operations.putObject(any(), any())).then(invocation -> { AmazonS3Client amazonS3Client = invocation.getArgument(1); ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonS3Client, "clientConfiguration"); assertEquals(S3Dao.SIGNER_OVERRIDE_V4, clientConfiguration.getSignerOverride()); return new PutObjectResult(); }); } finally { ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations); } }