Commit bc01759c authored by Maxym Borodenko's avatar Maxym Borodenko

Test TaxonomyFilter with empty collection for JPA

parent 79647965
......@@ -29,6 +29,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import com.google.common.collect.Sets;
import org.genesys.test.base.AbstractApiTest;
import org.genesys2.server.api.v1.AccessionController;
import org.genesys2.server.api.v1.AccessionUploadController;
......@@ -42,6 +43,7 @@ import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.persistence.Taxonomy2Repository;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
......@@ -158,6 +160,57 @@ public class AccessionControllerTest extends AbstractApiTest {
assertThat(accessionRepository.count(), is(1L));
}
@Test
public void taxonomyFilterTest() throws Exception {
ObjectNode accessionJson = setUpAccession();
final String s = "[" + verboseMapper.writeValueAsString(accessionJson) + "]";
/*@formatter:off*/
mockMvc
.perform(post(AccessionUploadController.CONTROLLER_URL + "/" + institute.getCode() + "/upsert")
.contentType(MediaType.APPLICATION_JSON)
.content(s))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$[0].instCode", is(institute.getCode())))
.andExpect(jsonPath("$[0].acceNumb", is(accessionJson.get("accessionNumber").textValue())))
.andExpect(jsonPath("$[0].genus", is(accessionJson.get("taxonomy").get("genus").textValue())))
.andExpect(jsonPath("$[0].error", nullValue()))
.andExpect(jsonPath("$[0].result.action", equalTo("INSERT")));
/*@formatter:on*/
assertThat(accessionRepository.count(), is(1L));
AccessionFilter filter = new AccessionFilter();
filter.taxonomy = filter.taxa();
filter.taxonomy.genusSpecies = Sets.newHashSet("Manihot sp.");
/*@formatter:off*/
mockMvc
.perform(post(AccessionUploadController.CONTROLLER_URL + "/list")
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(filter)))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.totalElements", is(1)))
.andExpect(jsonPath("$.content[0].taxonomy.taxonName", is("Manihot sp.")));
/*@formatter:on*/
filter.taxonomy.genusSpecies = Sets.newHashSet("Must not match");
/*@formatter:off*/
mockMvc
.perform(post(AccessionUploadController.CONTROLLER_URL + "/list")
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(filter)))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.totalElements", is(0)));
/*@formatter:on*/
}
@Test
public void getAccessionsTest() throws Exception {
......
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