@Test public void getAgreementsTest() throws JAXBException { Agreement agreement1 = new Agreement(); agreement1.setAccepted(false); agreement1.setId(1); agreement1.setPrice("111"); agreement1.setProviderId("provider-id1"); agreement1.setSlaAgreement("sssas1"); agreement1.setSlaAgreementId("sla-agreement-id1"); Agreement agreement2 = new Agreement(); agreement2.setAccepted(true); agreement2.setId(2); agreement2.setPrice("222"); agreement2.setProviderId("provider-id"); agreement2.setSlaAgreement("sssas"); agreement2.setSlaAgreementId("sla-agreement-id"); Deployment deployment = new Deployment(); deployment.addAgreement(agreement1); deployment.addAgreement(agreement2); DeploymentDAO deploymentDAO = mock(DeploymentDAO.class); when(deploymentDAO.getById(223)).thenReturn(deployment); AgreementRest agreementRest = new AgreementRest(); agreementRest.deploymentDAO = deploymentDAO; Response response = agreementRest.getAgreements("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/agreements", 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/agreements", 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().getAgreements().size()); Agreement agreement = collection.getItems().getAgreements().get(0); assertEquals("/applications/app-id/deployments/223/agreements/1", agreement.getHref()); assertEquals("111", agreement.getPrice()); assertEquals(1, agreement.getId()); assertEquals("provider-id1", agreement.getProviderId()); assertEquals("sla-agreement-id1", agreement.getSlaAgreementId()); assertEquals(2, agreement.getLinks().size()); assertEquals("/applications/app-id/deployments/223/agreements", agreement.getLinks().get(0).getHref()); assertEquals("parent", agreement.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, agreement.getLinks().get(0).getType()); assertEquals("/applications/app-id/deployments/223/agreements/1", agreement.getLinks().get(1).getHref()); assertEquals("self", agreement.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, agreement.getLinks().get(1).getType()); agreement = collection.getItems().getAgreements().get(1); assertEquals("/applications/app-id/deployments/223/agreements/2", agreement.getHref()); assertEquals("222", agreement.getPrice()); assertEquals(2, agreement.getId()); assertEquals("provider-id", agreement.getProviderId()); assertEquals("sla-agreement-id", agreement.getSlaAgreementId()); assertEquals(2, agreement.getLinks().size()); assertEquals("/applications/app-id/deployments/223/agreements", agreement.getLinks().get(0).getHref()); assertEquals("parent", agreement.getLinks().get(0).getRel()); assertEquals(MediaType.APPLICATION_XML, agreement.getLinks().get(0).getType()); assertEquals("/applications/app-id/deployments/223/agreements/2", agreement.getLinks().get(1).getHref()); assertEquals("self", agreement.getLinks().get(1).getRel()); assertEquals(MediaType.APPLICATION_XML, agreement.getLinks().get(1).getType()); }
@GET @Produces(MediaType.APPLICATION_XML) public Response getAgreements(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/agreements"); List<Agreement> agreements = deploymentDAO.getById(Integer.parseInt(deploymentId)).getAgreements(); String xml = XMLBuilder.getCollectionOfAgreements(agreements, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); }
AgreementRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getAgreements(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/agreements"); List<Agreement> agreements = deploymentDAO.getById(Integer.parseInt(deploymentId)).getAgreements(); String xml = XMLBuilder.getCollectionOfAgreements(agreements, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); } }
AgreementRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getAgreements(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/agreements"); List<Agreement> agreements = deploymentDAO.getById(Integer.parseInt(deploymentId)).getAgreements(); String xml = XMLBuilder.getCollectionOfAgreements(agreements, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); }  }
AgreementRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getAgreements(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/agreements"); List<Agreement> agreements = deploymentDAO.getById(Integer.parseInt(deploymentId)).getAgreements(); String xml = XMLBuilder.getCollectionOfAgreements(agreements, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); }  @GET @Produces(MediaType.APPLICATION_XML) Response getAgreements(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{agreement_id}") @Produces(MediaType.APPLICATION_XML) Response getAgreement(@PathParam("application_name") String applicationName, 
			                     @PathParam("deployment_id") String deploymentId,
			                     @PathParam("agreement_id") String agreementId); @GET @Path("{agreement_id}/sla") @Produces(MediaType.APPLICATION_XML) Response getSlaAgreement(@PathParam("application_name") String applicationName, 
			                     @PathParam("deployment_id") String deploymentId,
			                     @PathParam("agreement_id") String agreementId); @PUT @Path("{agreement_id}") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response acceptSlaAgreement(@PathParam("application_name") String applicationName, 
									   @PathParam("deployment_id") String deploymentId,
									   @PathParam("agreement_id") String agreementId,
									   String payload); }
AgreementRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getAgreements(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId) { logger.info("GET request to path: /applications/" + applicationName + "/deployments/" + deploymentId + "/agreements"); List<Agreement> agreements = deploymentDAO.getById(Integer.parseInt(deploymentId)).getAgreements(); String xml = XMLBuilder.getCollectionOfAgreements(agreements, applicationName, Integer.parseInt(deploymentId)); return buildResponse(Status.OK, xml); }  @GET @Produces(MediaType.APPLICATION_XML) Response getAgreements(@PathParam("application_name") String applicationName, @PathParam("deployment_id") String deploymentId); @GET @Path("{agreement_id}") @Produces(MediaType.APPLICATION_XML) Response getAgreement(@PathParam("application_name") String applicationName, 
			                     @PathParam("deployment_id") String deploymentId,
			                     @PathParam("agreement_id") String agreementId); @GET @Path("{agreement_id}/sla") @Produces(MediaType.APPLICATION_XML) Response getSlaAgreement(@PathParam("application_name") String applicationName, 
			                     @PathParam("deployment_id") String deploymentId,
			                     @PathParam("agreement_id") String agreementId); @PUT @Path("{agreement_id}") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response acceptSlaAgreement(@PathParam("application_name") String applicationName, 
									   @PathParam("deployment_id") String deploymentId,
									   @PathParam("agreement_id") String agreementId,
									   String payload);  }