Java源码示例:com.amazonaws.services.s3.model.BucketVersioningConfiguration

示例1
@Test
public void test()throws Exception{
    Collection<String> li = new ArrayList<>();
    li.add("123");
    BucketVersioningConfiguration configuration = new BucketVersioningConfiguration();
    configuration.setMfaDeleteEnabled(false);
    
    mockStatic(PacmanUtils.class);
    when(PacmanUtils.doesAllHaveValue(anyString(),anyString())).thenReturn(
            true);
    
    Map<String,Object>map=new HashMap<String, Object>();
    map.put("client", awsS3Client);
    CheckMFADeleteEnabledRule spy = Mockito.spy(new CheckMFADeleteEnabledRule());
    
    Mockito.doReturn(map).when((BaseRule)spy).getClientFor(anyObject(), anyString(), anyObject());
    
    when(awsS3Client.getBucketVersioningConfiguration(anyString())).thenReturn(configuration);
    spy.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "));
    
    assertThat(checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getEmptyMapString()), is(notNullValue()));
    
    when(awsS3Client.getBucketVersioningConfiguration(anyString())).thenThrow(new RuleExecutionFailedExeption());
    assertThatThrownBy( 
            () -> checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class);
    
    
    when(PacmanUtils.doesAllHaveValue(anyString(),anyString())).thenReturn(
            false);
    assertThatThrownBy(
            () -> checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class);
}
 
示例2
/**
 * Instantiates a new bucket VH.
 *
 * @param bucket the bucket
 * @param location the location
 * @param versionConfig the version config
 * @param tags the tags
 */
public BucketVH(Bucket bucket,String location,BucketVersioningConfiguration versionConfig, List<Tag> tags, String bucketEncryp, boolean websiteConfiguration,BucketLoggingConfiguration bucketLoggingConfiguration){
	this.bucket = bucket;
	this.location = location;
	this.versionStatus = versionConfig==null?"":versionConfig.getStatus();
	this.mfaDelete =  versionConfig==null?null:versionConfig.isMfaDeleteEnabled();
	this.tags = tags;
	this.bucketEncryp = bucketEncryp;
	this.websiteConfiguration = websiteConfiguration;
       this.isLoggingEnabled = bucketLoggingConfiguration==null?null:bucketLoggingConfiguration.isLoggingEnabled();
       this.destinationBucketName = bucketLoggingConfiguration==null?"":bucketLoggingConfiguration.getDestinationBucketName();
       this.logFilePrefix = bucketLoggingConfiguration==null?"":bucketLoggingConfiguration.getLogFilePrefix();

}
 
示例3
/**
 * Fetch S 3 info test.
 *
 * @throws Exception the exception
 */
@SuppressWarnings({ "static-access"})
@Test
public void fetchS3InfoTest() throws Exception {
    
    mockStatic(AmazonS3ClientBuilder.class);
    AmazonS3 amazonS3Client = PowerMockito.mock(AmazonS3.class);
    AmazonS3ClientBuilder amazonRDSClientBuilder = PowerMockito.mock(AmazonS3ClientBuilder.class);
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class);
    PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider);
    when(amazonRDSClientBuilder.standard()).thenReturn(amazonRDSClientBuilder);
    when(amazonRDSClientBuilder.withCredentials(anyObject())).thenReturn(amazonRDSClientBuilder);
    when(amazonRDSClientBuilder.withRegion(anyString())).thenReturn(amazonRDSClientBuilder);
    when(amazonRDSClientBuilder.build()).thenReturn(amazonS3Client);
    
    List<Bucket> s3buckets = new ArrayList<>();
    Bucket bucket = new Bucket();
    bucket.setName("name");
    s3buckets.add(bucket);
    when(amazonS3Client.listBuckets()).thenReturn(s3buckets);
    when(amazonS3Client.getBucketLocation(anyString())).thenReturn("bucketLocation");
    mockStatic(com.amazonaws.services.s3.model.Region.class);
    com.amazonaws.services.s3.model.Region value = null;
    when(com.amazonaws.services.s3.model.Region.fromValue(anyString())).thenReturn(value.US_West);
    when(value.US_West.toAWSRegion()).thenReturn(getRegions().get(0));
    when(amazonS3Client.getBucketVersioningConfiguration(anyString())).thenReturn(new BucketVersioningConfiguration());
    BucketTaggingConfiguration tagConfig = new BucketTaggingConfiguration();
    List<TagSet> tagSets = new ArrayList<>();
    TagSet tagSet = new TagSet();
    tagSet.setTag("key", "value");
    tagSets.add(tagSet);
    tagSets.add(tagSet);
    tagConfig.setTagSets(tagSets);
    when(amazonS3Client.getBucketTaggingConfiguration(anyString())).thenReturn(tagConfig);
    
    assertThat(inventoryUtil.fetchS3Info(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(1));
}
 
示例4
public static boolean checkBucketIsVersioned(String bucketName, AWSClientFactory awsClientFactory) {
    final BucketVersioningConfiguration bucketVersioningConfig = awsClientFactory.getS3Client().getBucketVersioningConfiguration(bucketName);
    return bucketVersioningConfig.getStatus().equals(BucketVersioningConfiguration.ENABLED);
}
 
示例5
/** Unsupported Operation. */
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(
    String bucketName) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
示例6
/** Unsupported Operation. */
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(
    GetBucketVersioningConfigurationRequest getBucketVersioningConfigurationReq) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
示例7
@Override
public BucketVersioningConfiguration getBucketVersioningConfiguration(String bucketName)
    throws AmazonClientException, AmazonServiceException {
  // TODO Auto-generated method stub
  return null;
}
 
示例8
private static void createBucket(AmazonS3 s3Client, Regions region, String bucketName) {
    CreateBucketRequest request = new CreateBucketRequest(bucketName, region.getName());
    s3Client.createBucket(request);
    BucketVersioningConfiguration configuration = new BucketVersioningConfiguration().withStatus(BucketVersioningConfiguration.ENABLED);

    SetBucketVersioningConfigurationRequest enableVersioningRequest = new SetBucketVersioningConfigurationRequest(bucketName, configuration);
    s3Client.setBucketVersioningConfiguration(enableVersioningRequest);


}