-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from ebi-uniprot/TRM-29836_doi
TRM-29836: Create an UniProtKB result column to show publication DOI ids
- Loading branch information
Showing
2 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
core-parser/src/test/java/org/uniprot/core/parser/tsv/uniprot/EntryReferenceMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package org.uniprot.core.parser.tsv.uniprot; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.uniprot.core.parser.tsv.uniprot.EntryReferenceMap.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.uniprot.core.citation.Citation; | ||
import org.uniprot.core.citation.CitationDatabase; | ||
import org.uniprot.core.citation.impl.ElectronicArticleBuilder; | ||
import org.uniprot.core.impl.CrossReferenceBuilder; | ||
import org.uniprot.core.uniprotkb.UniProtKBReference; | ||
import org.uniprot.core.uniprotkb.impl.UniProtKBReferenceBuilder; | ||
|
||
class EntryReferenceMapTest { | ||
|
||
private static final String FIELD_SEPARATOR = "; "; | ||
|
||
@Test | ||
void testFields() { | ||
List<String> expected = Arrays.asList(LIT_PUBMED_ID, LIT_DOI_ID); | ||
assertEquals(expected, FIELDS); | ||
} | ||
|
||
@Test | ||
void testLitDoiId() { | ||
String doiId = "doiId1"; | ||
List<UniProtKBReference> references = getUniProtKBReferences(CitationDatabase.DOI, doiId); | ||
EntryReferenceMap mapper = new EntryReferenceMap(references); | ||
Map<String, String> result = mapper.attributeValues(); | ||
|
||
verifyFieldValue(result, LIT_DOI_ID, doiId); | ||
} | ||
|
||
@Test | ||
void testMultipleLitDoiId() { | ||
String doiId = "doiId1"; | ||
String doiId2 = "doiId2"; | ||
List<UniProtKBReference> references = | ||
getUniProtKBReferences(CitationDatabase.DOI, doiId, doiId2); | ||
EntryReferenceMap mapper = new EntryReferenceMap(references); | ||
Map<String, String> result = mapper.attributeValues(); | ||
|
||
verifyFieldValue(result, LIT_DOI_ID, doiId + FIELD_SEPARATOR + doiId2); | ||
} | ||
|
||
@Test | ||
void testLitPubmedId() { | ||
String pubmedId = "pubmedId1"; | ||
List<UniProtKBReference> references = | ||
getUniProtKBReferences(CitationDatabase.PUBMED, pubmedId); | ||
EntryReferenceMap mapper = new EntryReferenceMap(references); | ||
Map<String, String> result = mapper.attributeValues(); | ||
|
||
verifyFieldValue(result, LIT_PUBMED_ID, pubmedId); | ||
} | ||
|
||
@Test | ||
void testMultipleLitPubmedId() { | ||
String pubmedId = "pubmedId1"; | ||
String pubmedId2 = "pubmedId2"; | ||
List<UniProtKBReference> references = | ||
getUniProtKBReferences(CitationDatabase.PUBMED, pubmedId, pubmedId2); | ||
|
||
EntryReferenceMap mapper = new EntryReferenceMap(references); | ||
Map<String, String> result = mapper.attributeValues(); | ||
|
||
verifyFieldValue(result, LIT_PUBMED_ID, pubmedId + FIELD_SEPARATOR + pubmedId2); | ||
} | ||
|
||
@Test | ||
void testMixedIds() { | ||
String pubmedId = "pubmedId1"; | ||
String pubmedId2 = "pubmedId2"; | ||
String doiId = "doiId1"; | ||
String doiId2 = "doiId2"; | ||
List<UniProtKBReference> references = | ||
getUniProtKBReferences(CitationDatabase.PUBMED, pubmedId, pubmedId2); | ||
references.addAll(getUniProtKBReferences(CitationDatabase.DOI, doiId, doiId2)); | ||
|
||
EntryReferenceMap mapper = new EntryReferenceMap(references); | ||
Map<String, String> result = mapper.attributeValues(); | ||
|
||
verifyFieldValue(result, LIT_PUBMED_ID, pubmedId + FIELD_SEPARATOR + pubmedId2); | ||
verifyFieldValue(result, LIT_DOI_ID, doiId + FIELD_SEPARATOR + doiId2); | ||
} | ||
|
||
private List<UniProtKBReference> getUniProtKBReferences( | ||
CitationDatabase database, String... ids) { | ||
List<UniProtKBReference> result = new ArrayList<>(); | ||
for (String id : ids) { | ||
Citation citation = | ||
new ElectronicArticleBuilder() | ||
.citationCrossReferencesAdd( | ||
new CrossReferenceBuilder<CitationDatabase>() | ||
.database(database) | ||
.id(id) | ||
.build()) | ||
.build(); | ||
UniProtKBReference reference = | ||
new UniProtKBReferenceBuilder().citation(citation).build(); | ||
result.add(reference); | ||
} | ||
return result; | ||
} | ||
|
||
private void verifyFieldValue( | ||
Map<String, String> result, String fieldName, String expectedValue) { | ||
String resultValue = result.get(fieldName); | ||
assertNotNull(resultValue); | ||
assertEquals(expectedValue, resultValue); | ||
} | ||
} |