InfrastructureManagerClaudiaImpl implements InfrastructureManager { public void deleteEnvironment(ClaudiaData claudiaData, EnvironmentInstance envInstance) throws InfrastructureException, InvalidEntityException, EntityNotFoundException { log.info("Delete environment " + envInstance.getBlueprintName()); List<TierInstance> tierInstances = envInstance.getTierInstances(); if (tierInstances == null) return; for (int i = 0; i < tierInstances.size(); i++) { TierInstance tierInstance = tierInstances.get(i); tierInstance = tierInstanceManager.loadNetworkInstnace(tierInstance.getName()); boolean exists = claudiaClient.existsVMReplica(claudiaData, tierInstance.getName(), tierInstance.getVM(), tierInstance.getTier().getRegion()); if (exists) { claudiaClient.undeployVMReplica(claudiaData, tierInstance); } } }  @Async TierInstance cloneTemplate(String templateName); List<VM> createEnvironment(EnvironmentInstance envInstance, String ovf, ClaudiaData claudiaData); EnvironmentInstance createInfrasctuctureEnvironmentInstance(EnvironmentInstance environmentInstance,
            Set<Tier> tiers, ClaudiaData claudiaData); String generateVMName(String service, String tierName, int numReplica, String vdc); @Async Template createTemplate(TierInstance tierInstance); void deleteEnvironment(ClaudiaData claudiaData, EnvironmentInstance envInstance); @Override void deleteNetworksInTierInstance(ClaudiaData claudiaData, TierInstance tierInstance); void deleteVMReplica(ClaudiaData claudiaData, TierInstance tierInstance); void deployVM(ClaudiaData claudiaData, TierInstance tierInstance, int replica, VM vm); String ImageScalability(ClaudiaData claudiaData, TierInstance tierInstance); void deployNetworks(ClaudiaData data, TierInstance tierInstance); void setClaudiaClient(ClaudiaClient claudiaClient); void setClaudiaResponseAnalyser(ClaudiaResponseAnalyser claudiaResponseAnalyser); void setEnvironmentInstanceDao(EnvironmentInstanceDao environmentInstanceDao); void setSystemPropertiesProvider(SystemPropertiesProvider systemPropertiesProvider); void setTierInstanceManager(TierInstanceManager tierInstanceManager); String StartStopScalability(ClaudiaData claudiaData, boolean b); void setNetworkInstanceManager(NetworkInstanceManager networkInstanceManager); void setNetworkManager(NetworkManager networkManager); void setTierManager(TierManager tierManager); String getFederatedRange(ClaudiaData data, String region); void federatedNetworks(ClaudiaData data, EnvironmentInstance environmentInstance);  }
@Test public void testDeleteInfrastructureEnvironmentInstance() throws Exception { Network net = new Network("NET", "vdc", "region"); tier.addNetwork(net); TierInstance tierInstance = new TierInstance(); tierInstance.setTier(tier); tierInstance.addNetworkInstance(net.toNetworkInstance()); Set<Tier> lTier = new HashSet<Tier>(); lTier.add(tier); Environment env = new Environment("name", "description", lTier); EnvironmentInstance envInst = new EnvironmentInstance("blue", "des", env); String ovf = null; tierInstance.setOvf(ovf); tierInstance.setVapp("vapp"); tierInstance.setVM(vm); envInst.addTierInstance(tierInstance); when(claudiaClient.existsVMReplica(any(ClaudiaData.class), any(String.class), any(VM.class), anyString())) .thenReturn(true); Mockito.doNothing().when(claudiaClient).undeployVMReplica(any(ClaudiaData.class), any(TierInstance.class)); Mockito.doNothing().when(networkInstanceManager) .delete(any(ClaudiaData.class), any(NetworkInstance.class), anyString()); when(tierInstanceManager.loadNetworkInstnace(any(String.class))).thenReturn(tierInstance); manager.deleteEnvironment(claudiaData, envInst); }