Commit 1d0ffd4c authored by Matija Obreza's avatar Matija Obreza

API: /crops/list as CSV

parent 36f027c1
......@@ -33,6 +33,7 @@ import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.CropService.CropDetails;
import org.genesys2.spring.CSVMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
......@@ -126,7 +127,7 @@ public class CropsController extends ApiBaseController {
*
* @return list of crops
*/
@RequestMapping(value = "/list", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/list", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, CSVMessageConverter.TEXT_CSV_VALUE })
public List<Crop> listCrops() {
LOG.info("Listing crops");
return cropService.list(LocaleContextHolder.getLocale());
......
......@@ -37,13 +37,12 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class CropsControllerTest extends AbstractCropsControllerTest {
public static final MediaType TEXT_CSV = new MediaType("text", "csv");
@Test
public void listCropsTest() throws Exception {
LOG.info("Start test-method listCropsTest");
mockMvc.perform(get("/api/v1/crops")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", hasSize(1)))
......@@ -54,15 +53,37 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
.andExpect(jsonPath("$[0].name", is("Maize")))
.andExpect(jsonPath("$[0].description", is("Crop description in EN")))
.andDo(document("crop-list"));
}
LOG.info("Test listCropsTest passed");
@Test
public void listCropTestJson() throws Exception {
/*@formatter:off*/
mockMvc.perform(get("/api/v1/crops/list")
.accept(MediaType.APPLICATION_JSON))
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
;
/*@formatter:on*/
}
@Test
public void listCropTestCSV() throws Exception {
/*@formatter:off*/
mockMvc.perform(get("/api/v1/crops/list")
.accept(TEXT_CSV))
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(TEXT_CSV))
;
/*@formatter:on*/
}
@Test
@SuppressWarnings("unused")
public void createCropTest() throws Exception {
LOG.info("Start test-method createCropTest");
/*@formatter:off*/
mockMvc.perform(post(CropsController.CONTROLLER_URL + "/save")
.contentType(MediaType.APPLICATION_JSON_VALUE)
......@@ -106,13 +127,10 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
)));
/*@formatter:on*/
LOG.info("Test createCropTest passed");
}
@Test
public void getCropTest() throws Exception {
LOG.info("Start test-method getCropTest");
/*@formatter:off*/
mockMvc.perform(get("/api/v1/crops/{shortName}", crop.getShortName())
.contentType(MediaType.APPLICATION_JSON_VALUE))
......@@ -145,7 +163,6 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
fieldWithPath("lastModifiedDate").ignored()
)));
/*@formatter:on*/
LOG.info("Test getCropTest passed");
}
@Test
......@@ -171,7 +188,6 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
@Test
public void getCropsDetailsTest() throws Exception {
LOG.info("Start test-method getCropsDetailsTest");
setupAccession();
setupBlurb();
......@@ -187,13 +203,10 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
.andExpect(jsonPath("$.accessionCount", is(1)));
/*@formatter:on*/
LOG.info("Test getCropTest passed");
}
@Test
public void getCropRulesTest() throws Exception {
LOG.info("Start test-method getCropRulesTest");
/*@formatter:off*/
mockMvc.perform(get("/api/v1/crops/{shortName}/rules", crop.getShortName())
.contentType(MediaType.APPLICATION_JSON_VALUE))
......@@ -210,13 +223,10 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
)));
/*@formatter:on*/
LOG.info("Test getCropRulesTest passed");
}
@Test
public void updateCropRulesTest() throws Exception {
LOG.info("Start test-method updateCropRulesTest");
ObjectMapper objectMapper = new ObjectMapper();
List<CropRule> cropRules = new ArrayList<>();
CropRule cropRule=new CropRule();
......@@ -250,13 +260,10 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
)));
/*@formatter:on*/
LOG.info("Test updateCropRulesTest passed");
}
@Test
public void getCropTaxaTest() throws Exception {
LOG.info("Start test-method getCropTaxaTest");
/*@formatter:off*/
mockMvc.perform(get("/api/v1/crops/{shortName}/taxa", crop.getShortName())
.contentType(MediaType.APPLICATION_JSON_VALUE))
......@@ -273,15 +280,12 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
.andExpect(jsonPath("$.size", is(50)));
/*@formatter:on*/
LOG.info("Test getCropTaxaTest passed");
}
// FIXME Authentication
@Ignore
@Test
public void rebuildTest() throws Exception {
LOG.info("Start test-method rebuildTest");
String JSON_OK = "{\"result\":true}";
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(JSON_OK);
......@@ -294,18 +298,14 @@ public class CropsControllerTest extends AbstractCropsControllerTest {
.andExpect(content().string(objectMapper.writeValueAsString(jsonNode)));
/*@formatter:on*/
LOG.info("Test rebuildTest passed");
}
@Test
public void rebuildCropTest() throws Exception {
LOG.info("Start test-method rebuildCropTest");
/*@formatter:off*/
mockMvc.perform(post("/api/v1/crops/{shortName}/rebuild", crop.getShortName())
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk());
/*@formatter:on*/
LOG.info("Test rebuildCropTest passed");
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment