@Test public void getVMsTest() throws JAXBException { VM vm1 = new VM(); vm1.setId(33); vm1.setIp("0.0.0.0"); vm1.setOvfId("vm-ovf-id"); vm1.setProviderId("provider-id"); vm1.setSlaAgreement("sla-agreement-id"); vm1.setStatus("ACTIVE"); VM vm2 = new VM(); vm2.setId(44); vm2.setIp("1.1.1.1"); vm2.setOvfId("vm-ovf-id2"); vm2.setProviderId("provider-id2"); vm2.setSlaAgreement("sla-agreement-id2"); vm2.setStatus("DELETED"); Deployment deployment = new Deployment(); deployment.addVM(vm1); deployment.addVM(vm2); DeploymentDAO deploymentDAO = mock(DeploymentDAO.class); when(deploymentDAO.getById(223)).thenReturn(deployment); VMRest vmRest = new VMRest(); vmRest.deploymentDAO = deploymentDAO; Response response = vmRest.getVMs("app-id", "223"); assertEquals(200, response.getStatus()); String xml = (String) response.getEntity(); JAXBContext jaxbContext = JAXBContext.newInstance(Collection.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Collection collection = (Collection) jaxbUnmarshaller.unmarshal(new StringReader(xml)); assertEquals("/applications/app-id/deployments/223/vms", collection.getHref()); assertEquals(0, collection.getItems().getOffset()); assertEquals(2, collection.getItems().getTotal()); assertEquals(2, collection.getLinks().size()); assertEquals("/applications/app-id/deployments/223", collection.getLinks().get(0).getHref()); assertEquals("parent", collection.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, collection.getLinks().get(0).getType()); assertEquals("/applications/app-id/deployments/223/vms", collection.getLinks().get(1).getHref()); assertEquals("self", collection.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, collection.getLinks().get(1).getType()); assertEquals(2, collection.getItems().getVms().size()); VM vm = collection.getItems().getVms().get(0); assertEquals("/applications/app-id/deployments/223/vms/33", vm.getHref()); assertEquals(33, vm.getId()); assertEquals("0.0.0.0", vm.getIp()); assertEquals("ACTIVE", vm.getStatus()); assertEquals("vm-ovf-id", vm.getOvfId()); assertEquals("provider-id", vm.getProviderId()); assertEquals(2, vm.getLinks().size()); assertEquals("/applications/app-id/deployments/223/vms", vm.getLinks().get(0).getHref()); assertEquals("parent", vm.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, vm.getLinks().get(0).getType()); assertEquals("/applications/app-id/deployments/223/vms/33", vm.getLinks().get(1).getHref()); assertEquals("self", vm.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, vm.getLinks().get(1).getType()); vm = collection.getItems().getVms().get(1); assertEquals("/applications/app-id/deployments/223/vms/44", vm.getHref()); assertEquals(44, vm.getId()); assertEquals("1.1.1.1", vm.getIp()); assertEquals("DELETED", vm.getStatus()); assertEquals("vm-ovf-id2", vm.getOvfId()); assertEquals("provider-id2", vm.getProviderId()); assertEquals(2, vm.getLinks().size()); assertEquals("/applications/app-id/deployments/223/vms", vm.getLinks().get(0).getHref()); assertEquals("parent", vm.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, vm.getLinks().get(0).getType()); assertEquals("/applications/app-id/deployments/223/vms/44", vm.getLinks().get(1).getHref()); assertEquals("self", vm.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, vm.getLinks().get(1).getType()); }
@GET @Produces(MediaType.APPLICATION_XML) public Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to /applications/" + applicationName + "/deployments/" + deploymentId + "/vms"); List<VM> vms = deploymentDAO.getById(Integer.parseInt(deploymentId)).getVms(); String xml = XMLBuilder.getCollectionOfVMs(vms, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); }
VMRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to /applications/" + applicationName + "/deployments/" + deploymentId + "/vms"); List<VM> vms = deploymentDAO.getById(Integer.parseInt(deploymentId)).getVms(); String xml = XMLBuilder.getCollectionOfVMs(vms, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); } }
VMRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to /applications/" + applicationName + "/deployments/" + deploymentId + "/vms"); List<VM> vms = deploymentDAO.getById(Integer.parseInt(deploymentId)).getVms(); String xml = XMLBuilder.getCollectionOfVMs(vms, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); }  }
VMRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to /applications/" + applicationName + "/deployments/" + deploymentId + "/vms"); List<VM> vms = deploymentDAO.getById(Integer.parseInt(deploymentId)).getVms(); String xml = XMLBuilder.getCollectionOfVMs(vms, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); }  @GET @Produces(MediaType.APPLICATION_XML) Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postVM(@PathParam("application_name") String applicationName, 
						   @PathParam("deployment_id") String deploymentId,
						   @DefaultValue("false") @QueryParam("force") boolean force,
						   String payload); @DELETE @Path("{vm_id}") Response deleteVM(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId); @GET @Path("{vm_id}") @Produces(MediaType.APPLICATION_XML) Response getVM(@PathParam("application_name") String applicationName,  @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId); @GET @Path("{vm_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimation(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @DefaultValue("0") @QueryParam("duration") long duration); @GET @Path("{vm_id}/events/{event_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimationForAnEvent(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("duration") long duration); @GET @Path("{vm_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimation(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId); @GET @Path("{vm_id}/events/{event_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimationForAnEvent(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId); @GET @Path("{vm_id}/events/{event_id}/cost-estimation") @Produces(MediaType.APPLICATION_XML) Response getCostEstimation(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @PathParam("vm_id") String vmId,
			                          @PathParam("event_id") String eventId); @GET @Path("{vm_id}/events/{event_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEventEnergyConsumption(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("startTime") long startTime,
			                             @DefaultValue("0") @QueryParam("endTime") long endTime); @GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getEventPowerConsumption(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @QueryParam("startTime") long startTime,
			                             @QueryParam("endTime") long endTime,
			                             @Context UriInfo uriInfo); @GET @Path("{vm_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEnergyConsumption(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@PathParam("vm_id") String vmId,
										@DefaultValue("0") @QueryParam("startTime") long startTime,
										@DefaultValue("0") @QueryParam("endTime") long endTime); @GET @Path("{vm_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getPowerConsumption(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@PathParam("vm_id") String vmId,
										@DefaultValue("0") @QueryParam("startTime") long startTime,
										@DefaultValue("0") @QueryParam("endTime") long endTime,
										@Context UriInfo uriInfo); @GET @Path("{vm_id}/events/{event_id}/energy-sample") @Produces(MediaType.APPLICATION_XML) Response getEnergySample(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("startTime") long startTime,
			                             @DefaultValue("0") @QueryParam("endTime") long endTime,
			                             @DefaultValue("0") @QueryParam("interval") long interval); }
VMRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to /applications/" + applicationName + "/deployments/" + deploymentId + "/vms"); List<VM> vms = deploymentDAO.getById(Integer.parseInt(deploymentId)).getVms(); String xml = XMLBuilder.getCollectionOfVMs(vms, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); }  @GET @Produces(MediaType.APPLICATION_XML) Response getVMs(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postVM(@PathParam("application_name") String applicationName, 
						   @PathParam("deployment_id") String deploymentId,
						   @DefaultValue("false") @QueryParam("force") boolean force,
						   String payload); @DELETE @Path("{vm_id}") Response deleteVM(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId); @GET @Path("{vm_id}") @Produces(MediaType.APPLICATION_XML) Response getVM(@PathParam("application_name") String applicationName,  @PathParam("deployment_id") String deploymentId, @PathParam("vm_id") String vmId); @GET @Path("{vm_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimation(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @DefaultValue("0") @QueryParam("duration") long duration); @GET @Path("{vm_id}/events/{event_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimationForAnEvent(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("duration") long duration); @GET @Path("{vm_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimation(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId); @GET @Path("{vm_id}/events/{event_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimationForAnEvent(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId); @GET @Path("{vm_id}/events/{event_id}/cost-estimation") @Produces(MediaType.APPLICATION_XML) Response getCostEstimation(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @PathParam("vm_id") String vmId,
			                          @PathParam("event_id") String eventId); @GET @Path("{vm_id}/events/{event_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEventEnergyConsumption(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("startTime") long startTime,
			                             @DefaultValue("0") @QueryParam("endTime") long endTime); @GET @Path("{vm_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getEventPowerConsumption(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @QueryParam("startTime") long startTime,
			                             @QueryParam("endTime") long endTime,
			                             @Context UriInfo uriInfo); @GET @Path("{vm_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEnergyConsumption(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@PathParam("vm_id") String vmId,
										@DefaultValue("0") @QueryParam("startTime") long startTime,
										@DefaultValue("0") @QueryParam("endTime") long endTime); @GET @Path("{vm_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getPowerConsumption(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@PathParam("vm_id") String vmId,
										@DefaultValue("0") @QueryParam("startTime") long startTime,
										@DefaultValue("0") @QueryParam("endTime") long endTime,
										@Context UriInfo uriInfo); @GET @Path("{vm_id}/events/{event_id}/energy-sample") @Produces(MediaType.APPLICATION_XML) Response getEnergySample(@PathParam("application_name") String applicationName, 
			                             @PathParam("deployment_id") String deploymentId,
			                             @PathParam("vm_id") String vmId,
			                             @PathParam("event_id") String eventId,
			                             @DefaultValue("0") @QueryParam("startTime") long startTime,
			                             @DefaultValue("0") @QueryParam("endTime") long endTime,
			                             @DefaultValue("0") @QueryParam("interval") long interval);  }