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;
*/
public class Target implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
private static transient Logger logger = Logger.getLogger(Target.class);
/**
* Database from which target was received.
*/
private MiriamData source;
/**
* Name of the target.
*/
private String name;
/**
* Organism in which target is located.
*/
private MiriamData organism;
/**
* List of genes located in a target.
*/
private List<MiriamData> genes = new ArrayList<>();
/**
* List of references describing target.
*/
private List<MiriamData> references = new ArrayList<>();
/**
* Type of target.
*/
private TargetType type;
/**
* Default constructor.
*/
public Target() {
}
/**
* Constructor that initializes target with some data.
*
* @param source
* from where the information about target was retrieved
* @param gene
* {@link MiriamData} that identifies gene
* @param references
* list of references that support this target
*/
public Target(MiriamData source, MiriamData gene, Collection<MiriamData> references) {
this.source = source;
if (gene != null) {
addGene(gene);
}
addReferences(references);
if (genes.size() == 1) {
setType(TargetType.SINGLE_PROTEIN);
}
}
/**
* @return the type
* @see #type
*/
public TargetType getType() {
return type;
}
/**
* @param type
* the type to set
* @see #type
*/
public void setType(TargetType type) {
this.type = type;
}
/**
*
* @return {@link #references} list
*/
@XmlElement(name = "pubmed")
public List<MiriamData> getReferences() {
return references;
}
/**
*
* @param md
* new {@link #references} list
*/
public void addReference(MiriamData md) {
if (this.references.contains(md)) {
logger.warn("Target " + getName() + " already has MiriamData: " + md);
} else {
this.references.add(md);
}
}
/**
* Adds gene to the gene list.
*
* @param gene
* object to add
*/
public void addGene(MiriamData gene) {
if (gene == null) {
throw new InvalidArgumentException("Cannot add null element");
}
this.genes.add(gene);
}
/**
* @return the name
* @see #name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
* @see #name
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the organism
* @see #organism
*/
public MiriamData getOrganism() {
return organism;
}
/**
* @param organism
* the organism to set
* @see #organism
*/
public void setOrganism(MiriamData organism) {
this.organism = organism;
}
/**
* @return the geneCardId
* @see #genes
*/
public List<MiriamData> getGenes() {
return genes;
}
/**
* @param genes
* the genes to set
* @see #genes
*/
public void setGenes(List<MiriamData> genes) {
this.genes = genes;
}
/**
* @return the source
* @see #source
*/
public MiriamData getSource() {
return source;
}
/**
* @param source
* the source to set
* @see #source
*/
public void setSource(MiriamData source) {
this.source = source;
}
/**
* Adds set of references to the target.
*
* @param references
* objects to add
*
* @see #references
*/
public void addReferences(Collection<MiriamData> references) {
this.references.addAll(references);
}
@Override
public String toString() {
return "[" + this.getClass().getSimpleName() + "]: " + name + ", source: " + source + ", organism: " + organism + "; ";
}
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
private static transient Logger logger = Logger.getLogger(Target.class);
/**
* Database from which target was received.
*/
private MiriamData source;
/**
* Name of the target.
*/
private String name;
/**
* Organism in which target is located.
*/
private MiriamData organism;
/**
* List of genes located in a target.
*/
private List<MiriamData> genes = new ArrayList<>();
/**
* List of references describing target.
*/
private List<MiriamData> references = new ArrayList<>();
/**
* Type of target.
*/
private TargetType type;
/**
* Default constructor.
*/
public Target() {
}
/**
* Constructor that initializes target with some data.
*
* @param source
* from where the information about target was retrieved
* @param gene
* {@link MiriamData} that identifies gene
* @param references
* list of references that support this target
*/
public Target(MiriamData source, MiriamData gene, Collection<MiriamData> references) {
this.source = source;
if (gene != null) {
addGene(gene);
}
addReferences(references);
if (getGenes().size() == 1) {
setType(TargetType.SINGLE_PROTEIN);
}
}
/**
* @return the type
* @see #type
*/
public TargetType getType() {
return type;
}
/**
* @param type
* the type to set
* @see #type
*/
public void setType(TargetType type) {
this.type = type;
}
/**
*
* @return {@link #references} list
*/
@XmlElement(name = "pubmed")
public List<MiriamData> getReferences() {
return references;
}
/**
*
* @param md
* new {@link #references} list
*/
public void addReference(MiriamData md) {
if (this.references.contains(md)) {
logger.warn("Target " + getName() + " already has MiriamData: " + md);
} else {
this.references.add(md);
}
}
/**
* Adds gene to the gene list.
*
* @param gene
* object to add
*/
public void addGene(MiriamData gene) {
if (gene == null) {
throw new InvalidArgumentException("Cannot add null element");
}
this.genes.add(gene);
}
/**
* @return the name
* @see #name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
* @see #name
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the organism
* @see #organism
*/
public MiriamData getOrganism() {
return organism;
}
/**
* @param organism
* the organism to set
* @see #organism
*/
public void setOrganism(MiriamData organism) {
this.organism = organism;
}
/**
* @return the geneCardId
* @see #genes
*/
public List<MiriamData> getGenes() {
return genes;
}
/**
* @param genes
* the genes to set
* @see #genes
*/
public void setGenes(List<MiriamData> genes) {
this.genes = genes;
}
/**
* @return the source
* @see #source
*/
public MiriamData getSource() {
return source;
}
/**
* @param source
* the source to set
* @see #source
*/
public void setSource(MiriamData source) {
this.source = source;
}
/**
* Adds set of references to the target.
*
* @param references
* objects to add
*
* @see #references
*/
public void addReferences(Collection<MiriamData> references) {
this.references.addAll(references);
}
@Override
public String toString() {
return "[" + this.getClass().getSimpleName() + "]: " + name + ", source: " + source + ", organism: " + organism
+ "; ";
}
}
......@@ -243,19 +243,21 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
* @return {@link MiriamData} with {@link MiriamType#HGNC_SYMBOL} identifier
* that could be extracted from input data
* @throws DrugSearchException
* thrown when there is aproblem with annotations
* thrown when there is a problem with annotations
*/
private MiriamData targetComponentToMiriamData(Node targetComponent) throws DrugSearchException {
MiriamData result = null;
Node uniprotAccessionId = getNode("accession", targetComponent.getChildNodes());
if (uniprotAccessionId != null) {
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) {
throw new DrugSearchException(e);
}
} else {
return null;
}
return result;
}
/**
......
......@@ -380,6 +380,7 @@ public class DrugbankHTMLParser extends DrugAnnotation implements IExternalServi
MiriamData uniprotTarget = new MiriamData(MiriamType.UNIPROT, uniprotId);
MiriamData hgncTarget = uniprotAnnotator.uniProtToHgnc(uniprotTarget);
if (hgncTarget != null) {
hgncTarget.setAnnotator(null);
result.addGene(hgncTarget);
} else {
result.addGene(uniprotTarget);
......
......@@ -285,13 +285,12 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
@Test
public void testGetByTarget() throws Exception {
try {
// Parkinson disease
MiriamData target = new MiriamData(MiriamType.HGNC_SYMBOL, "TNF");
List<MiriamData> targets = new ArrayList<>();
targets.add(target);
List<Chemical> list = chemicalParser.getChemicalListByTarget(targets, parkinsonDiseaseId);
assertNotNull(list);
assertTrue(!list.isEmpty());
assertFalse(list.isEmpty());
} catch (Exception e) {
e.printStackTrace();
......@@ -302,7 +301,6 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
@Test
public void testGetByInvalidTarget() throws Exception {
try {
// Parkinson disease
MiriamData target = new MiriamData(MiriamType.WIKIPEDIA, "TNF");
List<MiriamData> targets = new ArrayList<>();
targets.add(target);
......
......@@ -11,6 +11,7 @@
"build": "npm run clean && npm run build:css && npm run build:js",
"clean": "node scripts/clean.js",
"deploy": "node scripts/deploy.js",
"refresh-mock-requests": "node scripts/refresh_mock_requests.js",
"lint": "jshint src/.",
"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),
login: extractLogin(file),
params: extractParams(file)
})