Commit a0e2126a authored by Matija Obreza's avatar Matija Obreza

Merge branch '464-api-v1-delete-accession' into 'master'

Resolve "API v1 delete accession"

Closes #464

See merge request genesys-pgr/genesys-server!447
parents e316fcd1 cbc4832f
......@@ -231,7 +231,7 @@ public class AccessionController extends ApiBaseController {
} catch (DataAccessException | TransactionException | PersistenceException e) {
List<AccessionOpResponse> res = upsert1By1(institute, updates);
LOG.info("Processed {} accessions for {} 1by1 after {} tries in {}ms because of {}", updates.size(), instCode, tryCount + 1, stopWatch.getTime(), e.getMessage());
LOG.info("Processed {} accessions for {} 1by1 after {} tries in {}ms because of {}", updates.size(), instCode, tryCount + 1, stopWatch.getTime(), e.getMessage());
return res;
} catch (PleaseRetryException e) {
......@@ -309,14 +309,15 @@ public class AccessionController extends ApiBaseController {
throw new NotFoundElement();
}
final ArrayNode updates = convertToArrayNode(batch);
try {
List<AccessionOpResponse> response = null;
try {
response = uploader.deleteAccessions(institute, batch);
response = uploader.deleteAccessions(institute, updates);
LOG.info("Deleted {} accessions from {}", response.size(), instCode);
} catch (DataAccessException | TransactionException | PersistenceException e) {
LOG.info("Retrying delete one by one due to {}", e.getMessage());
response = deleteAccessions1by1(institute, batch);
response = deleteAccessions1by1(institute, updates);
}
return response;
......@@ -325,26 +326,24 @@ public class AccessionController extends ApiBaseController {
}
}
private List<AccessionOpResponse> deleteAccessions1by1(FaoInstitute institute, List<AccessionHeaderJson> batch) {
private List<AccessionOpResponse> deleteAccessions1by1(FaoInstitute institute, ArrayNode updates) {
LOG.info("Attempting delete 1 by 1");
final List<AccessionHeaderJson> batchOfOne = new ArrayList<AccessionHeaderJson>();
ArrayNode single = new ObjectMapper().createArrayNode();
List<AccessionOpResponse> response = new ArrayList<AccessionOpResponse>();
for (AccessionHeaderJson acceJ : batch) {
for (JsonNode update : updates) {
try {
batchOfOne.clear();
batchOfOne.add(acceJ);
AccessionOpResponse accessionResponse = uploader.deleteAccessions(institute, batchOfOne).get(0);
single.removeAll();
single.add(update);
AccessionOpResponse accessionResponse = uploader.deleteAccessions(institute, single).get(0);
response.add(accessionResponse);
} catch (Throwable e) {
if (LOG.isInfoEnabled()) {
LOG.info("Error deleting {}: {}", acceJ.instCode, e.getMessage());
LOG.info("Error deleting {}: {}", update.get("instituteCode").asText(), e.getMessage());
}
AccessionOpResponse accessionResponse = new AccessionOpResponse(acceJ.instCode, acceJ.acceNumb, acceJ.genus);
AccessionOpResponse accessionResponse = new AccessionOpResponse(update.get("instituteCode").asText(), update.get("accessionNumber").asText(), update.get("taxonomy").get("genus").asText());
accessionResponse.setError(getDetailedErrorMessage(e));
response.add(accessionResponse);
}
......@@ -414,8 +413,19 @@ public class AccessionController extends ApiBaseController {
public Integer maxRecords;
public String otherOptions;
}
private ArrayNode convertToArrayNode(List<AccessionHeaderJson> updates) {
final ArrayNode arrayNode = mapper.createArrayNode();
for (AccessionHeaderJson accnJ: updates) {
ObjectNode accession = arrayNode.addObject();
accession.put("instituteCode", accnJ.getHoldingInstitute());
accession.put("accessionNumber", accnJ.getAccessionNumber());
accession.put("doi", accnJ.getDoi());
ObjectNode taxonNode = accession.putObject("taxonomy");
taxonNode.put("genus", accnJ.getGenus());
}
return arrayNode;
}
private void upgradeToV2(ArrayNode updates) {
for (JsonNode update : updates) {
......
......@@ -26,7 +26,6 @@ import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.PleaseRetryException;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -115,7 +114,7 @@ public class AccessionUploadController {
} catch (DataAccessException | TransactionException | PersistenceException e) {
List<AccessionOpResponse> res = upsert1By1(institute, updates);
LOG.info("Processed {} accessions for {} 1by1 after {} tries in {}ms because of {}", updates.size(), instCode, tryCount + 1, stopWatch.getTime(), e.getMessage());
LOG.info("Processed {} accessions for {} 1by1 after {} tries in {}ms because of {}", updates.size(), instCode, tryCount + 1, stopWatch.getTime(), e.getMessage());
return res;
} catch (PleaseRetryException e) {
......@@ -180,7 +179,7 @@ public class AccessionUploadController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{instCode}/delete", method = { RequestMethod.POST }, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = {
MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<AccessionOpResponse> deleteAccessions(@PathVariable("instCode") String instCode, @RequestBody List<AccessionHeaderJson> batch) throws RESTApiException {
public @ResponseBody List<AccessionOpResponse> deleteAccessions(@PathVariable("instCode") String instCode, @RequestBody ArrayNode batch) throws RESTApiException {
// User's permission to WRITE to this WIEWS institute are checked in
// BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode);
......@@ -211,26 +210,24 @@ public class AccessionUploadController {
* @param batch the batch
* @return the list
*/
private List<AccessionOpResponse> deleteAccessions1by1(FaoInstitute institute, List<AccessionHeaderJson> batch) {
private List<AccessionOpResponse> deleteAccessions1by1(FaoInstitute institute, ArrayNode batch) {
LOG.info("Attempting delete 1 by 1");
final List<AccessionHeaderJson> batchOfOne = new ArrayList<AccessionHeaderJson>();
List<AccessionOpResponse> response = new ArrayList<AccessionOpResponse>();
for (AccessionHeaderJson acceJ : batch) {
final ArrayNode single = new ObjectMapper().createArrayNode();
final List<AccessionOpResponse> response = new ArrayList<AccessionOpResponse>();
for (JsonNode accn : batch) {
try {
batchOfOne.clear();
batchOfOne.add(acceJ);
AccessionOpResponse accessionResponse = uploader.deleteAccessions(institute, batchOfOne).get(0);
single.removeAll();
single.add(accn);
AccessionOpResponse accessionResponse = uploader.deleteAccessions(institute, single).get(0);
response.add(accessionResponse);
} catch (Throwable e) {
if (LOG.isInfoEnabled()) {
LOG.info("Error deleting {}: {}", acceJ.instCode, e.getMessage());
LOG.info("Error deleting {}: {}", accn.get("instituteCode"), e.getMessage());
}
AccessionOpResponse accessionResponse = new AccessionOpResponse(acceJ.instCode, acceJ.acceNumb, acceJ.genus);
AccessionOpResponse accessionResponse = new AccessionOpResponse(accn.get("instituteCode").asText(), accn.get("accessionNumber").asText(), accn.get("taxonomy").get("genus").asText());
accessionResponse.setError(getDetailedErrorMessage(e));
response.add(accessionResponse);
}
......
......@@ -31,6 +31,7 @@ import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
......@@ -172,7 +173,7 @@ public class AccessionUploader implements InitializingBean {
}
}
LOG.debug("Processsed incoming JSON for {} accessions in {}ms", updates.size(), stopWatch.getTime());
LOG.debug("Processed incoming JSON for {} accessions in {}ms", updates.size(), stopWatch.getTime());
List<Accession> existingAccessions = accessionRepository.find(! institute.hasUniqueAcceNumbs(), accessions);
LOG.debug("Have {} accessions for update and {} exist in {}ms", accessions.size(), existingAccessions.size(), stopWatch.getTime());
......@@ -674,40 +675,63 @@ public class AccessionUploader implements InitializingBean {
@Transactional(timeout = 250, isolation = Isolation.READ_UNCOMMITTED, rollbackFor = Throwable.class)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE')")
public List<AccessionOpResponse> deleteAccessions(FaoInstitute institute, List<AccessionHeaderJson> identifiers) {
// Security check
for (int i = 0; i < identifiers.size(); i++) {
AccessionHeaderJson accession = identifiers.get(i);
if (!institute.getCode().equals(accession.instCode)) {
throw new InvalidApiUsageException("Accession does not belong to institute " + institute.getCode());
}
}
public List<AccessionOpResponse> deleteAccessions(FaoInstitute institute, ArrayNode identifiers) {
assert (identifiers.isArray());
StopWatch stopWatch = StopWatch.createStarted();
ObjectReader reader = objectMapper.readerFor(Accession.class);
final List<Accession> toBeDeleted = new ArrayList<>(identifiers.size());
final List<AccessionOpResponse> responses = new ArrayList<>(identifiers.size());
// Require matching genus for deletion
List<Accession> existingAccessions = accessionRepository.find(true, identifiers);
List<Accession> toRemove = new ArrayList<>(identifiers.size());
List<AccessionHistoric> deleted = new ArrayList<>();
final List<Accession> toRemove = new ArrayList<>(identifiers.size());
final List<AccessionHistoric> deleted = new ArrayList<>();
for (JsonNode accn : identifiers) {
LOG.trace("Received: {}", accn);
try {
Accession accession = reader.readValue(accn);
if (accession.getInstituteCode() == null || (accession.getDoi() == null && accession.getAccessionNumber() == null)) {
throw new InvalidApiUsageException("instituteCode, accessionNumber OR doi missing in " + accn);
}
// Security check
if (!accession.getInstituteCode().equals(institute.getCode())) {
throw new InvalidApiUsageException("Accession does not belong to institute " + institute.getCode());
}
toBeDeleted.add(accession);
} catch (IOException e) {
LOG.error("Could not parse input: {}", e.getMessage(), e);
toBeDeleted.add(null); // need to match get(index) with responses and updates
AccessionOpResponse response = new AccessionOpResponse(accn.get("instituteCode").asText(), accn.get("accessionNumber").asText(), accn.get("taxonomy").get("genus").asText());
response.setResult(new UpsertResult(UpsertResult.Type.ERROR)).setError(e.getMessage());
responses.add(response);
}
}
LOG.debug("Processed incoming JSON for {} accessions in {}ms", identifiers.size(), stopWatch.getTime());
for (int i = 0; i < identifiers.size(); i++) {
final AccessionHeaderJson deletion = identifiers.get(i);
LOG.trace("Deleting: {}", deletion);
List<Accession> existingAccessions = accessionRepository.find(! institute.hasUniqueAcceNumbs(), toBeDeleted);
LOG.debug("Have {} accessions for update and {} exist in {}ms", toBeDeleted.size(), existingAccessions.size(), stopWatch.getTime());
for (Accession deletion: toBeDeleted) {
AccessionOpResponse response;
responses.add(response = new AccessionOpResponse(deletion.getHoldingInstitute(), deletion.getAccessionNumber(), deletion.getGenus()));
responses.add(response = new AccessionOpResponse(deletion.getHoldingInstitute(), deletion.getAccessionNumber(), deletion.getTaxonomy().getGenus()));
Accession accession = existingAccessions.stream()
.filter(existing -> (
existing.getInstituteCode().equals(deletion.getHoldingInstitute()) &&
existing.getAccessionNumber().equals(deletion.getAccessionNumber()) &&
existing.getTaxonomy().getGenus().equals(deletion.getGenus())
existing.getInstituteCode().equals(deletion.getHoldingInstitute()) &&
existing.getAccessionNumber().equals(deletion.getAccessionNumber()) &&
existing.getTaxonomy().getGenus().equals(deletion.getGenus())
)).findFirst().orElse(null);
if (accession == null) {
response.setResult(new UpsertResult(UpsertResult.Type.NOOP));
response.setError("Record not found");
} else {
try {
if (deletion.doi != null || accession.getDoi() != null) {
if (accession.getDoi() != null) {
throw new InvalidApiUsageException("Accessions with doi cannot be deleted");
}
......
......@@ -26,6 +26,8 @@ import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetCreator;
......@@ -221,4 +223,23 @@ public abstract class AbstractApiTest extends AbstractTest {
return descriptor;
}
protected ArrayNode upsertAccessions(final String instCode, final String acceNumb, final String genus, final String doi) {
ArrayNode updates = objectMapper.createArrayNode();
updates.add(upsertAccession(instCode, acceNumb, genus, doi));
return updates;
}
protected ObjectNode upsertAccession(final String instCode, final String accnNumber, final String genus, final String doi) {
ObjectNode accession = objectMapper.createObjectNode();
accession.put("instituteCode", instCode);
accession.put("accessionNumber", accnNumber);
if (doi != null) {
accession.put("doi", doi);
}
ObjectNode taxa = accession.putObject("taxonomy");
taxa.put("genus", genus);
return accession;
}
}
\ No newline at end of file
......@@ -241,13 +241,20 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
institute = instituteService.getInstitute(instCode);
}
ObjectMapper mapper = new ObjectMapper();
final ArrayNode arrayNode = mapper.createArrayNode();
ObjectNode rootNode = arrayNode.addObject();
rootNode.put("instituteCode", instCode);
rootNode.put("accessionNumber", acceNumb);
ObjectNode taxonNode = rootNode.putObject("taxonomy");
taxonNode.put("genus", genus);
AccessionHeaderJson ah = new AccessionHeaderJson();
ah.instCode = instCode;
ah.acceNumb = acceNumb;
ah.genus = genus;
List<AccessionHeaderJson> identifiers = Lists.newArrayList(ah);
accessionUploader.deleteAccessions(institute, identifiers);
accessionUploader.deleteAccessions(institute, arrayNode);
assert(accessionRepository.findOne(institute, null, acceNumb, genus) == null);
}
}
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,7 +16,9 @@
package org.genesys.test.server.api.v0;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
......@@ -29,16 +31,19 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.genesys.test.base.AbstractApiTest;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.api.v0.AccessionController;
import org.genesys2.server.model.genesys.*;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionHistoricRepository;
import org.genesys2.server.persistence.AccessionIdRepository;
import org.genesys2.server.persistence.AccessionRepository;
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.worker.AccessionUploader;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
......@@ -68,6 +73,12 @@ public class AccessionControllerTest extends AbstractApiTest {
private static final int STORAGE_10 = 10;
private static final int STORAGE_11 = 11;
private static final String ACCENUMB_1 = "A-0001";
private static final String ACCENUMB_2 = "A-0002";
private static final String GENUS_1 = "Hordeum";
private static final String GENUS_2 = "Musa";
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
......@@ -80,6 +91,8 @@ public class AccessionControllerTest extends AbstractApiTest {
@Autowired
private AccessionIdRepository accessionIdRepository;
@Autowired
private AccessionHistoricRepository accessionHistoricRepository;
@Autowired
private FaoInstituteRepository instituteRepository;
@Autowired
private InstituteService instituteService;
......@@ -87,6 +100,8 @@ public class AccessionControllerTest extends AbstractApiTest {
private Taxonomy2Repository taxonomyRepository;
@Autowired
private TaxonomyService taxonomyService;
@Autowired
private AccessionUploader accessionUploader;
MockMvc mockMvc;
......@@ -108,8 +123,10 @@ public class AccessionControllerTest extends AbstractApiTest {
@Override
@Transactional
public void cleanup() throws Exception {
accessionHistoricRepository.deleteAll();
accessionRepository.deleteAll();
accessionIdRepository.deleteAll();
taxonomyRepository.deleteAll();
instituteRepository.deleteAll();
super.cleanup();
......@@ -152,6 +169,40 @@ public class AccessionControllerTest extends AbstractApiTest {
assertThat(accessionRepository.count(), is(1L));
}
@Test
public void deleteAccessionsTest() throws Exception {
accessionUploader.upsertAccessions(institute, upsertAccessions(institute.getCode(), ACCENUMB_1, GENUS_1, null));
accessionUploader.upsertAccessions(institute, upsertAccessions(institute.getCode(), ACCENUMB_2, GENUS_2, null));
Accession storedAccession = accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_1);
assertThat(storedAccession.getAccessionNumber(), is(ACCENUMB_1));
Accession storedAccession2 = accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_2);
assertThat(storedAccession2.getAccessionNumber(), is(ACCENUMB_2));
AccessionHeaderJson aHS2 = new AccessionHeaderJson();
aHS2.instCode = storedAccession.getInstCode();
aHS2.acceNumb = storedAccession.getAccessionNumber();
aHS2.genus = storedAccession.getGenus();
final String s = "[" + verboseMapper.writeValueAsString(aHS2) + "]";
/*@formatter:off*/
mockMvc.perform(post(AccessionController.API_BASE + "/" + institute.getCode() + "/delete-named")
.contentType(MediaType.APPLICATION_JSON)
.content(s))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$[0].instCode", is(institute.getCode())))
.andExpect(jsonPath("$[0].error", nullValue()));
/*@formatter:on*/
assertThat(accessionRepository.count(), is(1L));
assertNotNull(accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_2));
}
@Test
public void getAccessionsTest() throws Exception {
......
......@@ -16,7 +16,9 @@
package org.genesys.test.server.api.v1;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNull;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
......@@ -37,6 +39,7 @@ import org.genesys2.server.model.genesys.*;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionGeoRepository;
import org.genesys2.server.persistence.AccessionHistoricRepository;
import org.genesys2.server.persistence.AccessionIdRepository;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.FaoInstituteRepository;
......@@ -44,6 +47,7 @@ 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.genesys2.server.service.worker.AccessionUploader;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
......@@ -73,6 +77,12 @@ public class AccessionControllerTest extends AbstractApiTest {
private static final int STORAGE_10 = 10;
private static final int STORAGE_11 = 11;
private static final String ACCENUMB_1 = "A-0001";
private static final String ACCENUMB_2 = "A-0002";
private static final String GENUS_1 = "Hordeum";
private static final String GENUS_2 = "Musa";
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
......@@ -85,6 +95,8 @@ public class AccessionControllerTest extends AbstractApiTest {
@Autowired
private AccessionIdRepository accessionIdRepository;
@Autowired
private AccessionHistoricRepository accessionHistoricRepository;
@Autowired
private AccessionGeoRepository accessionGeoRepository;
@Autowired
private FaoInstituteRepository instituteRepository;
......@@ -94,27 +106,21 @@ public class AccessionControllerTest extends AbstractApiTest {
private Taxonomy2Repository taxonomyRepository;
@Autowired
private TaxonomyService taxonomyService;
@Autowired
private AccessionUploader accessionUploader;
MockMvc mockMvc;
private FaoInstitute institute;
private AtomicInteger acceNumb = new AtomicInteger(1);
protected static final ObjectMapper objectMapper;
protected static final ObjectMapper verboseMapper = new ObjectMapper();
static {
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
}
@After
@Override
@Transactional
public void cleanup() throws Exception {
accessionHistoricRepository.deleteAll();
accessionRepository.deleteAll();
accessionIdRepository.deleteAll();
accessionGeoRepository.deleteAll();
......@@ -161,6 +167,38 @@ public class AccessionControllerTest extends AbstractApiTest {
assertThat(accessionRepository.findAll().get(0).isAegis(), is(true));
}
@Test
public void deleteAccessionsTest() throws Exception {
ArrayNode arrayNode = verboseMapper.createArrayNode();
arrayNode.add(upsertAccession(institute.getCode(), ACCENUMB_1, GENUS_1, null));
accessionUploader.upsertAccessions(institute, arrayNode);
accessionUploader.upsertAccessions(institute, upsertAccessions(institute.getCode(), ACCENUMB_2, GENUS_2, null));
Accession storedAccession = accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_1);
assertThat(storedAccession.getAccessionNumber(), is(ACCENUMB_1));
Accession storedAccession2 = accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_2);
assertThat(storedAccession2.getAccessionNumber(), is(ACCENUMB_2));
final String s = verboseMapper.writeValueAsString(arrayNode);
/*@formatter:off*/
mockMvc.perform(post(AccessionUploadController.CONTROLLER_URL + "/" + institute.getCode() + "/delete")
.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].error", nullValue()))
.andExpect(jsonPath("$[0].result.action", equalTo("DELETE")));
/*@formatter:on*/
assertThat(accessionRepository.count(), is(1L));
assertNotNull(accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_2));
}
@Test
public void taxonomyFilterTest() throws Exception {
ObjectNode accessionJson = setUpAccession();
......
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