/** * Web service endpoint to create a single Greeting entity. The HTTP request * body is expected to contain a Greeting object in JSON format. The * Greeting is persisted in the data repository. * * If created successfully, the persisted Greeting is returned as JSON with * HTTP status 201. * * If not created successfully, the service returns an empty response body * with HTTP status 500. * * @param greeting The Greeting object to be created. * @return A ResponseEntity containing a single Greeting object, if created * successfully, and a HTTP status code as described in the method * comment. */ @RequestMapping( value = "/api/greetings", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Greeting> createGreeting( @RequestBody Greeting greeting) { logger.info("> createGreeting"); Greeting savedGreeting = greetingService.create(greeting); logger.info("< createGreeting"); return new ResponseEntity<Greeting>(savedGreeting, HttpStatus.CREATED); }
@Test public void testDelete() { Long id = new Long(1); Greeting entity = service.findOne(id); Assert.assertNotNull("failure - expected not null", entity); service.delete(id); Collection<Greeting> list = service.findAll(); Assert.assertEquals("failure - expected size", 1, list.size()); Greeting deletedEntity = service.findOne(id); Assert.assertNull("failure - expected null", deletedEntity); }
logger.info("> updateGreeting id:{}", greeting.getId()); Greeting updatedGreeting = greetingService.update(greeting); if (updatedGreeting == null) { return new ResponseEntity<Greeting>(
/** * Web service endpoint to fetch a single Greeting entity by primary key * identifier. * * If found, the Greeting is returned as JSON with HTTP status 200. * * If not found, the service returns an empty response body with HTTP status * 404. * * @param id A Long URL path variable containing the Greeting primary key * identifier. * @return A ResponseEntity containing a single Greeting object, if found, * and a HTTP status code as described in the method comment. */ @RequestMapping( value = "/api/greetings/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Greeting> getGreeting(@PathVariable("id") Long id) { logger.info("> getGreeting id:{}", id); Greeting greeting = greetingService.findOne(id); if (greeting == null) { return new ResponseEntity<Greeting>(HttpStatus.NOT_FOUND); } logger.info("< getGreeting id:{}", id); return new ResponseEntity<Greeting>(greeting, HttpStatus.OK); }
/** * Web service endpoint to fetch all Greeting entities. The service returns * the collection of Greeting entities as JSON. * * @return A ResponseEntity containing a Collection of Greeting objects. */ @RequestMapping( value = "/api/greetings", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Collection<Greeting>> getGreetings() { logger.info("> getGreetings"); Collection<Greeting> greetings = greetingService.findAll(); logger.info("< getGreetings"); return new ResponseEntity<Collection<Greeting>>(greetings, HttpStatus.OK); }
@Test public void testCreate() { Greeting entity = new Greeting(); entity.setText("test"); Greeting createdEntity = service.create(entity); Assert.assertNotNull("failure - expected not null", createdEntity); Assert.assertNotNull("failure - expected id attribute not null", createdEntity.getId()); Assert.assertEquals("failure - expected text attribute match", "test", createdEntity.getText()); Collection<Greeting> list = service.findAll(); Assert.assertEquals("failure - expected size", 3, list.size()); }
@Test public void testUpdate() { Long id = new Long(1); Greeting entity = service.findOne(id); Assert.assertNotNull("failure - expected not null", entity); String updatedText = entity.getText() + " test"; entity.setText(updatedText); Greeting updatedEntity = service.update(entity); Assert.assertNotNull("failure - expected not null", updatedEntity); Assert.assertEquals("failure - expected id attribute match", id, updatedEntity.getId()); Assert.assertEquals("failure - expected text attribute match", updatedText, updatedEntity.getText()); }
/** * Web service endpoint to delete a single Greeting entity. The HTTP request * body is empty. The primary key identifier of the Greeting to be deleted * is supplied in the URL as a path variable. * * If deleted successfully, the service returns an empty response body with * HTTP status 204. * * If not deleted successfully, the service returns an empty response body * with HTTP status 500. * * @param id A Long URL path variable containing the Greeting primary key * identifier. * @return A ResponseEntity with an empty response body and a HTTP status * code as described in the method comment. */ @RequestMapping( value = "/api/greetings/{id}", method = RequestMethod.DELETE) public ResponseEntity<Greeting> deleteGreeting( @PathVariable("id") Long id) { logger.info("> deleteGreeting id:{}", id); greetingService.delete(id); logger.info("< deleteGreeting id:{}", id); return new ResponseEntity<Greeting>(HttpStatus.NO_CONTENT); }
@Before public void setUp() { service.evictCache(); }
/** * Web service endpoint to fetch a single Greeting entity by primary key * identifier. * * If found, the Greeting is returned as JSON with HTTP status 200. * * If not found, the service returns an empty response body with HTTP status * 404. * * @param id A Long URL path variable containing the Greeting primary key * identifier. * @return A ResponseEntity containing a single Greeting object, if found, * and a HTTP status code as described in the method comment. */ @RequestMapping( value = "/api/greetings/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Greeting> getGreeting(@PathVariable("id") Long id) { logger.info("> getGreeting id:{}", id); Greeting greeting = greetingService.findOne(id); if (greeting == null) { return new ResponseEntity<Greeting>(HttpStatus.NOT_FOUND); } logger.info("< getGreeting id:{}", id); return new ResponseEntity<Greeting>(greeting, HttpStatus.OK); }
/** * Web service endpoint to fetch all Greeting entities. The service returns * the collection of Greeting entities as JSON. * * @return A ResponseEntity containing a Collection of Greeting objects. */ @RequestMapping( value = "/api/greetings", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Collection<Greeting>> getGreetings() { logger.info("> getGreetings"); Collection<Greeting> greetings = greetingService.findAll(); logger.info("< getGreetings"); return new ResponseEntity<Collection<Greeting>>(greetings, HttpStatus.OK); }
/** * Web service endpoint to delete a single Greeting entity. The HTTP request * body is empty. The primary key identifier of the Greeting to be deleted * is supplied in the URL as a path variable. * * If deleted successfully, the service returns an empty response body with * HTTP status 204. * * If not deleted successfully, the service returns an empty response body * with HTTP status 500. * * @param id A Long URL path variable containing the Greeting primary key * identifier. * @return A ResponseEntity with an empty response body and a HTTP status * code as described in the method comment. */ @RequestMapping( value = "/api/greetings/{id}", method = RequestMethod.DELETE) public ResponseEntity<Greeting> deleteGreeting( @PathVariable("id") Long id) { logger.info("> deleteGreeting id:{}", id); greetingService.delete(id); logger.info("< deleteGreeting id:{}", id); return new ResponseEntity<Greeting>(HttpStatus.NO_CONTENT); }
@Before public void setUp() { super.setUp(); greetingService.evictCache(); }
greeting = greetingService.findOne(id); if (greeting == null) { logger.info("< sendGreeting id:{}", id);
/** * Use a cron expression to execute logic on a schedule. * * Expression: second minute hour day-of-month month weekday * * @see http ://docs.spring.io/spring/docs/current/javadoc-api/org/ * springframework /scheduling/support/CronSequenceGenerator.html */ @Scheduled( cron = "${batch.greeting.cron}") public void cronJob() { logger.info("> cronJob"); // Add scheduled logic here Collection<Greeting> greetings = greetingService.findAll(); logger.info("There are {} greetings in the data store.", greetings.size()); logger.info("< cronJob"); }
logger.info("> updateGreeting id:{}", greeting.getId()); Greeting updatedGreeting = greetingService.update(greeting); if (updatedGreeting == null) { return new ResponseEntity<Greeting>(
/** * Web service endpoint to create a single Greeting entity. The HTTP request * body is expected to contain a Greeting object in JSON format. The * Greeting is persisted in the data repository. * * If created successfully, the persisted Greeting is returned as JSON with * HTTP status 201. * * If not created successfully, the service returns an empty response body * with HTTP status 500. * * @param greeting The Greeting object to be created. * @return A ResponseEntity containing a single Greeting object, if created * successfully, and a HTTP status code as described in the method * comment. */ @RequestMapping( value = "/api/greetings", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Greeting> createGreeting( @RequestBody Greeting greeting) { logger.info("> createGreeting"); Greeting savedGreeting = greetingService.create(greeting); logger.info("< createGreeting"); return new ResponseEntity<Greeting>(savedGreeting, HttpStatus.CREATED); }
@Test public void testDeleteGreeting() throws Exception { // Create some test data Long id = new Long(1); // Perform the behavior being tested String uri = "/api/greetings/{id}"; MvcResult result = mvc.perform(MockMvcRequestBuilders.delete(uri, id)) .andReturn(); // Extract the response status and body String content = result.getResponse().getContentAsString(); int status = result.getResponse().getStatus(); // Verify the GreetingService.delete method was invoked once verify(greetingService, times(1)).delete(id); // Perform standard JUnit assertions on the test results Assert.assertEquals("failure - expected HTTP status 204", 204, status); Assert.assertTrue("failure - expected HTTP response body to be empty", content.trim().length() == 0); }
greeting = greetingService.findOne(id); if (greeting == null) { logger.info("< sendGreeting id:{}", id);
/** * Use a cron expression to execute logic on a schedule. * * Expression: second minute hour day-of-month month weekday * * @see http ://docs.spring.io/spring/docs/current/javadoc-api/org/ * springframework /scheduling/support/CronSequenceGenerator.html */ @Scheduled( cron = "${batch.greeting.cron}") public void cronJob() { logger.info("> cronJob"); // Add scheduled logic here Collection<Greeting> greetings = greetingService.findAll(); logger.info("There are {} greetings in the data store.", greetings.size()); logger.info("< cronJob"); }