/** * 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 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); }
greeting = greetingService.findOne(id); if (greeting == null) { logger.info("< sendGreeting id:{}", id);
greeting = greetingService.findOne(id); if (greeting == null) { logger.info("< sendGreeting id:{}", id);
@Test public void testFindOneNotFound() { Long id = Long.MAX_VALUE; Greeting entity = service.findOne(id); Assert.assertNull("failure - expected null", entity); }
@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 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()); }
@Test public void testGetGreetingNotFound() throws Exception { // Create some test data Long id = Long.MAX_VALUE; // Stub the GreetingService.findOne method return value when(greetingService.findOne(id)).thenReturn(null); // Perform the behavior being tested String uri = "/api/greetings/{id}"; MvcResult result = mvc.perform(MockMvcRequestBuilders.get(uri, id) .accept(MediaType.APPLICATION_JSON)).andReturn(); // Extract the response status and body String content = result.getResponse().getContentAsString(); int status = result.getResponse().getStatus(); // Verify the GreetingService.findOne method was invoked once verify(greetingService, times(1)).findOne(id); // Perform standard JUnit assertions on the test results Assert.assertEquals("failure - expected HTTP status 404", 404, status); Assert.assertTrue("failure - expected HTTP response body to be empty", content.trim().length() == 0); }
@Test public void testGetGreeting() throws Exception { // Create some test data Long id = new Long(1); Greeting entity = getEntityStubData(); // Stub the GreetingService.findOne method return value when(greetingService.findOne(id)).thenReturn(entity); // Perform the behavior being tested String uri = "/api/greetings/{id}"; MvcResult result = mvc.perform(MockMvcRequestBuilders.get(uri, id) .accept(MediaType.APPLICATION_JSON)).andReturn(); // Extract the response status and body String content = result.getResponse().getContentAsString(); int status = result.getResponse().getStatus(); // Verify the GreetingService.findOne method was invoked once verify(greetingService, times(1)).findOne(id); // Perform standard JUnit assertions on the test results 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 testDeleteGreeting() throws Exception { String uri = "/api/greetings/{id}"; Long id = new Long(1); MvcResult result = mvc.perform(MockMvcRequestBuilders.delete(uri, id) .contentType(MediaType.APPLICATION_JSON)).andReturn(); String content = result.getResponse().getContentAsString(); int status = result.getResponse().getStatus(); Assert.assertEquals("failure - expected HTTP status 204", 204, status); Assert.assertTrue("failure - expected HTTP response body to be empty", content.trim().length() == 0); Greeting deletedGreeting = greetingService.findOne(id); Assert.assertNull("failure - expected greeting to be null", deletedGreeting); }
@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 testUpdateGreeting() throws Exception { String uri = "/api/greetings/{id}"; Long id = new Long(1); Greeting greeting = greetingService.findOne(id); String updatedText = greeting.getText() + " test"; greeting.setText(updatedText); String inputJson = super.mapToJson(greeting); MvcResult result = mvc .perform(MockMvcRequestBuilders.put(uri, id) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON).content(inputJson)) .andReturn(); String content = result.getResponse().getContentAsString(); int status = result.getResponse().getStatus(); Assert.assertEquals("failure - expected HTTP status 200", 200, status); Assert.assertTrue( "failure - expected HTTP response body to have a value", content.trim().length() > 0); Greeting updatedGreeting = super.mapFromJson(content, Greeting.class); Assert.assertNotNull("failure - expected greeting not null", updatedGreeting); Assert.assertEquals("failure - expected greeting.id unchanged", greeting.getId(), updatedGreeting.getId()); Assert.assertEquals("failure - expected updated greeting text match", updatedText, updatedGreeting.getText()); }