@Test public void getPacmanTagValue2() throws Exception{ PowerMockito.mockStatic(CommonUtils.class); Map<String, Object> clientMap = Maps.newHashMap(); clientMap.put("client", ec2Mock); Map<String, String> pacTag = Maps.newHashMap(); List<TagSet> existingTargets = Lists.newArrayList(); TagSet tagSet = new TagSet(); tagSet.setTag("test", "value2"); existingTargets.add(tagSet); DescribeTagsResult descriptions = getDescribeTagsResult(); PowerMockito.when(ec2Mock.describeTags(any(DescribeTagsRequest.class))).thenReturn(descriptions); 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()); assertNull(classUnderTest.getPacmanTagValue("resourceId", clientMap, AWSService.EC2)); }
public String getPacmanTagValue(String resourceId, Map<String, Object> clientMap, AWSService serviceType) { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (null == bucketTaggingConfiguration) { return null; } List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); return existingTags.get(CommonUtils.getPropValue(PacmanSdkConstants.PACMAN_AUTO_FIX_TAG_NAME)); } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return getEC2PacManTagValue(resourceId, clientMap); } case VOLUME: { return getEC2PacManTagValue(resourceId, clientMap); } case SNAPSHOT: { return getEC2PacManTagValue(resourceId, clientMap); } case IAM: { return ""; } case ELB_APP: { return getAppElbPacManTagValue(resourceId, clientMap); } case ELB_CLASSIC: { return ""; } case REDSHIFT: { return ""; } case RDS: { return ""; } case ELASTICSEARCH: { return ""; } default: throw new OperationNotPermittedException("this resource tagging is not imlemented yet"); } }
ResourceTaggingManager { public String getPacmanTagValue(String resourceId, Map<String, Object> clientMap, AWSService serviceType) { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (null == bucketTaggingConfiguration) { return null; } List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); return existingTags.get(CommonUtils.getPropValue(PacmanSdkConstants.PACMAN_AUTO_FIX_TAG_NAME)); } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return getEC2PacManTagValue(resourceId, clientMap); } case VOLUME: { return getEC2PacManTagValue(resourceId, clientMap); } case SNAPSHOT: { return getEC2PacManTagValue(resourceId, clientMap); } case IAM: { return ""; } case ELB_APP: { return getAppElbPacManTagValue(resourceId, clientMap); } case ELB_CLASSIC: { return ""; } case REDSHIFT: { return ""; } case RDS: { return ""; } case ELASTICSEARCH: { return ""; } default: throw new OperationNotPermittedException("this resource tagging is not imlemented yet"); } } }
ResourceTaggingManager { public String getPacmanTagValue(String resourceId, Map<String, Object> clientMap, AWSService serviceType) { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (null == bucketTaggingConfiguration) { return null; } List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); return existingTags.get(CommonUtils.getPropValue(PacmanSdkConstants.PACMAN_AUTO_FIX_TAG_NAME)); } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return getEC2PacManTagValue(resourceId, clientMap); } case VOLUME: { return getEC2PacManTagValue(resourceId, clientMap); } case SNAPSHOT: { return getEC2PacManTagValue(resourceId, clientMap); } case IAM: { return ""; } case ELB_APP: { return getAppElbPacManTagValue(resourceId, clientMap); } case ELB_CLASSIC: { return ""; } case REDSHIFT: { return ""; } case RDS: { return ""; } case ELASTICSEARCH: { return ""; } default: throw new OperationNotPermittedException("this resource tagging is not imlemented yet"); } }  }
ResourceTaggingManager { public String getPacmanTagValue(String resourceId, Map<String, Object> clientMap, AWSService serviceType) { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (null == bucketTaggingConfiguration) { return null; } List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); return existingTags.get(CommonUtils.getPropValue(PacmanSdkConstants.PACMAN_AUTO_FIX_TAG_NAME)); } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return getEC2PacManTagValue(resourceId, clientMap); } case VOLUME: { return getEC2PacManTagValue(resourceId, clientMap); } case SNAPSHOT: { return getEC2PacManTagValue(resourceId, clientMap); } case IAM: { return ""; } case ELB_APP: { return getAppElbPacManTagValue(resourceId, clientMap); } case ELB_CLASSIC: { return ""; } case REDSHIFT: { return ""; } case RDS: { return ""; } case ELASTICSEARCH: { return ""; } 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 String getPacmanTagValue(String resourceId, Map<String, Object> clientMap, AWSService serviceType) { switch (serviceType) { case S3: { try { AmazonS3 s3Client = (AmazonS3) clientMap.get("client"); BucketTaggingConfiguration bucketTaggingConfiguration = s3Client .getBucketTaggingConfiguration(resourceId); if (null == bucketTaggingConfiguration) { return null; } List<TagSet> existingTargets = bucketTaggingConfiguration.getAllTagSets(); Map<String, String> existingTags = existingTargets.get(0).getAllTags(); return existingTags.get(CommonUtils.getPropValue(PacmanSdkConstants.PACMAN_AUTO_FIX_TAG_NAME)); } catch (Exception exception) { logger.error("error tagging bucekt - > " + resourceId, exception); throw exception; } } case EC2: { return getEC2PacManTagValue(resourceId, clientMap); } case VOLUME: { return getEC2PacManTagValue(resourceId, clientMap); } case SNAPSHOT: { return getEC2PacManTagValue(resourceId, clientMap); } case IAM: { return ""; } case ELB_APP: { return getAppElbPacManTagValue(resourceId, clientMap); } case ELB_CLASSIC: { return ""; } case REDSHIFT: { return ""; } case RDS: { return ""; } case ELASTICSEARCH: { return ""; } 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);  }