Commit ec799ee1 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

model annotator coverage tests

parent aa2f032b
......@@ -378,7 +378,7 @@ public class ModelAnnotator {
* {@link AnnotatedObject}
* @return list of improper annotations
*/
protected Collection<ImproperAnnotations> findImproperAnnotations(AnnotatedObject element, Collection<MiriamType> validClasses) {
protected List<ImproperAnnotations> findImproperAnnotations(AnnotatedObject element, Collection<MiriamType> validClasses) {
List<ImproperAnnotations> result = new ArrayList<>();
for (MiriamData md : element.getMiriamData()) {
boolean valid = false;
......@@ -498,7 +498,7 @@ public class ModelAnnotator {
* class for which list of annotators will be returned
* @return annotators names for a given class
*/
public Collection<String> getAvailableAnnotatorNames(Class<?> clazz) {
public List<String> getAvailableAnnotatorNames(Class<?> clazz) {
List<String> result = new ArrayList<>();
for (ElementAnnotator annotator : getAvailableAnnotators(clazz)) {
result.add(annotator.getCommonName());
......@@ -514,8 +514,8 @@ public class ModelAnnotator {
* class for which list of default annotators will be returned
* @return annotators names for a given class
*/
public Collection<String> getAvailableDefaultAnnotatorNames(Class<?> clazz) {
List<String> result = new ArrayList<String>();
public List<String> getAvailableDefaultAnnotatorNames(Class<?> clazz) {
List<String> result = new ArrayList<>();
for (ElementAnnotator annotator : getAvailableDefaultAnnotators(clazz)) {
result.add(annotator.getCommonName());
}
......@@ -530,8 +530,8 @@ public class ModelAnnotator {
* class for which list of default annotators will be returned
* @return annotators for a given class
*/
public Collection<ElementAnnotator> getAvailableDefaultAnnotators(Class<?> clazz) {
List<ElementAnnotator> result = new ArrayList<ElementAnnotator>();
public List<ElementAnnotator> getAvailableDefaultAnnotators(Class<?> clazz) {
List<ElementAnnotator> result = new ArrayList<>();
for (ElementAnnotator annotator : availableAnnotators) {
if (annotator.isAnnotatable(clazz) && annotator.isDefault()) {
result.add(annotator);
......@@ -549,7 +549,7 @@ public class ModelAnnotator {
* @return list of {@link ElementAnnotator annotators}
*/
public List<ElementAnnotator> getAnnotatorsFromCommonNames(List<String> list) {
List<ElementAnnotator> result = new ArrayList<ElementAnnotator>();
List<ElementAnnotator> result = new ArrayList<>();
for (String string : list) {
boolean added = false;
for (ElementAnnotator annotator : availableAnnotators) {
......
......@@ -29,6 +29,7 @@ import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.annotation.services.annotators.ReconAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.AnnotatedObject;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamRelationType;
......@@ -239,6 +240,36 @@ public class ModelAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testFindInmproperAnnotations2() throws Exception {
try {
List<MiriamType> list = new ArrayList<>();
list.add(MiriamType.PUBMED);
Reaction reaction = new Reaction();
reaction.addMiriamData(new MiriamData(MiriamType.PUBMED, "12345"));
List<ImproperAnnotations> result = modelAnnotator.findImproperAnnotations(reaction, list);
assertEquals(0, result.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testFindInmproperAnnotations3() throws Exception {
try {
List<MiriamType> list = new ArrayList<>();
list.add(MiriamType.PUBMED);
Reaction reaction = new Reaction();
reaction.addMiriamData(new MiriamData(MiriamType.PUBMED, "inv_id"));
List<ImproperAnnotations> result = modelAnnotator.findImproperAnnotations(reaction, list);
assertEquals(1, result.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testFindMissingAnnotations() throws Exception {
try {
......@@ -252,6 +283,21 @@ public class ModelAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testFindMissingAnnotations2() throws Exception {
try {
Model model = getModelForFile("testFiles/annotation/missingAnnotations.xml", false);
Map<Class<? extends AnnotatedObject>, Set<MiriamType>> requestedAnnotations = new HashMap<>();;
requestedAnnotations.put(GenericProtein.class, new HashSet<>());
Collection<? extends ProblematicAnnotation> results = modelAnnotator.findMissingAnnotations(model, requestedAnnotations);
assertEquals(1, results.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotateModelWithDrugMolecule() throws Exception {
try {
......@@ -336,4 +382,75 @@ public class ModelAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testGetAvailableAnnotatorNamess() {
try {
List<String> list = modelAnnotator.getAvailableAnnotatorNames(Protein.class);
assertTrue(list.size() > 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetAvailableAnnotators2() {
try {
List<ElementAnnotator> list = modelAnnotator.getAvailableAnnotators();
assertTrue(list.size() > 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetAvailableDefaultAnnotators() {
try {
List<ElementAnnotator> list = modelAnnotator.getAvailableDefaultAnnotators(Protein.class);
assertTrue(list.size() > 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetAvailableDefaultAnnotatorNamess() {
try {
List<String> list = modelAnnotator.getAvailableDefaultAnnotatorNames(Protein.class);
assertTrue(list.size() > 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetAnnotatorsFromCommonNames() {
try {
List<ElementAnnotator> list = modelAnnotator.getAnnotatorsFromCommonNames(modelAnnotator.getAvailableAnnotatorNames(Protein.class));
assertTrue(list.size() > 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetAnnotatorsFromInvalidName() {
try {
String name = "unkName";
List<String> names = new ArrayList<>();
names.add(name);
modelAnnotator.getAnnotatorsFromCommonNames(names);
fail();
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
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