Commit 5e65fe5c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

script in frontend unt tests to refresh query cache for mocking server side

This sript refreshes all GET queries. Because of that some tests had to be modified. And api resposnes are reproducible now (sets results are changed to a "sorted" set, so with every query we should have the same response).
Second big change is that overlay iamages are stored differently (there are no overlays in submaps anymore)
parent 28785dc8
...@@ -21,209 +21,210 @@ import lcsb.mapviewer.model.map.MiriamData; ...@@ -21,209 +21,210 @@ import lcsb.mapviewer.model.map.MiriamData;
*/ */
public class Target implements Serializable { public class Target implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Default class logger. * Default class logger.
*/ */
private static transient Logger logger = Logger.getLogger(Target.class); private static transient Logger logger = Logger.getLogger(Target.class);
/** /**
* Database from which target was received. * Database from which target was received.
*/ */
private MiriamData source; private MiriamData source;
/** /**
* Name of the target. * Name of the target.
*/ */
private String name; private String name;
/** /**
* Organism in which target is located. * Organism in which target is located.
*/ */
private MiriamData organism; private MiriamData organism;
/** /**
* List of genes located in a target. * List of genes located in a target.
*/ */
private List<MiriamData> genes = new ArrayList<>(); private List<MiriamData> genes = new ArrayList<>();
/** /**
* List of references describing target. * List of references describing target.
*/ */
private List<MiriamData> references = new ArrayList<>(); private List<MiriamData> references = new ArrayList<>();
/** /**
* Type of target. * Type of target.
*/ */
private TargetType type; private TargetType type;
/** /**
* Default constructor. * Default constructor.
*/ */
public Target() { public Target() {
} }
/** /**
* Constructor that initializes target with some data. * Constructor that initializes target with some data.
* *
* @param source * @param source
* from where the information about target was retrieved * from where the information about target was retrieved
* @param gene * @param gene
* {@link MiriamData} that identifies gene * {@link MiriamData} that identifies gene
* @param references * @param references
* list of references that support this target * list of references that support this target
*/ */
public Target(MiriamData source, MiriamData gene, Collection<MiriamData> references) { public Target(MiriamData source, MiriamData gene, Collection<MiriamData> references) {
this.source = source; this.source = source;
if (gene != null) { if (gene != null) {
addGene(gene); addGene(gene);
} }
addReferences(references); addReferences(references);
if (genes.size() == 1) { if (getGenes().size() == 1) {
setType(TargetType.SINGLE_PROTEIN); setType(TargetType.SINGLE_PROTEIN);
} }
} }
/** /**
* @return the type * @return the type
* @see #type * @see #type
*/ */
public TargetType getType() { public TargetType getType() {
return type; return type;
} }
/** /**
* @param type * @param type
* the type to set * the type to set
* @see #type * @see #type
*/ */
public void setType(TargetType type) { public void setType(TargetType type) {
this.type = type; this.type = type;
} }
/** /**
* *
* @return {@link #references} list * @return {@link #references} list
*/ */
@XmlElement(name = "pubmed") @XmlElement(name = "pubmed")
public List<MiriamData> getReferences() { public List<MiriamData> getReferences() {
return references; return references;
} }
/** /**
* *
* @param md * @param md
* new {@link #references} list * new {@link #references} list
*/ */
public void addReference(MiriamData md) { public void addReference(MiriamData md) {
if (this.references.contains(md)) { if (this.references.contains(md)) {
logger.warn("Target " + getName() + " already has MiriamData: " + md); logger.warn("Target " + getName() + " already has MiriamData: " + md);
} else { } else {
this.references.add(md); this.references.add(md);
} }
} }
/** /**
* Adds gene to the gene list. * Adds gene to the gene list.
* *
* @param gene * @param gene
* object to add * object to add
*/ */
public void addGene(MiriamData gene) { public void addGene(MiriamData gene) {
if (gene == null) { if (gene == null) {
throw new InvalidArgumentException("Cannot add null element"); throw new InvalidArgumentException("Cannot add null element");
} }
this.genes.add(gene); this.genes.add(gene);
} }
/** /**
* @return the name * @return the name
* @see #name * @see #name
*/ */
public String getName() { public String getName() {
return name; return name;
} }
/** /**
* @param name * @param name
* the name to set * the name to set
* @see #name * @see #name
*/ */
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** /**
* @return the organism * @return the organism
* @see #organism * @see #organism
*/ */
public MiriamData getOrganism() { public MiriamData getOrganism() {
return organism; return organism;
} }
/** /**
* @param organism * @param organism
* the organism to set * the organism to set
* @see #organism * @see #organism
*/ */
public void setOrganism(MiriamData organism) { public void setOrganism(MiriamData organism) {
this.organism = organism; this.organism = organism;
} }
/** /**
* @return the geneCardId * @return the geneCardId
* @see #genes * @see #genes
*/ */
public List<MiriamData> getGenes() { public List<MiriamData> getGenes() {
return genes; return genes;
} }
/** /**
* @param genes * @param genes
* the genes to set * the genes to set
* @see #genes * @see #genes
*/ */
public void setGenes(List<MiriamData> genes) { public void setGenes(List<MiriamData> genes) {
this.genes = genes; this.genes = genes;
} }
/** /**
* @return the source * @return the source
* @see #source * @see #source
*/ */
public MiriamData getSource() { public MiriamData getSource() {
return source; return source;
} }
/** /**
* @param source * @param source
* the source to set * the source to set
* @see #source * @see #source
*/ */
public void setSource(MiriamData source) { public void setSource(MiriamData source) {
this.source = source; this.source = source;
} }
/** /**
* Adds set of references to the target. * Adds set of references to the target.
* *
* @param references * @param references
* objects to add * objects to add
* *
* @see #references * @see #references
*/ */
public void addReferences(Collection<MiriamData> references) { public void addReferences(Collection<MiriamData> references) {
this.references.addAll(references); this.references.addAll(references);
} }
@Override @Override
public String toString() { public String toString() {
return "[" + this.getClass().getSimpleName() + "]: " + name + ", source: " + source + ", organism: " + organism + "; "; return "[" + this.getClass().getSimpleName() + "]: " + name + ", source: " + source + ", organism: " + organism
} + "; ";
}
} }
...@@ -243,19 +243,21 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService { ...@@ -243,19 +243,21 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
* @return {@link MiriamData} with {@link MiriamType#HGNC_SYMBOL} identifier * @return {@link MiriamData} with {@link MiriamType#HGNC_SYMBOL} identifier
* that could be extracted from input data * that could be extracted from input data
* @throws DrugSearchException * @throws DrugSearchException
* thrown when there is aproblem with annotations * thrown when there is a problem with annotations
*/ */
private MiriamData targetComponentToMiriamData(Node targetComponent) throws DrugSearchException { private MiriamData targetComponentToMiriamData(Node targetComponent) throws DrugSearchException {
MiriamData result = null;
Node uniprotAccessionId = getNode("accession", targetComponent.getChildNodes()); Node uniprotAccessionId = getNode("accession", targetComponent.getChildNodes());
if (uniprotAccessionId != null) { if (uniprotAccessionId != null) {
try { try {
return uniprotAnnotator.uniProtToHgnc(new MiriamData(MiriamType.UNIPROT, uniprotAccessionId.getTextContent())); result = uniprotAnnotator
.uniProtToHgnc(new MiriamData(MiriamType.UNIPROT, uniprotAccessionId.getTextContent()));
result.setAnnotator(null);
} catch (UniprotSearchException e) { } catch (UniprotSearchException e) {
throw new DrugSearchException(e); throw new DrugSearchException(e);
} }
} else {
return null;
} }
return result;
} }
/** /**
......
...@@ -380,6 +380,7 @@ public class DrugbankHTMLParser extends DrugAnnotation implements IExternalServi ...@@ -380,6 +380,7 @@ public class DrugbankHTMLParser extends DrugAnnotation implements IExternalServi
MiriamData uniprotTarget = new MiriamData(MiriamType.UNIPROT, uniprotId); MiriamData uniprotTarget = new MiriamData(MiriamType.UNIPROT, uniprotId);
MiriamData hgncTarget = uniprotAnnotator.uniProtToHgnc(uniprotTarget); MiriamData hgncTarget = uniprotAnnotator.uniProtToHgnc(uniprotTarget);
if (hgncTarget != null) { if (hgncTarget != null) {
hgncTarget.setAnnotator(null);
result.addGene(hgncTarget); result.addGene(hgncTarget);
} else { } else {
result.addGene(uniprotTarget); result.addGene(uniprotTarget);
......
...@@ -285,13 +285,12 @@ public class ChemicalParserTest extends AnnotationTestFunctions { ...@@ -285,13 +285,12 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
@Test @Test
public void testGetByTarget() throws Exception { public void testGetByTarget() throws Exception {
try { try {
// Parkinson disease
MiriamData target = new MiriamData(MiriamType.HGNC_SYMBOL, "TNF"); MiriamData target = new MiriamData(MiriamType.HGNC_SYMBOL, "TNF");
List<MiriamData> targets = new ArrayList<>(); List<MiriamData> targets = new ArrayList<>();
targets.add(target); targets.add(target);
List<Chemical> list = chemicalParser.getChemicalListByTarget(targets, parkinsonDiseaseId); List<Chemical> list = chemicalParser.getChemicalListByTarget(targets, parkinsonDiseaseId);
assertNotNull(list); assertNotNull(list);
assertTrue(!list.isEmpty()); assertFalse(list.isEmpty());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -302,7 +301,6 @@ public class ChemicalParserTest extends AnnotationTestFunctions { ...@@ -302,7 +301,6 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
@Test @Test
public void testGetByInvalidTarget() throws Exception { public void testGetByInvalidTarget() throws Exception {
try { try {
// Parkinson disease
MiriamData target = new MiriamData(MiriamType.WIKIPEDIA, "TNF"); MiriamData target = new MiriamData(MiriamType.WIKIPEDIA, "TNF");
List<MiriamData> targets = new ArrayList<>(); List<MiriamData> targets = new ArrayList<>();
targets.add(target); targets.add(target);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"build": "npm run clean && npm run build:css && npm run build:js", "build": "npm run clean && npm run build:css && npm run build:js",
"clean": "node scripts/clean.js", "clean": "node scripts/clean.js",
"deploy": "node scripts/deploy.js", "deploy": "node scripts/deploy.js",
"refresh-mock-requests": "node scripts/refresh_mock_requests.js",
"lint": "jshint src/.", "lint": "jshint src/.",
"test": "istanbul cover node_modules/mocha/bin/_mocha -- --recursive src/test/js" "test": "istanbul cover node_modules/mocha/bin/_mocha -- --recursive src/test/js"
}, },
......
const testFolder = './testFiles/apiCalls';
const apiBaseDir = 'http://localhost:8080/minerva/api/';
const fs = require('fs');
const path = require('path');
const request = require('request');
function listFiles(dir, filelist) {
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function (file) {
if (fs.statSync(dir + '/' + file).isDirectory()) {
filelist = listFiles(dir + '/' + file, filelist);
}
else {
filelist.push(dir + "/" + file);
}
});
return filelist;
}
function extractUrl(file) {
var url = apiBaseDir + path.dirname(file);
url = url.replace(testFolder, "") + "/";
url = url.replace("/all/", "/*/");
//don't change "." character if it's part of a number
if (!/\.[0-9]+/.test(url)) {
url = url.replace(".", ":");
}
return url;
}
function extractLogin(file) {
var filename = file.replace(path.dirname(file), "").substr(1);
if (filename.endsWith("MOCK_TOKEN_ID&")) {
return "anonymous";
}
if (filename.endsWith("ADMIN_TOKEN_ID&")) {
return "admin";
}
return undefined;
}
function extractMethod(file) {
var filename = file.replace(path.dirname(file), "").substr(1);
var method = filename.split("=")[0];
var result;
if (method.indexOf("_") >= 0) {
result = method.split("_")[0];
} else {
result = "GET";
}
return result;
}
function setParam(params, key, value) {
if (key.indexOf(".") > 0) {
var topKey = key.split(".")[0];
if (params[topKey] === undefined) {
params[topKey] = {};
}
setParam(params[topKey], key.substr(topKey.length + 1), value)
} else {
if (value.indexOf("ALIAS.") >= 0) {
value = value.replace("ALIAS.", "ALIAS:")
}
if (value.indexOf("REACTION.") >= 0) {
value = value.replace("REACTION.", "REACTION:")
}
params[key] = value;
}
}
function extractParams(file) {
var filename = file.replace(path.dirname(file), "").substr(1);
var params = {};
var method = extractMethod(file);
if (filename.indexOf(method) === 0) {
filename = filename.substr(method.length + 1);
}
var tokens = filename.split("&");
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
var key = token.split("=")[0];
var value = token.split("=")[1];
if (key !== "" && key !== "token") {
setParam(params, key, value)
}
}
return params;
}
function prepareQueries(filelist) {
var result = [];
for (var i = 0; i < filelist.length; i++) {
var file = filelist[i];
result.push({
file: file,
url: extractUrl(file),
method: extractMethod(file),