public void testValidId() { Function<Object, String> parser = new DatacenterId(); DatacenterDto datacenter = new DatacenterDto(); datacenter.setId(5); assertEquals(parser.apply(datacenter), "5"); }
/** ********************* Enterprise Limits ********************** */ public void testCreateLimits() throws SecurityException, NoSuchMethodException, IOException { EnterpriseDto enterprise = EnterpriseResources.enterprisePut(); DatacenterDto datacenter = InfrastructureResources.datacenterPut(); DatacenterLimitsDto limits = EnterpriseResources.datacenterLimitsPost(); Method method = EnterpriseAsyncClient.class.getMethod( "createLimits", EnterpriseDto.class, DatacenterDto.class, DatacenterLimitsDto.class); GeneratedHttpRequest<EnterpriseAsyncClient> request = processor.createRequest(method, enterprise, datacenter, limits); String limitsUri = enterprise.searchLink("limits").getHref(); String requestURI = String.format("POST %s?datacenter=%d HTTP/1.1", limitsUri, datacenter.getId()); assertRequestLineEquals(request, requestURI); assertNonPayloadHeadersEqual(request, "Accept: " + DatacenterLimitsDto.BASE_MEDIA_TYPE + "\n"); assertPayloadEquals( request, withHeader(EnterpriseResources.datacenterLimitsPostPayload()), DatacenterLimitsDto.BASE_MEDIA_TYPE, false); assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); checkFilters(request); }
@Transactional(propagation = Propagation.REQUIRED) public Datacenter modifyDatacenter(final Integer datacenterId, final DatacenterDto dto) { Datacenter old = getDatacenter(datacenterId); if (repo.existsAnyOtherWithName(old, dto.getName())) { addConflictErrors(APIError.DATACENTER_DUPLICATED_NAME); flushErrors(); } old.setName(dto.getName()); old.setLocation(dto.getLocation()); isValidDatacenter(old); repo.update(old); return old; }
@Transactional(propagation = Propagation.REQUIRED) public DatacenterDto addDatacenter(final DatacenterDto dto) throws Exception { if (repo.existsAnyDatacenterWithName(dto.getName())) { addConflictErrors(APIError.DATACENTER_DUPLICATED_NAME); flushErrors(); } // Create the public network before the datacenter // This network will store all the public VLANs of the datacenter. Network network = new Network(UUID.randomUUID().toString()); repo.insertNetwork(network); Datacenter datacenter = new Datacenter(dto.getName(), dto.getLocation()); isValidDatacenter(datacenter); datacenter.setNetwork(network); repo.insert(datacenter); DatacenterDto responseDto = ModelTransformer.transportFromPersistence(DatacenterDto.class, datacenter); // Add the default tiers for (int i = 1; i <= 4; i++) { Tier tier = new Tier("Default Tier " + i, "Description of the default tier " + i, datacenter); repo.insertTier(tier); } // Add the Remote Services in database in case are informed in the request if (dto.getRemoteServices() != null) { RemoteServicesDto responseRemoteService = new RemoteServicesDto(); for (RemoteServiceDto rsd : dto.getRemoteServices().getCollection()) { RemoteServiceDto rsDto = infrastructureService.addRemoteService(rsd, datacenter.getId()); responseRemoteService.add(rsDto); } responseDto.setRemoteServices(responseRemoteService); } return responseDto; }