@Async @Override public void sendAsync(Greeting greeting) { logger.info("> sendAsync"); try { send(greeting); } catch (Exception e) { logger.warn("Exception caught sending asynchronous mail.", e); } logger.info("< sendAsync"); }
/** * 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"); }
@Before public void setUp() { service.evictCache(); }
@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); }
@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()); }
@Test public void testFindOneNotFound() { Long id = Long.MAX_VALUE; Greeting entity = service.findOne(id); Assert.assertNull("failure - expected null", entity); }
@Test public void testUpdateNotFound() { Exception exception = null; Greeting entity = new Greeting(); entity.setId(Long.MAX_VALUE); entity.setText("test"); try { service.update(entity); } catch (NoResultException e) { exception = e; } Assert.assertNotNull("failure - expected exception", exception); Assert.assertTrue("failure - expected NoResultException", exception instanceof NoResultException); }
@Test public void testCreateWithId() { Exception exception = null; Greeting entity = new Greeting(); entity.setId(Long.MAX_VALUE); entity.setText("test"); try { service.create(entity); } catch (EntityExistsException e) { exception = e; } Assert.assertNotNull("failure - expected exception", exception); Assert.assertTrue("failure - expected EntityExistsException", exception instanceof EntityExistsException); }
/** * 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 testFindOne() { Long id = new Long(1); Greeting entity = service.findOne(id); Assert.assertNotNull("failure - expected not null", entity); Assert.assertEquals("failure - expected id attribute match", id, entity.getId()); }
@Async @Override public void sendAsync(Greeting greeting) { logger.info("> sendAsync"); try { send(greeting); } catch (Exception e) { logger.warn("Exception caught sending asynchronous mail.", e); } logger.info("< sendAsync"); }
@Before public void setUp() { super.setUp(); greetingService.evictCache(); }
/** * 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); }
@Async @Override public Future<Boolean> sendAsyncWithResult(Greeting greeting) { logger.info("> sendAsyncWithResult"); AsyncResponse<Boolean> response = new AsyncResponse<Boolean>(); try { Boolean success = send(greeting); response.complete(success); } catch (Exception e) { logger.warn("Exception caught sending asynchronous mail.", e); response.completeExceptionally(e); } logger.info("< sendAsyncWithResult"); return response; }
/** * 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"); }
@Async @Override public Future<Boolean> sendAsyncWithResult(Greeting greeting) { logger.info("> sendAsyncWithResult"); AsyncResponse<Boolean> response = new AsyncResponse<Boolean>(); try { Boolean success = send(greeting); response.complete(success); } catch (Exception e) { logger.warn("Exception caught sending asynchronous mail.", e); response.completeExceptionally(e); } logger.info("< sendAsyncWithResult"); return response; }
@Override public Health health() { // Assess the application's Greeting health. If the application's // Greeting components have data to service user requests, the Greeting // component is considered 'healthy', otherwise it is not. Collection<Greeting> greetings = greetingService.findAll(); if (greetings == null || greetings.size() == 0) { return Health.down().withDetail("count", 0).build(); } return Health.up().withDetail("count", greetings.size()).build(); }
@Override public Health health() { // Assess the application's Greeting health. If the application's // Greeting components have data to service user requests, the Greeting // component is considered 'healthy', otherwise it is not. Collection<Greeting> greetings = greetingService.findAll(); if (greetings == null || greetings.size() == 0) { return Health.down().withDetail("count", 0).build(); } return Health.up().withDetail("count", greetings.size()).build(); }
@Test public void testFindAll() { Collection<Greeting> list = service.findAll(); Assert.assertNotNull("failure - expected not null", list); Assert.assertEquals("failure - expected list size", 2, list.size()); }