@Test public void testDeleteNetworkWithoutEnv() throws Exception { Network net = new Network("NET", "vdc", "region"); Network net2 = new Network("Internet", "vdc", "region"); tier.addNetwork(net); tier.addNetwork(net2); TierInstance tierInstance = new TierInstance(); tierInstance.setTier(tier); Environment env = new Environment("name", "description", null); env.addTier(tier); EnvironmentInstance envInst = new EnvironmentInstance("blue", "des", env); envInst.addTierInstance(tierInstance); String region = "RegionOne"; when(tierInstanceManager.update(any(TierInstance.class))).thenReturn(tierInstance); when(networkInstanceManager.create(any(ClaudiaData.class), any(NetworkInstance.class), anyString())) .thenReturn(net.toNetworkInstance()); Mockito.doThrow(EntityNotFoundException.class).when(networkInstanceManager) .load(any(String.class), any(ClaudiaData.class), any(String.class)); manager.deleteNetworksInTierInstance(claudiaData, tierInstance); assertEquals(envInst.getTierInstances().get(0).getNetworkInstances().size(), 0); }
@Override public void deleteNetworksInTierInstance(ClaudiaData claudiaData, TierInstance tierInstance) throws InvalidEntityException, InfrastructureException, EntityNotFoundException { log.info("Delete the networks in env if there are not being used"); List<NetworkInstance> netInsts = null; try { netInsts = getNetworkInstInEnv(tierInstance); } catch (EntityNotFoundException e) { throw new InfrastructureException("It is not possible to find the network " + e.getMessage()); } tierInstance.getNetworkInstances().clear(); tierInstanceManager.update(tierInstance); for (NetworkInstance network : netInsts) { log.info("Is network default? " + network.isDefaultNet()); if (!network.isDefaultNet()) { try { networkInstanceManager.delete(claudiaData, network, network.getRegionName()); } catch (Exception e) { log.warn("It is not possible to delete the network " + network.getNetworkName() + " " + network.getRegionName() + " " + e.getMessage()); } } } }
InfrastructureManagerClaudiaImpl implements InfrastructureManager { @Override public void deleteNetworksInTierInstance(ClaudiaData claudiaData, TierInstance tierInstance) throws InvalidEntityException, InfrastructureException, EntityNotFoundException { log.info("Delete the networks in env if there are not being used"); List<NetworkInstance> netInsts = null; try { netInsts = getNetworkInstInEnv(tierInstance); } catch (EntityNotFoundException e) { throw new InfrastructureException("It is not possible to find the network " + e.getMessage()); } tierInstance.getNetworkInstances().clear(); tierInstanceManager.update(tierInstance); for (NetworkInstance network : netInsts) { log.info("Is network default? " + network.isDefaultNet()); if (!network.isDefaultNet()) { try { networkInstanceManager.delete(claudiaData, network, network.getRegionName()); } catch (Exception e) { log.warn("It is not possible to delete the network " + network.getNetworkName() + " " + network.getRegionName() + " " + e.getMessage()); } } } } }
InfrastructureManagerClaudiaImpl implements InfrastructureManager { @Override public void deleteNetworksInTierInstance(ClaudiaData claudiaData, TierInstance tierInstance) throws InvalidEntityException, InfrastructureException, EntityNotFoundException { log.info("Delete the networks in env if there are not being used"); List<NetworkInstance> netInsts = null; try { netInsts = getNetworkInstInEnv(tierInstance); } catch (EntityNotFoundException e) { throw new InfrastructureException("It is not possible to find the network " + e.getMessage()); } tierInstance.getNetworkInstances().clear(); tierInstanceManager.update(tierInstance); for (NetworkInstance network : netInsts) { log.info("Is network default? " + network.isDefaultNet()); if (!network.isDefaultNet()) { try { networkInstanceManager.delete(claudiaData, network, network.getRegionName()); } catch (Exception e) { log.warn("It is not possible to delete the network " + network.getNetworkName() + " " + network.getRegionName() + " " + e.getMessage()); } } } }  }
InfrastructureManagerClaudiaImpl implements InfrastructureManager { @Override public void deleteNetworksInTierInstance(ClaudiaData claudiaData, TierInstance tierInstance) throws InvalidEntityException, InfrastructureException, EntityNotFoundException { log.info("Delete the networks in env if there are not being used"); List<NetworkInstance> netInsts = null; try { netInsts = getNetworkInstInEnv(tierInstance); } catch (EntityNotFoundException e) { throw new InfrastructureException("It is not possible to find the network " + e.getMessage()); } tierInstance.getNetworkInstances().clear(); tierInstanceManager.update(tierInstance); for (NetworkInstance network : netInsts) { log.info("Is network default? " + network.isDefaultNet()); if (!network.isDefaultNet()) { try { networkInstanceManager.delete(claudiaData, network, network.getRegionName()); } catch (Exception e) { log.warn("It is not possible to delete the network " + network.getNetworkName() + " " + network.getRegionName() + " " + e.getMessage()); } } } }  @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); }
InfrastructureManagerClaudiaImpl implements InfrastructureManager { @Override public void deleteNetworksInTierInstance(ClaudiaData claudiaData, TierInstance tierInstance) throws InvalidEntityException, InfrastructureException, EntityNotFoundException { log.info("Delete the networks in env if there are not being used"); List<NetworkInstance> netInsts = null; try { netInsts = getNetworkInstInEnv(tierInstance); } catch (EntityNotFoundException e) { throw new InfrastructureException("It is not possible to find the network " + e.getMessage()); } tierInstance.getNetworkInstances().clear(); tierInstanceManager.update(tierInstance); for (NetworkInstance network : netInsts) { log.info("Is network default? " + network.isDefaultNet()); if (!network.isDefaultNet()) { try { networkInstanceManager.delete(claudiaData, network, network.getRegionName()); } catch (Exception e) { log.warn("It is not possible to delete the network " + network.getNetworkName() + " " + network.getRegionName() + " " + e.getMessage()); } } } }  @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);  }