test_class.file: api/src/test/java/com/abiquo/api/services/cloud/VirtualDatacenterServiceTest.java
test_class.identifier: VirtualDatacenterServiceTest
test_class.superclass: extends AbstractUnitTest
test_case.body: @Test
      public void createVirtualDatacenterByUserWithVdcsAssigned() throws Exception
      {
          Enterprise enterprise = enterpriseGenerator.createUniqueInstance();
          Datacenter d = datacenterGenerator.createUniqueInstance();
          Machine machine = machineGenerator.createMachine(d);
          Hypervisor hypervisor = hypervisorGenerator.createInstance(machine, HypervisorType.KVM);
          VirtualDatacenter vdc = vdcGenerator.createInstance(d, enterprise, HypervisorType.KVM);
          VirtualDatacenter vdc1 = vdcGenerator.createInstance(d, enterprise, HypervisorType.KVM);
          DatacenterLimits dl = datacenterLimitsGenerator.createInstance(enterprise, d);
          setup(enterprise, d, dl, machine, hypervisor, vdc);
  
          Role role = roleGenerator.createInstance();
          User user = userGenerator.createInstance(enterprise, role);
          user.setAvailableVirtualDatacenters(vdc.getId().toString());
  
          setup(role, user);
  
          SecurityContextHolder.getContext().setAuthentication(
              new BasicUserAuthentication(user.getNick()));
  
          EntityManager em = getEntityManagerWithAnActiveTransaction();
  
          DatacenterService datacenterService = new DatacenterService(em);
          VirtualDatacenterService service = new VirtualDatacenterService(em);
  
          Datacenter datacenter = datacenterService.getDatacenter(d.getId());
  
          VirtualDatacenterDto dto = VirtualDatacenterResource.createTransferObject(vdc1);
          VLANNetworkDto networkDto = new VLANNetworkDto();
          networkDto.setName("DefaultNetwork");
          networkDto.setAddress("192.168.0.0");
          networkDto.setGateway("192.168.0.1");
          networkDto.setMask(24);
          networkDto.setPrimaryDNS("10.0.0.1");
          networkDto.setSecondaryDNS("10.0.0.1");
  
          dto.setVlan(networkDto);
  
          VirtualDatacenter virtualDatacenter =
              service.createVirtualDatacenter(dto, datacenter, enterprise);
  
          UserService userService = new UserService(em);
  
          User currentUser = userService.getCurrentUser();
  
          commitActiveTransaction(em);
  
          org.testng.Assert.assertTrue(currentUser.getAvailableVirtualDatacenters().endsWith(
              "," + virtualDatacenter.getId()));
      }
test_case.class_method_signature: VirtualDatacenterServiceTest.createVirtualDatacenterByUserWithVdcsAssigned()
test_case.full_signature: @Test public void createVirtualDatacenterByUserWithVdcsAssigned()
test_case.identifier: createVirtualDatacenterByUserWithVdcsAssigned
test_case.invocations: createUniqueInstance createUniqueInstance createMachine createInstance createInstance createInstance createInstance setup createInstance createInstance setAvailableVirtualDatacenters toString getId setup setAuthentication getContext getNick getEntityManagerWithAnActiveTransaction getDatacenter getId createTransferObject setName setAddress setGateway setMask setPrimaryDNS setSecondaryDNS setVlan createVirtualDatacenter getCurrentUser commitActiveTransaction assertTrue endsWith getAvailableVirtualDatacenters getId
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void createVirtualDatacenterByUserWithVdcsAssigned()
focal_class.declarator: FENCE_MODE = "bridge"
focal_class.modifier: public static final
focal_class.original_string: public static final String FENCE_MODE = "bridge";
focal_class.type: String
focal_class.var_name: FENCE_MODE
focal_class.declarator: userService
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      UserService userService;
focal_class.type: UserService
focal_class.var_name: userService
focal_class.declarator: datacenterRepo
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      InfrastructureRep datacenterRepo;
focal_class.type: InfrastructureRep
focal_class.var_name: datacenterRepo
focal_class.declarator: repo
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      VirtualDatacenterRep repo;
focal_class.type: VirtualDatacenterRep
focal_class.var_name: repo
focal_class.declarator: datacenterLimitsDao
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      DatacenterLimitsDAO datacenterLimitsDao;
focal_class.type: DatacenterLimitsDAO
focal_class.var_name: datacenterLimitsDao
focal_class.declarator: networkService
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      NetworkService networkService;
focal_class.type: NetworkService
focal_class.var_name: networkService
focal_class.declarator: securityService
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      SecurityService securityService;
focal_class.type: SecurityService
focal_class.var_name: securityService
focal_class.file: api/src/main/java/com/abiquo/api/services/cloud/VirtualDatacenterService.java
focal_class.identifier: VirtualDatacenterService
focal_class.class_method_signature: VirtualDatacenterService.VirtualDatacenterService()
focal_class.full_signature: public  VirtualDatacenterService()
focal_class.identifier: VirtualDatacenterService
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  VirtualDatacenterService()
focal_class.class_method_signature: VirtualDatacenterService.VirtualDatacenterService(final EntityManager em)
focal_class.full_signature: public  VirtualDatacenterService(final EntityManager em)
focal_class.identifier: VirtualDatacenterService
focal_class.modifiers: public
focal_class.parameters: (final EntityManager em)
focal_class.signature:  VirtualDatacenterService(final EntityManager em)
focal_class.class_method_signature: VirtualDatacenterService.getVirtualDatacenters(final Enterprise enterprise,
          final Datacenter datacenter, final FilterOptions filterOptions)
focal_class.full_signature: public Collection<VirtualDatacenter> getVirtualDatacenters(final Enterprise enterprise,
          final Datacenter datacenter, final FilterOptions filterOptions)
focal_class.identifier: getVirtualDatacenters
focal_class.modifiers: public
focal_class.parameters: (final Enterprise enterprise,
          final Datacenter datacenter, final FilterOptions filterOptions)
focal_class.return: Collection<VirtualDatacenter>
focal_class.signature: Collection<VirtualDatacenter> getVirtualDatacenters(final Enterprise enterprise,
          final Datacenter datacenter, final FilterOptions filterOptions)
focal_class.class_method_signature: VirtualDatacenterService.getVirtualDatacenters(Enterprise enterprise,
          final Datacenter datacenter, final User user, final FilterOptions filterOptions)
focal_class.full_signature: public Collection<VirtualDatacenter> getVirtualDatacenters(Enterprise enterprise,
          final Datacenter datacenter, final User user, final FilterOptions filterOptions)
focal_class.identifier: getVirtualDatacenters
focal_class.modifiers: public
focal_class.parameters: (Enterprise enterprise,
          final Datacenter datacenter, final User user, final FilterOptions filterOptions)
focal_class.return: Collection<VirtualDatacenter>
focal_class.signature: Collection<VirtualDatacenter> getVirtualDatacenters(Enterprise enterprise,
          final Datacenter datacenter, final User user, final FilterOptions filterOptions)
focal_class.class_method_signature: VirtualDatacenterService.getVirtualDatacentersByDatacenter(
          final Datacenter datacenter, final Integer startwith, final Integer limit,
          final String filter, final OrderByEnum orderByEnum, final Boolean asc)
focal_class.full_signature: public Collection<VirtualDatacenter> getVirtualDatacentersByDatacenter(
          final Datacenter datacenter, final Integer startwith, final Integer limit,
          final String filter, final OrderByEnum orderByEnum, final Boolean asc)
focal_class.identifier: getVirtualDatacentersByDatacenter
focal_class.modifiers: public
focal_class.parameters: (
          final Datacenter datacenter, final Integer startwith, final Integer limit,
          final String filter, final OrderByEnum orderByEnum, final Boolean asc)
focal_class.return: Collection<VirtualDatacenter>
focal_class.signature: Collection<VirtualDatacenter> getVirtualDatacentersByDatacenter(
          final Datacenter datacenter, final Integer startwith, final Integer limit,
          final String filter, final OrderByEnum orderByEnum, final Boolean asc)
focal_class.class_method_signature: VirtualDatacenterService.getVirtualDatacenter(final Integer id)
focal_class.full_signature: @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public VirtualDatacenter getVirtualDatacenter(final Integer id)
focal_class.identifier: getVirtualDatacenter
focal_class.modifiers: @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public
focal_class.parameters: (final Integer id)
focal_class.return: VirtualDatacenter
focal_class.signature: VirtualDatacenter getVirtualDatacenter(final Integer id)
focal_class.class_method_signature: VirtualDatacenterService.createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise)
focal_class.full_signature: @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public VirtualDatacenter createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise)
focal_class.identifier: createVirtualDatacenter
focal_class.modifiers: @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public
focal_class.parameters: (final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise)
focal_class.return: VirtualDatacenter
focal_class.signature: VirtualDatacenter createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise)
focal_class.class_method_signature: VirtualDatacenterService.assignVirtualDatacenterToUser(final VirtualDatacenter vdc)
focal_class.full_signature: private void assignVirtualDatacenterToUser(final VirtualDatacenter vdc)
focal_class.identifier: assignVirtualDatacenterToUser
focal_class.modifiers: private
focal_class.parameters: (final VirtualDatacenter vdc)
focal_class.return: void
focal_class.signature: void assignVirtualDatacenterToUser(final VirtualDatacenter vdc)
focal_class.class_method_signature: VirtualDatacenterService.isValidEnterpriseDatacenter(final Enterprise enterprise,
          final Datacenter datacenter)
focal_class.full_signature: protected boolean isValidEnterpriseDatacenter(final Enterprise enterprise,
          final Datacenter datacenter)
focal_class.identifier: isValidEnterpriseDatacenter
focal_class.modifiers: protected
focal_class.parameters: (final Enterprise enterprise,
          final Datacenter datacenter)
focal_class.return: boolean
focal_class.signature: boolean isValidEnterpriseDatacenter(final Enterprise enterprise,
          final Datacenter datacenter)
focal_class.class_method_signature: VirtualDatacenterService.updateVirtualDatacenter(final Integer id,
          final VirtualDatacenterDto dto)
focal_class.full_signature: @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public VirtualDatacenter updateVirtualDatacenter(final Integer id,
          final VirtualDatacenterDto dto)
focal_class.identifier: updateVirtualDatacenter
focal_class.modifiers: @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public
focal_class.parameters: (final Integer id,
          final VirtualDatacenterDto dto)
focal_class.return: VirtualDatacenter
focal_class.signature: VirtualDatacenter updateVirtualDatacenter(final Integer id,
          final VirtualDatacenterDto dto)
focal_class.class_method_signature: VirtualDatacenterService.updateVirtualDatacenter(final VirtualDatacenter vdc,
          final VirtualDatacenterDto dto)
focal_class.full_signature: protected VirtualDatacenter updateVirtualDatacenter(final VirtualDatacenter vdc,
          final VirtualDatacenterDto dto)
focal_class.identifier: updateVirtualDatacenter
focal_class.modifiers: protected
focal_class.parameters: (final VirtualDatacenter vdc,
          final VirtualDatacenterDto dto)
focal_class.return: VirtualDatacenter
focal_class.signature: VirtualDatacenter updateVirtualDatacenter(final VirtualDatacenter vdc,
          final VirtualDatacenterDto dto)
focal_class.class_method_signature: VirtualDatacenterService.deleteVirtualDatacenter(final Integer id)
focal_class.full_signature: @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public void deleteVirtualDatacenter(final Integer id)
focal_class.identifier: deleteVirtualDatacenter
focal_class.modifiers: @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public
focal_class.parameters: (final Integer id)
focal_class.return: void
focal_class.signature: void deleteVirtualDatacenter(final Integer id)
focal_class.class_method_signature: VirtualDatacenterService.createNetwork()
focal_class.full_signature: private Network createNetwork()
focal_class.identifier: createNetwork
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: Network
focal_class.signature: Network createNetwork()
focal_class.class_method_signature: VirtualDatacenterService.createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise, final Network network)
focal_class.full_signature: private VirtualDatacenter createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise, final Network network)
focal_class.identifier: createVirtualDatacenter
focal_class.modifiers: private
focal_class.parameters: (final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise, final Network network)
focal_class.return: VirtualDatacenter
focal_class.signature: VirtualDatacenter createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise, final Network network)
focal_class.class_method_signature: VirtualDatacenterService.setLimits(final VirtualDatacenterDto dto, final VirtualDatacenter vdc)
focal_class.full_signature: private void setLimits(final VirtualDatacenterDto dto, final VirtualDatacenter vdc)
focal_class.identifier: setLimits
focal_class.modifiers: private
focal_class.parameters: (final VirtualDatacenterDto dto, final VirtualDatacenter vdc)
focal_class.return: void
focal_class.signature: void setLimits(final VirtualDatacenterDto dto, final VirtualDatacenter vdc)
focal_class.class_method_signature: VirtualDatacenterService.validateVirtualDatacenter(final VirtualDatacenter vdc, final VLANNetworkDto vlan,
          final Datacenter datacenter)
focal_class.full_signature: private void validateVirtualDatacenter(final VirtualDatacenter vdc, final VLANNetworkDto vlan,
          final Datacenter datacenter)
focal_class.identifier: validateVirtualDatacenter
focal_class.modifiers: private
focal_class.parameters: (final VirtualDatacenter vdc, final VLANNetworkDto vlan,
          final Datacenter datacenter)
focal_class.return: void
focal_class.signature: void validateVirtualDatacenter(final VirtualDatacenter vdc, final VLANNetworkDto vlan,
          final Datacenter datacenter)
focal_class.class_method_signature: VirtualDatacenterService.isValidVlanHardLimitPerVdc(final long vlansHard)
focal_class.full_signature: private boolean isValidVlanHardLimitPerVdc(final long vlansHard)
focal_class.identifier: isValidVlanHardLimitPerVdc
focal_class.modifiers: private
focal_class.parameters: (final long vlansHard)
focal_class.return: boolean
focal_class.signature: boolean isValidVlanHardLimitPerVdc(final long vlansHard)
focal_class.class_method_signature: VirtualDatacenterService.isValidHypervisorForDatacenter(final HypervisorType type,
          final Datacenter datacenter)
focal_class.full_signature: private boolean isValidHypervisorForDatacenter(final HypervisorType type,
          final Datacenter datacenter)
focal_class.identifier: isValidHypervisorForDatacenter
focal_class.modifiers: private
focal_class.parameters: (final HypervisorType type,
          final Datacenter datacenter)
focal_class.return: boolean
focal_class.signature: boolean isValidHypervisorForDatacenter(final HypervisorType type,
          final Datacenter datacenter)
focal_class.class_method_signature: VirtualDatacenterService.getNodeVirtualImageByEnterprise(final Enterprise enterprise)
focal_class.full_signature: public Collection<NodeVirtualImage> getNodeVirtualImageByEnterprise(final Enterprise enterprise)
focal_class.identifier: getNodeVirtualImageByEnterprise
focal_class.modifiers: public
focal_class.parameters: (final Enterprise enterprise)
focal_class.return: Collection<NodeVirtualImage>
focal_class.signature: Collection<NodeVirtualImage> getNodeVirtualImageByEnterprise(final Enterprise enterprise)
focal_class.class_method_signature: VirtualDatacenterService.detach(final VirtualDatacenter virtualDatacenter)
focal_class.full_signature: public void detach(final VirtualDatacenter virtualDatacenter)
focal_class.identifier: detach
focal_class.modifiers: public
focal_class.parameters: (final VirtualDatacenter virtualDatacenter)
focal_class.return: void
focal_class.signature: void detach(final VirtualDatacenter virtualDatacenter)
focal_class.superclass: extends DefaultApiService
focal_method.body: @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
      public VirtualDatacenter createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise) throws Exception
      {
          if (!isValidEnterpriseDatacenter(enterprise, datacenter))
          {
              addForbiddenErrors(APIError.DATACENTER_NOT_ALLOWED);
              flushErrors();
          }
  
          Network network = createNetwork();
          VirtualDatacenter vdc = createVirtualDatacenter(dto, datacenter, enterprise, network);
  
          // set as default vlan (as it is the first one) and create it.
          VLANNetwork vlan =
              networkService.createPrivateNetwork(vdc.getId(), PrivateNetworkResource
                  .createPersistenceObject(dto.getVlan()), false);
  
          // find the default vlan stablished by the enterprise-datacenter limits
          DatacenterLimits dcLimits =
              datacenterRepo.findDatacenterLimits(vdc.getEnterprise(), vdc.getDatacenter());
          if (dcLimits.getDefaultVlan() != null)
          {
              vdc.setDefaultVlan(dcLimits.getDefaultVlan());
          }
          else
          {
              vdc.setDefaultVlan(vlan);
          }
          repo.update(vdc);
  
          assignVirtualDatacenterToUser(vdc);
  
          return vdc;
      }
focal_method.class_method_signature: VirtualDatacenterService.createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise)
focal_method.full_signature: @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public VirtualDatacenter createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise)
focal_method.identifier: createVirtualDatacenter
focal_method.invocations: isValidEnterpriseDatacenter addForbiddenErrors flushErrors createNetwork createVirtualDatacenter createPrivateNetwork getId createPersistenceObject getVlan findDatacenterLimits getEnterprise getDatacenter getDefaultVlan setDefaultVlan getDefaultVlan setDefaultVlan update assignVirtualDatacenterToUser
focal_method.modifiers: @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public
focal_method.parameters: (final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise)
focal_method.return: VirtualDatacenter
focal_method.signature: VirtualDatacenter createVirtualDatacenter(final VirtualDatacenterDto dto,
          final Datacenter datacenter, final Enterprise enterprise)