150 lines
4.2 KiB
Java
150 lines
4.2 KiB
Java
package eu.dnetlib.dhp.schema.sx.scholix;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
|
|
public class ScholixCompareTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ScholixIdentifier generateMockScholixId(boolean toUpper, int idCount) {
|
|
|
|
final String id = String.format("10.11646/zootaxa.5099.1.%d", idCount);
|
|
final String schema = "DOI";
|
|
final String url =String.format("http://dx.dOI.org/10.11646/Zootaxa.5099.1.%d", idCount);
|
|
|
|
final ScholixIdentifier result = new ScholixIdentifier();
|
|
result.setIdentifier(toUpper ? id.toUpperCase(): id.toLowerCase());
|
|
result.setSchema(toUpper ? schema.toUpperCase():schema.toLowerCase());
|
|
result.setUrl(toUpper ? url.toUpperCase():url.toLowerCase());
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
private ScholixEntityId generateMockScholixEntityId(boolean toUpper, boolean invertOrder, int numberOfIds) {
|
|
|
|
final String datasourceName = "Datacite";
|
|
|
|
final List<ScholixIdentifier> ids = new ArrayList<>();
|
|
|
|
if (!invertOrder) {
|
|
for (int i = 0; i < numberOfIds; i++) {
|
|
ids.add(generateMockScholixId(toUpper, i));
|
|
}
|
|
}
|
|
else {
|
|
for (int i = numberOfIds-1; i >=0; i--) {
|
|
ids.add(generateMockScholixId(toUpper, i));
|
|
}
|
|
}
|
|
|
|
return new ScholixEntityId(toUpper? datasourceName.toUpperCase(): datasourceName.toLowerCase(), ids);
|
|
}
|
|
|
|
private ScholixCollectedFrom generateMockScholixCollectedFrom(boolean toUpper, boolean invertOrder, int numberOfIds) {
|
|
|
|
final ScholixCollectedFrom result = new ScholixCollectedFrom();
|
|
final String completionStatus = "complete";
|
|
final String provisionMode = "collected";
|
|
result.setProvider(generateMockScholixEntityId(toUpper, invertOrder, numberOfIds));
|
|
result.setCompletionStatus(toUpper ? completionStatus.toUpperCase(): completionStatus.toLowerCase());
|
|
result.setProvisionMode(toUpper ? provisionMode.toUpperCase(): provisionMode.toLowerCase());
|
|
return result;
|
|
}
|
|
|
|
private ScholixRelationship generateMockScholixRelationships(boolean toUpper) {
|
|
|
|
final String name = "IsRelatedTo";
|
|
final String inverse = "RelatedTo";
|
|
final String schema = "datacite";
|
|
|
|
final ScholixRelationship rel = new ScholixRelationship();
|
|
|
|
rel.setName(toUpper? name.toUpperCase():name.toLowerCase());
|
|
rel.setInverse(toUpper? inverse.toUpperCase():inverse.toLowerCase());
|
|
rel.setSchema(toUpper? schema.toUpperCase():schema.toLowerCase());
|
|
|
|
return rel;
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
public void testScholixIdentifierComparison() {
|
|
|
|
final ScholixIdentifier left = generateMockScholixId(true, 1);
|
|
|
|
|
|
final ScholixIdentifier right = generateMockScholixId(false,1);
|
|
|
|
assertEquals(0,left.compareTo(right));
|
|
|
|
assertEquals(left, right);
|
|
assertEquals(left.hashCode(), right.hashCode());
|
|
|
|
|
|
left.setIdentifier(null);
|
|
|
|
assertEquals(-1, left.compareTo(right));
|
|
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
public void testScholixEntityIDComparison() {
|
|
|
|
final ScholixEntityId first =generateMockScholixEntityId(true,false,10);
|
|
final ScholixEntityId second =generateMockScholixEntityId(false,true,10);
|
|
assertEquals(first,second);
|
|
assertEquals(first.hashCode(), second.hashCode());
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
public void testScholixCollectedFromComparison() {
|
|
final ScholixCollectedFrom cfLeft = generateMockScholixCollectedFrom(true, true, 20);
|
|
|
|
|
|
|
|
final ScholixCollectedFrom cfRight = generateMockScholixCollectedFrom(false, false, 20);
|
|
|
|
assertEquals(cfLeft, cfRight);
|
|
|
|
assertEquals(cfLeft.hashCode(), cfRight.hashCode());
|
|
|
|
cfRight.setCompletionStatus(null);
|
|
|
|
assertNotEquals(cfLeft, cfRight);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
public void testCompareScholixRelation() {
|
|
|
|
|
|
final ScholixRelationship left = generateMockScholixRelationships(true);
|
|
final ScholixRelationship right = generateMockScholixRelationships(false);
|
|
|
|
assertEquals(left, right);
|
|
assertEquals(left.hashCode(), right.hashCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|