@Test public void postAnApplicationInDBJSON() throws Exception { AmqpMessageReceiver receiver = new AmqpMessageReceiver(Configuration.amqpAddress, Configuration.amqpUsername, Configuration.amqpPassword, "APPLICATION.>", true); AmqpListListener listener = new AmqpListListener(); receiver.setMessageConsumer(listener); ApplicationDAO applicationDAO = mock(ApplicationDAO.class); Application application = new Application(); application.setId(1); application.setName("threeTierWebApp"); when(applicationDAO.getByName("threeTierWebApp")).thenReturn(application, application); when(applicationDAO.update(any(Application.class))).thenReturn(true); DeploymentEventService deploymentEventService = mock(DeploymentEventService.class); ApplicationRest applicationRest = new ApplicationRest(); applicationRest.applicationDAO = applicationDAO; applicationRest.deploymentEventService = deploymentEventService; Response response = applicationRest.postApplicationJSON("automatic", null, threeTierWebAppOvfString); assertEquals(201, response.getStatus()); String json = (String) response.getEntity(); Application applicationResponse = ModelConverter.jsonApplicationToObject(json); assertEquals(1, applicationResponse.getId()); assertEquals("/applications/threeTierWebApp", applicationResponse.getHref()); assertEquals("threeTierWebApp", applicationResponse.getName()); assertEquals(1, applicationResponse.getDeployments().size()); assertEquals(threeTierWebAppOvfString, applicationResponse.getDeployments().get(0).getOvf()); assertEquals(1, applicationResponse.getDeployments().get(0).getSchema()); assertEquals(Dictionary.APPLICATION_STATUS_SUBMITTED, applicationResponse.getDeployments().get(0).getStatus()); Pattern p = Pattern.compile("\\d\\d/\\d\\d/\\d\\d\\d\\d:\\d\\d:\\d\\d:\\d\\d \\+\\d\\d\\d\\d"); Matcher m = p.matcher(applicationResponse.getDeployments().get(0).getStartDate()); assertTrue(m.matches()); verify(applicationDAO, times(2)).getByName("threeTierWebApp"); verify(applicationDAO, times(1)).update(any(Application.class)); ArgumentCaptor<DeploymentEvent> argument = ArgumentCaptor.forClass(DeploymentEvent.class); verify(deploymentEventService).fireDeploymentEvent(argument.capture()); assertEquals(Dictionary.APPLICATION_STATUS_SUBMITTED, argument.getValue().getDeploymentStatus()); assertEquals(true, argument.getValue().isAutomaticNegotiation()); Thread.sleep(1000l); assertEquals(1, listener.getTextMessages().size()); assertEquals("APPLICATION.threeTierWebApp.DEPLOYMENT.0.SUBMITTED", listener.getTextMessages().get(0).getJMSDestination().toString()); assertEquals("threeTierWebApp", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(0).getText()).getApplicationId()); assertEquals("0", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(0).getText()).getDeploymentId()); assertEquals("SUBMITTED", ModelConverter.jsonToApplicationManagerMessage(listener.getTextMessages().get(0).getText()).getStatus()); receiver.close(); }
@POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) public Response postApplicationJSON(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload) { logger.info("POST request to path: /applications?negotiation=" + negotiation); logger.info(" PAYLOAD: " + payload); return createNewDeployment(payload, negotiation, schema, false); }
ApplicationRest extends AbstractRest { @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) public Response postApplicationJSON(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload) { logger.info("POST request to path: /applications?negotiation=" + negotiation); logger.info(" PAYLOAD: " + payload); return createNewDeployment(payload, negotiation, schema, false); } }
ApplicationRest extends AbstractRest { @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) public Response postApplicationJSON(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload) { logger.info("POST request to path: /applications?negotiation=" + negotiation); logger.info(" PAYLOAD: " + payload); return createNewDeployment(payload, negotiation, schema, false); }  }
ApplicationRest extends AbstractRest { @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) public Response postApplicationJSON(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload) { logger.info("POST request to path: /applications?negotiation=" + negotiation); logger.info(" PAYLOAD: " + payload); return createNewDeployment(payload, negotiation, schema, false); }  @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getApplications(); @GET @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getApplicationsJSON(); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postApplication(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) Response postApplicationJSON(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload); @GET @Path("{application_name}") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getApplication(@PathParam("application_name") String applicationName); @GET @Path("{application_name}") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getApplicationJSON(@PathParam("application_name") String applicationName); @DELETE @Path("{application_name}") Response deleteApplication(@PathParam("application_name") String applicationName); }
ApplicationRest extends AbstractRest { @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) public Response postApplicationJSON(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload) { logger.info("POST request to path: /applications?negotiation=" + negotiation); logger.info(" PAYLOAD: " + payload); return createNewDeployment(payload, negotiation, schema, false); }  @GET @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getApplications(); @GET @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getApplicationsJSON(); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) Response postApplication(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload); @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) Response postApplicationJSON(@QueryParam("negotiation") String negotiation, @QueryParam("schema") String schema, String payload); @GET @Path("{application_name}") @Produces(MediaType.APPLICATION_XML + ";qs=1") Response getApplication(@PathParam("application_name") String applicationName); @GET @Path("{application_name}") @Produces(MediaType.APPLICATION_JSON + ";qs=0.5") Response getApplicationJSON(@PathParam("application_name") String applicationName); @DELETE @Path("{application_name}") Response deleteApplication(@PathParam("application_name") String applicationName);  }