@Test public void tagResource2() throws Exception{ PowerMockito.mockStatic(CommonUtils.class); Map<String, Object> clientMap = Maps.newHashMap(); clientMap.put("client", s3Mock); clientMap.put("field234", "field234"); clientMap.put("field345", "field345"); Map<String, String> pacTag = Maps.newHashMap(); clientMap.put("field123", "field123"); clientMap.put("field234", "field234"); clientMap.put("field345", "field345"); List<TagSet> existingTargets = Lists.newArrayList(); TagSet tagSet = new TagSet(); tagSet.setTag("test", "value2"); existingTargets.add(tagSet); existingTargets.add(tagSet); PowerMockito.when(bucketTaggingConfiguration.getAllTagSets()).thenReturn(existingTargets); PowerMockito.when(s3Mock.getBucketTaggingConfiguration(anyString())).thenReturn(bucketTaggingConfiguration); PowerMockito.when(CommonUtils.getPropValue(anyString())).thenReturn("test"); final ResourceTaggingManager classUnderTest = PowerMockito.spy(new ResourceTaggingManager()); assertTrue(classUnderTest.tagResource("resourceId", clientMap, AWSService.S3, pacTag)); }
public Boolean tagResource(final String resourceId, final Map<String, Object> clientMap, AWSService serviceType, Map<String, String> pacTag) throws Exception { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (bucketTaggingConfiguration == null) { saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(pacTag))), s3Client); } else { List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); Map<String, String> allTags = Maps.newHashMap(); if (bucketAlreadyTaggedAndTagValueNotAltered(existingTags, pacTag)) return Boolean.TRUE; allTags.putAll(existingTags); allTags.putAll(pacTag); bucketTaggingConfiguration.setTagSets(existingTargets); saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(allTags))), s3Client); } return Boolean.TRUE; } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case SNAPSHOT: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case VOLUME: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case RDSDB: { return setRDSDBTag(resourceId,clientMap,pacTag); } case ELASTICSEARCH:{ return setElasticSearchTag(resourceId,clientMap,pacTag); } case EFS:{ return setEFSTag(resourceId,clientMap,pacTag); } case REDSHIFT:{ return setRedshiftTag(resourceId,clientMap,pacTag); } default: throw new OperationNotPermittedException("this resource tagging is not imlemented yet"); } }
ResourceTaggingManager { public Boolean tagResource(final String resourceId, final Map<String, Object> clientMap, AWSService serviceType, Map<String, String> pacTag) throws Exception { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (bucketTaggingConfiguration == null) { saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(pacTag))), s3Client); } else { List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); Map<String, String> allTags = Maps.newHashMap(); if (bucketAlreadyTaggedAndTagValueNotAltered(existingTags, pacTag)) return Boolean.TRUE; allTags.putAll(existingTags); allTags.putAll(pacTag); bucketTaggingConfiguration.setTagSets(existingTargets); saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(allTags))), s3Client); } return Boolean.TRUE; } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case SNAPSHOT: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case VOLUME: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case RDSDB: { return setRDSDBTag(resourceId,clientMap,pacTag); } case ELASTICSEARCH:{ return setElasticSearchTag(resourceId,clientMap,pacTag); } case EFS:{ return setEFSTag(resourceId,clientMap,pacTag); } case REDSHIFT:{ return setRedshiftTag(resourceId,clientMap,pacTag); } default: throw new OperationNotPermittedException("this resource tagging is not imlemented yet"); } } }
ResourceTaggingManager { public Boolean tagResource(final String resourceId, final Map<String, Object> clientMap, AWSService serviceType, Map<String, String> pacTag) throws Exception { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (bucketTaggingConfiguration == null) { saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(pacTag))), s3Client); } else { List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); Map<String, String> allTags = Maps.newHashMap(); if (bucketAlreadyTaggedAndTagValueNotAltered(existingTags, pacTag)) return Boolean.TRUE; allTags.putAll(existingTags); allTags.putAll(pacTag); bucketTaggingConfiguration.setTagSets(existingTargets); saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(allTags))), s3Client); } return Boolean.TRUE; } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case SNAPSHOT: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case VOLUME: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case RDSDB: { return setRDSDBTag(resourceId,clientMap,pacTag); } case ELASTICSEARCH:{ return setElasticSearchTag(resourceId,clientMap,pacTag); } case EFS:{ return setEFSTag(resourceId,clientMap,pacTag); } case REDSHIFT:{ return setRedshiftTag(resourceId,clientMap,pacTag); } default: throw new OperationNotPermittedException("this resource tagging is not imlemented yet"); } }  }
ResourceTaggingManager { public Boolean tagResource(final String resourceId, final Map<String, Object> clientMap, AWSService serviceType, Map<String, String> pacTag) throws Exception { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (bucketTaggingConfiguration == null) { saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(pacTag))), s3Client); } else { List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); Map<String, String> allTags = Maps.newHashMap(); if (bucketAlreadyTaggedAndTagValueNotAltered(existingTags, pacTag)) return Boolean.TRUE; allTags.putAll(existingTags); allTags.putAll(pacTag); bucketTaggingConfiguration.setTagSets(existingTargets); saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(allTags))), s3Client); } return Boolean.TRUE; } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case SNAPSHOT: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case VOLUME: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case RDSDB: { return setRDSDBTag(resourceId,clientMap,pacTag); } case ELASTICSEARCH:{ return setElasticSearchTag(resourceId,clientMap,pacTag); } case EFS:{ return setEFSTag(resourceId,clientMap,pacTag); } case REDSHIFT:{ return setRedshiftTag(resourceId,clientMap,pacTag); } default: throw new OperationNotPermittedException("this resource tagging is not imlemented yet"); } }  Boolean tagResource(final String resourceId, final Map<String, Object> clientMap, AWSService serviceType,
            Map<String, String> pacTag); String getPacmanTagValue(String resourceId, Map<String, Object> clientMap, AWSService serviceType); }
ResourceTaggingManager { public Boolean tagResource(final String resourceId, final Map<String, Object> clientMap, AWSService serviceType, Map<String, String> pacTag) throws Exception { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (bucketTaggingConfiguration == null) { saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(pacTag))), s3Client); } else { List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); Map<String, String> allTags = Maps.newHashMap(); if (bucketAlreadyTaggedAndTagValueNotAltered(existingTags, pacTag)) return Boolean.TRUE; allTags.putAll(existingTags); allTags.putAll(pacTag); bucketTaggingConfiguration.setTagSets(existingTargets); saveTags(resourceId, new BucketTaggingConfiguration(Collections.singletonList(new TagSet(allTags))), s3Client); } return Boolean.TRUE; } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case SNAPSHOT: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case VOLUME: { return setEC2VolumeTag(resourceId, clientMap, pacTag); } case RDSDB: { return setRDSDBTag(resourceId,clientMap,pacTag); } case ELASTICSEARCH:{ return setElasticSearchTag(resourceId,clientMap,pacTag); } case EFS:{ return setEFSTag(resourceId,clientMap,pacTag); } case REDSHIFT:{ return setRedshiftTag(resourceId,clientMap,pacTag); } default: throw new OperationNotPermittedException("this resource tagging is not imlemented yet"); } }  Boolean tagResource(final String resourceId, final Map<String, Object> clientMap, AWSService serviceType,
            Map<String, String> pacTag); String getPacmanTagValue(String resourceId, Map<String, Object> clientMap, AWSService serviceType);  }