/** * 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"); }
/** * 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 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); }
/** * 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"); }
@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()); }
@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 testGetGreetings() throws Exception { // Create some test data Collection<Greeting> list = getEntityListStubData(); // Stub the GreetingService.findAll method return value when(greetingService.findAll()).thenReturn(list); // Perform the behavior being tested String uri = "/api/greetings"; MvcResult result = mvc.perform(MockMvcRequestBuilders.get(uri) .accept(MediaType.APPLICATION_JSON)).andReturn(); // Extract the response status and body String content = result.getResponse().getContentAsString(); int status = result.getResponse().getStatus(); // Verify the GreetingService.findAll method was invoked once verify(greetingService, times(1)).findAll(); // Perform standard JUnit assertions on the response Assert.assertEquals("failure - expected HTTP status 200", 200, status); Assert.assertTrue( "failure - expected HTTP response body to have a value", content.trim().length() > 0); }
@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()); }