ElastiCacheRaiderImpl implements ElastiCacheRaider { @Override public void attachSubnet(String clusterName, String subnetId) { if (clusterName.isEmpty() || clusterName == null) { throw new InvalidInputDataException("Empty/Null clusterName provided in request"); } else if (subnetId.isEmpty() || subnetId == null) { throw new InvalidInputDataException("Empty/Null subnetId provided in request"); } List<String> subnetIds = this.getSubnetIds(clusterName); if (subnetIds != null && !subnetIds.contains(subnetId)) { subnetIds.add(subnetId); ModifyCacheSubnetGroupRequest modifyCacheSubnetGroupRequest = new ModifyCacheSubnetGroupRequest() .withCacheSubnetGroupName(getSubnetGroupName(clusterName)) .withSubnetIds(subnetIds); elastiCacheDelegator.getAmazonElastiCache().modifyCacheSubnetGroup(modifyCacheSubnetGroupRequest); } else { throw new com.intuit.cloudraider.exceptions.ResourceNotFoundException("Unable to attach Subnet: " + subnetId); } } ElastiCacheRaiderImpl(); @Override void rebootElastiCacheCluster(String clusterName, Integer numNodes); @Override void detachSubnet(String clusterName, String subnetId); @Override void attachSubnet(String clusterName, String subnetId); @Override String getElastiCacheClusterStatus(String clusterName); @Override void addNodesToCluster(String clusterName, Integer numNodes); Integer getNumNodes(String clusterName); @Override void removeNodesFromCluster(String clusterName, Integer numNodes); List<String> getSubnetIds(String clusterName); @Override void changeSecurityGroupId(String clusterName, String fromSecurityGroupId, String toSecurityGroupId); @Override List<String> getSecurityGroups(String clusterName); List<CacheNode> getAllElasticCacheNodes(); List<CacheNode> getAllElasticCacheNodesForGivenCluster(String clusterName); @Override List<String> getAllElastiCacheNodeNames(); @Override List<String> getAllElastiCacheNodeNames(String clusterName); @Override String getElastiCacheNodeStatus(String nodeName); @Override void rebootElasticCacheNode(String nodeName);  }
@Test public void testAttachSubnet(){ elastiCacheRaider.attachSubnet("cacheCluster", "subnet-1234"); }
@Test (expected = ResourceNotFoundException.class) public void testAttachUnknownSubnet(){ elastiCacheRaider.attachSubnet("cacheCluster", "subnet-123"); }
@Test (expected = InvalidInputDataException.class) public void testAttachMissingSubnet(){ elastiCacheRaider.attachSubnet("cacheCluster", ""); }
@Test (expected = InvalidInputDataException.class) public void testAttachSubnetMissingCluster(){ elastiCacheRaider.attachSubnet("", "subnet-1234"); }