Commit cb2809f0 authored by Matija Obreza's avatar Matija Obreza

Merge branch '468-accession-doi-validation' into 'master'

Resolve "Accession DOI validation"

Closes #468

See merge request genesys-pgr/genesys-server!457
parents e0ca9cf4 537d1f34
......@@ -78,6 +78,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
@QueryInit({ "geo.*", "coll.*", "pdci.*", "lists.*" })
private AccessionId accessionId;
@Pattern(regexp = "10\\.\\d+/.+")
@Column(name = "doi")
private String doi;
......
......@@ -20,6 +20,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List;
......@@ -191,6 +192,58 @@ public class AccessionUploaderTest extends AbstractServicesTest {
assertThat(a2.getDoi(), is(DOI_1));
}
/**
* Inserting new accession with an invalid DOI.
*/
@Test
public void testInsertWithInvalidDOI() {
final String withWhitespaceDOI = " 10.0155/AB1R6";
List<AccessionOpResponse> resp_1 = accessionUploader.upsertAccessions(institute, upsertAccessions(institute.getCode(), ACCENUMB_1, GENUS_1, withWhitespaceDOI));
assertNotNull(resp_1.get(0));
assertNotNull(resp_1.get(0).getError());
assertTrue(resp_1.get(0).getError().startsWith("Validation failed: Accession.doi"));
assertThat(accessionRepository.count(), is(0L));
Accession accession_1 = accessionRepository.findOne(institute, null, ACCENUMB_1, GENUS_1);
assertNull(accession_1);
final String noDotDOI = "10/0155/AB1R6";
List<AccessionOpResponse> resp_2 = accessionUploader.upsertAccessions(institute, upsertAccessions(institute.getCode(), ACCENUMB_1, GENUS_1, noDotDOI));
assertNotNull(resp_2.get(0));
assertNotNull(resp_2.get(0).getError());
assertTrue(resp_2.get(0).getError().startsWith("Validation failed: Accession.doi"));
assertThat(accessionRepository.count(), is(0L));
Accession accession_2 = accessionRepository.findOne(institute, null, ACCENUMB_1, GENUS_1);
assertNull(accession_2);
final String no10DotDOI = "2.18730/A";
List<AccessionOpResponse> resp_3 = accessionUploader.upsertAccessions(institute, upsertAccessions(institute.getCode(), ACCENUMB_1, GENUS_1, no10DotDOI));
assertNotNull(resp_3.get(0));
assertNotNull(resp_3.get(0).getError());
assertTrue(resp_3.get(0).getError().startsWith("Validation failed: Accession.doi"));
assertThat(accessionRepository.count(), is(0L));
Accession accession_3 = accessionRepository.findOne(institute, null, ACCENUMB_1, GENUS_1);
assertNull(accession_3);
final String noSlashDOI = "10.18730";
List<AccessionOpResponse> resp_4 = accessionUploader.upsertAccessions(institute, upsertAccessions(institute.getCode(), ACCENUMB_1, GENUS_1, noSlashDOI));
assertNotNull(resp_4.get(0));
assertNotNull(resp_4.get(0).getError());
assertTrue(resp_4.get(0).getError().startsWith("Validation failed: Accession.doi"));
assertThat(accessionRepository.count(), is(0L));
Accession accession_4 = accessionRepository.findOne(institute, null, ACCENUMB_1, GENUS_1);
assertNull(accession_4);
final String noIdDOI = "10.18730/";
List<AccessionOpResponse> resp_5 = accessionUploader.upsertAccessions(institute, upsertAccessions(institute.getCode(), ACCENUMB_1, GENUS_1, noIdDOI));
assertNotNull(resp_5.get(0));
assertNotNull(resp_5.get(0).getError());
assertTrue(resp_5.get(0).getError().startsWith("Validation failed: Accession.doi"));
assertThat(accessionRepository.count(), is(0L));
Accession accession_5 = accessionRepository.findOne(institute, null, ACCENUMB_1, GENUS_1);
assertNull(accession_5);
}
/**
* Assigning a DOI to existing accession must work.
*/
......
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