Skip to content
Snippets Groups Projects
Commit 1331ea0a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unit tests fixed (model cannot contain reactions with the same id)

parent eb819fd5
No related branches found
No related tags found
1 merge request!190Resolve "uploading zip file from MAC"
Pipeline #
......@@ -616,4 +616,6 @@ public interface Model {
void addFunction(SbmlFunction sbmlFunction);
SbmlArgument getFunctionById(String id);
void removeReactions(Collection<Reaction> reactions);
}
......@@ -734,4 +734,13 @@ public class ModelFullIndexed implements Model {
}
return null;
}
@Override
public void removeReactions(Collection<Reaction> reactions) {
Set<Reaction> reactionsToRemove = new HashSet<>();
reactionsToRemove.addAll(reactions);
for (Reaction reaction : reactionsToRemove) {
removeReaction(reaction);
}
}
}
......@@ -40,195 +40,197 @@ import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.overlay.ChebiTreeRow;
public class FullAliasViewFactoryTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(FullAliasViewFactoryTest.class);
@Autowired
FullAliasViewFactory fullAliasViewFactory;
@Autowired
private ChebiAnnotator backend;
private Species alias;
private Species alias2;
private Point2D midPoint;
private Reaction reaction;
private Species alias3;
private Model model;
private Compartment compartmentAlias;
@Before
public void setUp() throws Exception {
model = new ModelFullIndexed(null);
model.setWidth(20010);
model.setHeight(20010);
model.setTileSize(256);
model.setZoomLevels(7);
model.addLayout(new Layout());
model.getModelData().setId(-12);
alias = new GenericProtein("AL1");
alias.setName("blablabla");
alias.setNotes("nottttttes");
alias.setX(10.0);
alias.setY(12.0);
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.WIKIPEDIA, "144352"));
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.PUBMED, "43345"));
model.addElement(alias);
alias2 = new GenericProtein("AL2");
alias2.setName("blablabla2");
alias2.setX(100.0);
alias2.setY(120.0);
model.addElement(alias2);
midPoint = new Point2D.Double(30, 100);
reaction = new Reaction();
Reactant reactant = new Reactant(alias);
reactant.setLine(new PolylineData(alias.getCenter(), midPoint));
reaction.addReactant(reactant);
Product product = new Product(alias2);
product.setLine(new PolylineData(alias2.getCenter(), midPoint));
reaction.addProduct(product);
model.addReaction(reaction);
alias3 = new GenericProtein("AL3");
alias3.setName("blablabla3");
alias3.setX(200.0);
alias3.setY(120.0);
model.addElement(alias3);
reaction = new NegativeInfluenceReaction(reaction);
reaction.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CAS, "cc"));
model.addReaction(reaction);
compartmentAlias = new Compartment("AL4");
compartmentAlias.setX(10);
compartmentAlias.setY(10);
compartmentAlias.setWidth(10);
compartmentAlias.setHeight(10);
model.addElement(compartmentAlias);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateGson() {
try {
Element alias = new GenericProtein("id");
alias.setName("12");
alias.setModel(new ModelFullIndexed(null));
FullAliasView object = fullAliasViewFactory.create(alias);
String gson = fullAliasViewFactory.createGson(object);
assertNotNull(gson);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay2() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias2);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetNotes() throws Exception {
try {
Model model = getModelForFile("testFiles/protein_with_modification.xml", true);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa1");
FullAliasView marker = fullAliasViewFactory.create(alias);
List<?> list = (List<?>) marker.getOther("posttranslationalModifications");
assertNotNull(list);
assertEquals(2, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateChebiTree() throws Exception {
try {
Chebi chebi = backend.getChebiElementForChebiId(new MiriamData(MiriamType.CHEBI, "CHEBI:15377"));
TreeNode root = fullAliasViewFactory.createTreeForChebi(chebi);
Set<String> el = new HashSet<String>();
assertNotNull(root);
Queue<TreeNode> elements = new LinkedList<TreeNode>();
elements.add(root);
while (!elements.isEmpty()) {
TreeNode node = elements.peek();
elements.remove();
el.add(((ChebiTreeRow) node.getData()).getName());
for (TreeNode child : node.getChildren()) {
elements.add(child);
}
}
assertTrue(el.size() > 3);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotationsInConversionForChebiTree() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", false);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa4");
assertNotNull(alias);
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result.getOther("chebiTree"));
alias = (Species) model.getElementByElementId("sa3");
result = fullAliasViewFactory.create(alias);
assertNull(result.getOther("chebiTree"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Logger logger = Logger.getLogger(FullAliasViewFactoryTest.class);
@Autowired
FullAliasViewFactory fullAliasViewFactory;
@Autowired
private ChebiAnnotator backend;
private Species alias;
private Species alias2;
private Point2D midPoint;
private Reaction reaction;
private Species alias3;
private Model model;
private Compartment compartmentAlias;
@Before
public void setUp() throws Exception {
model = new ModelFullIndexed(null);
model.setWidth(20010);
model.setHeight(20010);
model.setTileSize(256);
model.setZoomLevels(7);
model.addLayout(new Layout());
model.getModelData().setId(-12);
alias = new GenericProtein("AL1");
alias.setName("blablabla");
alias.setNotes("nottttttes");
alias.setX(10.0);
alias.setY(12.0);
alias.getMiriamData()
.add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.WIKIPEDIA, "144352"));
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.PUBMED, "43345"));
model.addElement(alias);
alias2 = new GenericProtein("AL2");
alias2.setName("blablabla2");
alias2.setX(100.0);
alias2.setY(120.0);
model.addElement(alias2);
midPoint = new Point2D.Double(30, 100);
reaction = new Reaction("re1");
Reactant reactant = new Reactant(alias);
reactant.setLine(new PolylineData(alias.getCenter(), midPoint));
reaction.addReactant(reactant);
Product product = new Product(alias2);
product.setLine(new PolylineData(alias2.getCenter(), midPoint));
reaction.addProduct(product);
model.addReaction(reaction);
alias3 = new GenericProtein("AL3");
alias3.setName("blablabla3");
alias3.setX(200.0);
alias3.setY(120.0);
model.addElement(alias3);
reaction = new NegativeInfluenceReaction(reaction);
reaction.setIdReaction("re2");
reaction.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CAS, "cc"));
model.addReaction(reaction);
compartmentAlias = new Compartment("AL4");
compartmentAlias.setX(10);
compartmentAlias.setY(10);
compartmentAlias.setWidth(10);
compartmentAlias.setHeight(10);
model.addElement(compartmentAlias);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateGson() {
try {
Element alias = new GenericProtein("id");
alias.setName("12");
alias.setModel(new ModelFullIndexed(null));
FullAliasView object = fullAliasViewFactory.create(alias);
String gson = fullAliasViewFactory.createGson(object);
assertNotNull(gson);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay2() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias2);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetNotes() throws Exception {
try {
Model model = getModelForFile("testFiles/protein_with_modification.xml", true);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa1");
FullAliasView marker = fullAliasViewFactory.create(alias);
List<?> list = (List<?>) marker.getOther("posttranslationalModifications");
assertNotNull(list);
assertEquals(2, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateChebiTree() throws Exception {
try {
Chebi chebi = backend.getChebiElementForChebiId(new MiriamData(MiriamType.CHEBI, "CHEBI:15377"));
TreeNode root = fullAliasViewFactory.createTreeForChebi(chebi);
Set<String> el = new HashSet<String>();
assertNotNull(root);
Queue<TreeNode> elements = new LinkedList<TreeNode>();
elements.add(root);
while (!elements.isEmpty()) {
TreeNode node = elements.peek();
elements.remove();
el.add(((ChebiTreeRow) node.getData()).getName());
for (TreeNode child : node.getChildren()) {
elements.add(child);
}
}
assertTrue(el.size() > 3);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotationsInConversionForChebiTree() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", false);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa4");
assertNotNull(alias);
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result.getOther("chebiTree"));
alias = (Species) model.getElementByElementId("sa3");
result = fullAliasViewFactory.create(alias);
assertNull(result.getOther("chebiTree"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment