@Test public void getDeployments() throws Exception { DeploymentRest deploymentRest = new DeploymentRest(); Application application = new Application(); application.setId(1); application.setName("Application Name"); Deployment deployment1 = new Deployment(); deployment1.setId(1); deployment1.setOvf("ovf1"); deployment1.setPrice("price1"); deployment1.setStatus("Status1"); Deployment deployment2 = new Deployment(); deployment2.setId(2); deployment2.setOvf("ovf2"); deployment2.setPrice("price2"); deployment2.setStatus("Status2"); application.addDeployment(deployment1); application.addDeployment(deployment2); ApplicationDAO applicationDAO = mock(ApplicationDAO.class); deploymentRest.applicationDAO = applicationDAO; when(applicationDAO.getByName("1")).thenReturn(application); Response response = deploymentRest.getDeployments("1", ""); 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/1/deployments", collection.getHref()); assertEquals(0, collection.getItems().getOffset()); assertEquals(2, collection.getItems().getTotal()); assertEquals(2, collection.getItems().getDeployments().size()); deployment1 = collection.getItems().getDeployments().get(0); assertEquals("/applications/1/deployments/1", deployment1.getLinks().get(1).getHref()); assertEquals("self", deployment1.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, deployment1.getLinks().get(1).getType()); assertEquals("/applications/1/deployments", deployment1.getLinks().get(0).getHref()); assertEquals("parent", deployment1.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, deployment1.getLinks().get(0).getType()); assertEquals("/applications/1/deployments/1/ovf", deployment1.getLinks().get(2).getHref()); assertEquals("ovf", deployment1.getLinks().get(2).getRel()); assertEquals(MediaType.APPLICATION_XML, deployment1.getLinks().get(2).getType()); assertEquals("/applications/1/deployments/1/vms", deployment1.getLinks().get(3).getHref()); assertEquals("vms", deployment1.getLinks().get(3).getRel()); assertEquals(MediaType.APPLICATION_XML, deployment1.getLinks().get(3).getType()); assertEquals("ovf1", deployment1.getOvf()); assertEquals("price1", deployment1.getPrice()); assertEquals("Status1", deployment1.getStatus()); deployment2 = collection.getItems().getDeployments().get(1); assertEquals("/applications/1/deployments/2", deployment2.getLinks().get(1).getHref()); assertEquals("self", deployment2.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, deployment1.getLinks().get(1).getType()); assertEquals("/applications/1/deployments", deployment2.getLinks().get(0).getHref()); assertEquals("parent", deployment1.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, deployment2.getLinks().get(0).getType()); assertEquals("/applications/1/deployments/2/ovf", deployment2.getLinks().get(2).getHref()); assertEquals("ovf", deployment2.getLinks().get(2).getRel()); assertEquals(MediaType.APPLICATION_XML, deployment2.getLinks().get(2).getType()); assertEquals("/applications/1/deployments/2/vms", deployment2.getLinks().get(3).getHref()); assertEquals("vms", deployment2.getLinks().get(3).getRel()); assertEquals(MediaType.APPLICATION_XML, deployment1.getLinks().get(3).getType()); assertEquals("ovf2", deployment2.getOvf()); assertEquals("price2", deployment2.getPrice()); assertEquals("Status2", deployment2.getStatus()); }
@GET @Produces(MediaType.APPLICATION_XML + ";qs=1") public Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status) { logger.info("GET request to paht: /applications/" + applicationName + "/deployments?status=" + status + " [XML]"); List<Deployment> deployments = getDeploymentsList(applicationName, status); String xml = XMLBuilder.getCollectionOfDeploymentsXML(deployments, applicationName); return buildResponse(Status.OK, xml); }
DeploymentRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") public Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status) { logger.info("GET request to paht: /applications/" + applicationName + "/deployments?status=" + status + " [XML]"); List<Deployment> deployments = getDeploymentsList(applicationName, status); String xml = XMLBuilder.getCollectionOfDeploymentsXML(deployments, applicationName); return buildResponse(Status.OK, xml); } }
DeploymentRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") public Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status) { logger.info("GET request to paht: /applications/" + applicationName + "/deployments?status=" + status + " [XML]"); List<Deployment> deployments = getDeploymentsList(applicationName, status); String xml = XMLBuilder.getCollectionOfDeploymentsXML(deployments, applicationName); return buildResponse(Status.OK, xml); }  }
DeploymentRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") public Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status) { logger.info("GET request to paht: /applications/" + applicationName + "/deployments?status=" + status + " [XML]"); List<Deployment> deployments = getDeploymentsList(applicationName, status); String xml = XMLBuilder.getCollectionOfDeploymentsXML(deployments, applicationName); return buildResponse(Status.OK, xml); }  @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status); @GET @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getDeploymentsJSON(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postDeployment(@PathParam("application_name") String applicationName, @QueryParam("negotiation") String negotiation,  @QueryParam("schema") String schema, String payload); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) Response postDeploymentJSON(@PathParam("application_name") String applicationName, @QueryParam("negotiation") String negotiation,  @QueryParam("schema") String schema, String payload); @OPTIONS @Path("{deployment_id}") Response optionsForSpecificDeployment(); @GET @Path("{deployment_id}") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getDeploymentJSON(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/agreement") @Produces(MediaType.APPLICATION_XML) Response getDeploymentAgreement(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/ovf") @Produces(MediaType.APPLICATION_XML) Response getDeploymentOvf(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @PUT @Path("{deployment_id}/agreement") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response putDeploymentAgreement(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/cost-consumption") @Produces(MediaType.APPLICATION_XML) Response getCost(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getEnergyConsumptionXML(@PathParam("application_name") String applicationName, 
										 @PathParam("deployment_id") String deploymentId,
										 @QueryParam("startTime") String startTime,
			                             @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/energy-consumption") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getEnergyConsumptionJSON(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("startTime") String startTime,
            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/power-consumption") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getPowerConsumptionXML(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("startTime") String startTime,
			                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/power-consumption") @Produces(MediaType.APPLICATION_JSON + ";qs=0,5") Response getPowerConsumptionJSON(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("startTime") String startTime,
			                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimation(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimation(@PathParam("application_name") String applicationName, 
									   @PathParam("deployment_id") String deploymentId,
										@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimationForEvent(@PathParam("application_name") String applicationName, 
												@PathParam("deployment_id") String deploymentId, 
												@PathParam("event_id") String eventId,
												@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimationForEvent(@PathParam("application_name") String applicationName, 
											   @PathParam("deployment_id") String deploymentId, 
											   @PathParam("event_id") String eventId,
											   @QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEnergyMeasurementForEvent(@PathParam("application_name") String applicationName, 
												 @PathParam("deployment_id") String deploymentId, 
												 @PathParam("event_id") String eventId,
												 @QueryParam("startTime") String startTime,
					                             @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getPowerConsumptionForEvent(@PathParam("application_name") String applicationName, 
												@PathParam("deployment_id") String deploymentId, 
												@PathParam("event_id") String eventId,
					                            @QueryParam("startTime") String startTime,
					                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @QueryParam("duration") String duration); @GET @Path("{deployment_id}/events/{event_id}/cost-estimation") @Produces(MediaType.APPLICATION_XML) Response getCostEstimation(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @PathParam("event_id") String eventId); @GET @Path("{deployment_id}/sla-limits") @Produces(MediaType.APPLICATION_XML) Response getSLALimits(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @POST @Path("{deployment_id}/renegotiate") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response renegotiateWithPayload(@PathParam("application_name") String applicationName,@PathParam("deployment_id") String deploymentId, String payload); @GET @Path("{deployment_id}/renegotiate") @Produces(MediaType.APPLICATION_XML) Response renegotiate(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/predict-price-next-hour") @Produces(MediaType.APPLICATION_XML) Response predictPriceNextHour(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); }
DeploymentRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") public Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status) { logger.info("GET request to paht: /applications/" + applicationName + "/deployments?status=" + status + " [XML]"); List<Deployment> deployments = getDeploymentsList(applicationName, status); String xml = XMLBuilder.getCollectionOfDeploymentsXML(deployments, applicationName); return buildResponse(Status.OK, xml); }  @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getDeployments(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status); @GET @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getDeploymentsJSON(@PathParam("application_name") String applicationName, @DefaultValue("")@QueryParam("status") String status); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postDeployment(@PathParam("application_name") String applicationName, @QueryParam("negotiation") String negotiation,  @QueryParam("schema") String schema, String payload); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) Response postDeploymentJSON(@PathParam("application_name") String applicationName, @QueryParam("negotiation") String negotiation,  @QueryParam("schema") String schema, String payload); @OPTIONS @Path("{deployment_id}") Response optionsForSpecificDeployment(); @GET @Path("{deployment_id}") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getDeploymentJSON(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/agreement") @Produces(MediaType.APPLICATION_XML) Response getDeploymentAgreement(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/ovf") @Produces(MediaType.APPLICATION_XML) Response getDeploymentOvf(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @PUT @Path("{deployment_id}/agreement") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response putDeploymentAgreement(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @DELETE @Path("{deployment_id}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) Response deleteDeployment(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/cost-consumption") @Produces(MediaType.APPLICATION_XML) Response getCost(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getEnergyConsumptionXML(@PathParam("application_name") String applicationName, 
										 @PathParam("deployment_id") String deploymentId,
										 @QueryParam("startTime") String startTime,
			                             @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/energy-consumption") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getEnergyConsumptionJSON(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId, @QueryParam("startTime") String startTime,
            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/power-consumption") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getPowerConsumptionXML(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("startTime") String startTime,
			                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/power-consumption") @Produces(MediaType.APPLICATION_JSON + ";qs=0,5") Response getPowerConsumptionJSON(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("startTime") String startTime,
			                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimation(@PathParam("application_name") String applicationName, 
										@PathParam("deployment_id") String deploymentId,
										@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimation(@PathParam("application_name") String applicationName, 
									   @PathParam("deployment_id") String deploymentId,
										@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/energy-estimation") @Produces(MediaType.APPLICATION_XML) Response getEnergyEstimationForEvent(@PathParam("application_name") String applicationName, 
												@PathParam("deployment_id") String deploymentId, 
												@PathParam("event_id") String eventId,
												@QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/power-estimation") @Produces(MediaType.APPLICATION_XML) Response getPowerEstimationForEvent(@PathParam("application_name") String applicationName, 
											   @PathParam("deployment_id") String deploymentId, 
											   @PathParam("event_id") String eventId,
											   @QueryParam("duration") String durationQuery); @GET @Path("{deployment_id}/events/{event_id}/energy-consumption") @Produces(MediaType.APPLICATION_XML) Response getEnergyMeasurementForEvent(@PathParam("application_name") String applicationName, 
												 @PathParam("deployment_id") String deploymentId, 
												 @PathParam("event_id") String eventId,
												 @QueryParam("startTime") String startTime,
					                             @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/events/{event_id}/power-consumption") @Produces(MediaType.APPLICATION_XML) Response getPowerConsumptionForEvent(@PathParam("application_name") String applicationName, 
												@PathParam("deployment_id") String deploymentId, 
												@PathParam("event_id") String eventId,
					                            @QueryParam("startTime") String startTime,
					                            @QueryParam("endTime") String endTime); @GET @Path("{deployment_id}/predicted-price-for-next-period") @Produces(MediaType.APPLICATION_XML) Response getPredictedPriceForNextPeriod(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @QueryParam("duration") String duration); @GET @Path("{deployment_id}/events/{event_id}/cost-estimation") @Produces(MediaType.APPLICATION_XML) Response getCostEstimation(@PathParam("application_name") String applicationName, 
			                          @PathParam("deployment_id") String deploymentId,
			                          @PathParam("event_id") String eventId); @GET @Path("{deployment_id}/sla-limits") @Produces(MediaType.APPLICATION_XML) Response getSLALimits(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @POST @Path("{deployment_id}/renegotiate") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response renegotiateWithPayload(@PathParam("application_name") String applicationName,@PathParam("deployment_id") String deploymentId, String payload); @GET @Path("{deployment_id}/renegotiate") @Produces(MediaType.APPLICATION_XML) Response renegotiate(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{deployment_id}/predict-price-next-hour") @Produces(MediaType.APPLICATION_XML) Response predictPriceNextHour(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId);  }