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

changes to make sure that the results are the same after refactoring (order of...

changes to make sure that the results are the same after refactoring (order of elements in returned structure)
parent 43496542
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import java.awt.geom.Line2D;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -187,23 +188,54 @@ public class ReactionsRestImpl extends BaseRestImpl {
return result;
}
private List<Map<String, Object>> getLines(AbstractNode reactant) {
protected List<Map<String, Object>> getLines(AbstractNode reactant) {
// order in this method is to keep the order from previous version, it can be
// changed in the future, but I wanted to make that it's giving the same results
// when refactoring
List<Map<String, Object>> result = new ArrayList<>();
List<Line2D> rLines = reactant.getLine().getLines();
for (Line2D line2d : rLines) {
Map<String, Object> line = new TreeMap<>();
line.put("start", line2d.getP1());
line.put("end", line2d.getP2());
if (reactant instanceof Reactant) {
line.put("type", "START");
} else if (reactant instanceof Product) {
line.put("type", "END");
} else {
line.put("type", "MIDDLE");
List<Line2D> startLines = new ArrayList<>();
List<Line2D> middleLines = new ArrayList<>();
List<Line2D> endLines = new ArrayList<>();
List<Line2D> lines = reactant.getLine().getLines();
if (reactant instanceof Reactant) {
startLines.add(lines.get(0));
for (int i = 1; i < lines.size(); i++) {
middleLines.add(lines.get(i));
}
} else if (reactant instanceof Product) {
endLines.add(lines.get(lines.size() - 1));
for (int i = 0; i < lines.size()-1; i++) {
middleLines.add(lines.get(i));
}
result.add(line);
} else if (reactant instanceof Modifier) {
middleLines.add(lines.get(lines.size() - 1));
for (int i = 0; i < lines.size()-1; i++) {
middleLines.add(lines.get(i));
}
} else {
middleLines.addAll(lines);
}
for (Line2D line2d : startLines) {
result.add(lineToMap(line2d, "START"));
}
for (Line2D line2d : endLines) {
result.add(lineToMap(line2d, "END"));
}
for (Line2D line2d : middleLines) {
result.add(lineToMap(line2d, "MIDDLE"));
}
return result;
}
private Map<String, Object> lineToMap(Line2D line2d, String type) {
Map<String, Object> result = new LinkedHashMap<>();
result.put("start", line2d.getP1());
result.put("end", line2d.getP2());
result.put("type", type);
return result;
}
......
package lcsb.mapviewer.api.projects.models.bioEntities.reactions;
import static org.junit.Assert.assertEquals;
import java.awt.geom.Point2D;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.reaction.Modifier;
import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.species.GenericProtein;
public class ReactionsRestImplTest extends RestTestFunctions {
@Autowired
ReactionsRestImpl reactionsRestImpl;
@Test
public void testLineCreationForReactant() {
Reactant reactant = new Reactant();
reactant.setLine(new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(1, 0)));
List<?> lines = reactionsRestImpl.getLines(reactant);
assertEquals(1, lines.size());
}
@Test
public void testLineCreationForProduct() {
Product reactant = new Product();
reactant.setLine(new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(1, 0)));
List<?> lines = reactionsRestImpl.getLines(reactant);
assertEquals(1, lines.size());
}
@Test
public void testLineCreationForModifier() {
Modifier modifier = new Modifier(new GenericProtein("id"));
modifier.setLine(new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(1, 0)));
List<?> lines = reactionsRestImpl.getLines(modifier);
assertEquals(1, lines.size());
}
}
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