diff --git a/CHANGELOG b/CHANGELOG index f758efea904e4c5b39e7d6ebad7e281f97a8ebb0..a70f238e18f6cb41f09fdcfaf90c85926d4303a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +minerva (14.0.0~alpha.0) unstable; urgency=low + * Feature: log4j is replaced with log4j2 logging mechanism (#291) + * Feature removal: BioCompendium annotator removed (#32) + minerva (13.1.0~alpha.0) unstable; urgency=low * Feature: annotators are more flexible - you can define set of input and outputs used by annotator (#617) diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/BiocompendiumAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/BiocompendiumAnnotator.java deleted file mode 100644 index 1d84a47976756c32213aec9a0092e8f87e3b82e5..0000000000000000000000000000000000000000 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/BiocompendiumAnnotator.java +++ /dev/null @@ -1,389 +0,0 @@ -package lcsb.mapviewer.annotation.services.annotators; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Scanner; - -import lcsb.mapviewer.common.XmlParser; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.logging.log4j.*; -import org.springframework.stereotype.Service; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; -import lcsb.mapviewer.annotation.cache.SourceNotAvailable; -import lcsb.mapviewer.annotation.services.ExternalServiceStatus; -import lcsb.mapviewer.annotation.services.ExternalServiceStatusType; -import lcsb.mapviewer.annotation.services.IExternalService; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; -import lcsb.mapviewer.converter.model.celldesigner.annotation.NoteField; -import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.species.Gene; -import lcsb.mapviewer.model.map.species.Protein; -import lcsb.mapviewer.model.map.species.Rna; -import lcsb.mapviewer.model.user.annotator.AnnotatorData; -import lcsb.mapviewer.model.user.annotator.AnnotatorInputParameter; -import lcsb.mapviewer.model.user.annotator.AnnotatorOutputParameter; -import lcsb.mapviewer.model.user.annotator.BioEntityField; - -/** - * This class is responsible for connection to Vencata annotation service. The - * service is available on - * http://biocompendium.embl.de/map_annotator/REST/GetAnnotation/. This service - * is RESTful service. To query for an annotation one need to send a POST - * message with two parameters:<br> - * Method - this parameter should be set to GetAnnotation <br> - * File - this parameter should bo connected to a file with a request<br> - * - * Request file should looks like the one in testFiles/sampleRequest.xml.<br> - * As a result the xml file is received. An example of a xml response is in - * testFiles/sampleResponse.xml - * - * - * @author Piotr Gawron - * - */ -@Service -public class BiocompendiumAnnotator extends ElementAnnotator implements IExternalService { - - /** - * Address of the restfull API for biocompendium. - */ - private static final String SERVICE_ADDRESS = "http://biocompendium.embl.de/map_annotator/REST/GetAnnotation/"; - - /** - * Standard class logger. - */ - private final Logger logger = LogManager.getLogger(BiocompendiumAnnotator.class); - - /** - * Xml parser used for processing notes into structured data. - */ - private RestAnnotationParser rap = new RestAnnotationParser(); - - /** - * Default constructor. - */ - public BiocompendiumAnnotator() { - super(BiocompendiumAnnotator.class, new Class[] { Protein.class, Gene.class, Rna.class }, true); - } - - @Override - public String refreshCacheQuery(Object query) throws SourceNotAvailable { - String result = null; - try { - if (query instanceof String) { - String name = (String) query; - result = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, name)); - } else { - throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass()); - } - } catch (IOException e) { - throw new SourceNotAvailable(e); - } - return result; - } - - /** - * Returns String with annotations for species described by {@link MiriamData} - * with {@link MiriamType#HGNC_SYMBOL} entry. - * - * @param md - * description of the element by {@link MiriamData} with - * {@link MiriamType#HGNC_SYMBOL} entry - * @return annotation for species with given name and type from Venkata server - * @throws IOException - * thrown when there is a problem with connection to the server - */ - protected String getAnnotation(MiriamData md) throws IOException { - if (!MiriamType.HGNC_SYMBOL.equals(md.getDataType())) { - throw new InvalidArgumentException( - "Only " + MiriamType.HGNC_SYMBOL.getCommonName() + " miriam registry is supported."); - } - - MiriamData miriamData = new MiriamData(md); - miriamData.setResource(miriamData.getResource().replaceAll("[\n\r]+", " ")); - - String annotation = getCacheValue(miriamData.getResource()); - if (annotation != null) { - return annotation; - } - - CloseableHttpClient httpClient = HttpClients.createDefault(); - - HttpPost httppost = new HttpPost(SERVICE_ADDRESS); - MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - - // prepare a query - String requestXml = dataToString(miriamData); - - // save query to a temporary file - File tmp = File.createTempFile("annotation-plugin", "xml"); - BufferedWriter out = new BufferedWriter(new FileWriter(tmp)); - out.write(requestXml); - out.close(); - - builder.addBinaryBody("File", tmp, ContentType.APPLICATION_OCTET_STREAM, tmp.getName()); - HttpEntity multipart = builder.build(); - httppost.setEntity(multipart); - CloseableHttpResponse response = httpClient.execute(httppost); - - HttpEntity entity2 = response.getEntity(); - if (entity2 != null) { - InputStream instream = entity2.getContent(); - Scanner scanner = new Scanner(instream); - try { - Scanner s = scanner.useDelimiter("\\A"); - // get results - String responseXml = ""; - if (s.hasNext()) { - responseXml = s.next(); - } - try { - annotation = getAnnotationsFromXml(responseXml).get(miriamData.getResource()); - } catch (InvalidXmlSchemaException e) { - throw new IOException(e); - } - - } finally { - scanner.close(); - instream.close(); - } - } - if (annotation != null) { - setCacheValue(miriamData.getResource(), annotation); - } - return annotation; - } - - /** - * This method convert a hgnc symbol in miriam data into xml request. - * - * @param miriamData - * - {@link MiriamData} with {@link MiriamType#HGNC_SYMBOL} - * @return xml string that represent a request to RESTful service - */ - String dataToString(MiriamData miriamData) { - if (!MiriamType.HGNC_SYMBOL.equals(miriamData.getDataType())) { - throw new InvalidArgumentException( - "Only " + MiriamType.HGNC_SYMBOL.getCommonName() + " miriam registry is supported."); - } - String requestXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; - requestXml += "<request>\n"; - requestXml += " <species name=\"" + miriamData.getResource() + "\" type=\"PROTEIN\"/>\n"; - requestXml += "</request>\n"; - return requestXml; - } - - /** - * This method parse a response xml from annotation service into a map. A key in - * the map is a name of species and value is a annotation received from the - * service. - * - * @param xml - * - xml string to be parsed - * @return a map with information about annotations. A key in the map is a name - * of species and value is a annotation received from the service. - * @throws InvalidXmlSchemaException - * thrown when there is a problem with xml - */ - Map<String, String> getAnnotationsFromXml(String xml) throws InvalidXmlSchemaException { - Map<String, String> result = new HashMap<String, String>(); - // if xml is null or empty string then return empty map - if (xml == null) { - return result; - } - if (xml.isEmpty()) { - return result; - } - // there is a bug in annotation service that create incorrect xml, therefore - // we need to alter the xml - xml = correctInvalidXml(xml); - - Document doc = XmlParser.getXmlDocumentFromString(xml); - result = getAnnotationsFromXmlNode(doc); - return result; - - } - - /** - * Transforms xml retrieved from Venkata server into map of annotations. A key - * in the map is a name of species and value is a annotation received from the - * service. - * - * @param doc - * - xml node - * @return a map with information about annotations. A key in the map is a - * name of species and value is a annotation received from the - * service. - */ - private Map<String, String> getAnnotationsFromXmlNode(Node doc) { - Map<String, String> result = new HashMap<String, String>(); - NodeList root = doc.getChildNodes(); - Node responseNode = XmlParser.getNode("response", root); - // root node is called "response" - if (responseNode == null) { - throw new InvalidArgumentException("Invalid xml returned by annotation service. No response root node"); - } - NodeList list = responseNode.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - // all nodes in response are species - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("species")) { - String name = XmlParser.getNodeAttr("name", node).replaceAll("%0A", "\n"); - String annotation = XmlParser.getNodeValue(node); - if (annotation.contains("Symbol: " + name.split(" ")[0].toUpperCase())) { - result.put(name, annotation); - } else { - logger.warn("Problem with annotation for: " + name); - result.put(name, ""); - } - } else { - throw new InvalidArgumentException("Unknown node in xml response: " + node.getNodeName()); - } - } - } - return result; - } - - /** - * Corrects invalid xml retrieved from Venkata server. - * - * @param xml - * xml to correct - * @return corrected xml - */ - private String correctInvalidXml(String xml) { - int size = 0; - int size2 = 0; - do { - size = xml.length(); - xml = xml.replaceAll("<species name=\"[^\"]*\" type=\"[^\"]*\">(\\s)*<species", "<species"); - xml = xml.replaceAll("<species name=\"[^\"]*\" type=\"[^\"]*\">(\\s)*</response", "</response"); - size2 = xml.length(); - } while (size != size2); - return xml; - } - - @Override - public ExternalServiceStatus getServiceStatus() { - ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl()); - - GeneralCacheInterface cacheCopy = getCache(); - this.setCache(null); - - try { - String annotations = getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA")); - - status.setStatus(ExternalServiceStatusType.OK); - if (annotations == null) { - status.setStatus(ExternalServiceStatusType.DOWN); - } else if (!annotations.contains("ymbol")) { - status.setStatus(ExternalServiceStatusType.CHANGED); - } - } catch (Exception e) { - logger.error(status.getName() + " is down", e); - status.setStatus(ExternalServiceStatusType.DOWN); - } - this.setCache(cacheCopy); - return status; - } - - @Override - public boolean annotateElement(BioEntityProxy element, MiriamData identifier, AnnotatorData parameters) - throws AnnotatorException { - try { - String annotationString = getAnnotation(identifier); - if (annotationString != null) { - element.addMiriamData(rap.getMiriamData(annotationString)); - - String annotations = ""; - - String[] string = annotationString.split("\n"); - boolean remove = false; - for (String string2 : string) { - if (string2.startsWith("Symbol:")) { - remove = true; - } - if (remove) { - annotations += string2 + "\n"; - } - if (string2.startsWith("Synonyms:")) { - remove = false; - } - } - element.setDescription(rap.getDescription(annotations)); - element.setSymbol(rap.getSymbol(annotations)); - element.setSynonyms(rap.getSynonyms(annotations)); - element.setAbbreviation(rap.getAbbreviation(annotations)); - element.setFormula(rap.getFormula(annotations)); - element.setFullName(rap.getFullName(annotations)); - element.setFormerSymbols(rap.getFormerSymbols(annotations)); - - return true; - } - return false; - - } catch (IOException e) { - throw new AnnotatorException(e); - } - - } - - @Override - public String getCommonName() { - return "Biocompendium"; - } - - @Override - public String getUrl() { - return "http://biocompendium.embl.de/"; - } - - @Override - public List<AnnotatorInputParameter> getAvailableInputParameters() { - return Arrays.asList(new AnnotatorInputParameter(BioEntityField.NAME, MiriamType.HGNC_SYMBOL)); - } - - @Override - public List<AnnotatorOutputParameter> getAvailableOuputProperties() { - List<AnnotatorOutputParameter> result = new ArrayList<>(); - for (NoteField field : NoteField.values()) { - if (field.getMiriamType() != null) { - result.add(new AnnotatorOutputParameter(field.getMiriamType())); - } - } - result.add(new AnnotatorOutputParameter(BioEntityField.SYMBOL)); - result.add(new AnnotatorOutputParameter(BioEntityField.DESCRIPTION)); - result.add(new AnnotatorOutputParameter(BioEntityField.PREVIOUS_SYMBOLS)); - result.add(new AnnotatorOutputParameter(BioEntityField.SYNONYMS)); - - return result; - } - - @Override - public MiriamData getExampleValidAnnotation() { - //we don't provide example because this annotator is unstable - return null; - } -} diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AllAnnotatorTests.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AllAnnotatorTests.java index e68e714fdb6155fffa807aeeed8a1507c7d71657..5c3ae3a0b5bbe7f40b0f5f5163ec78add3c21c66 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AllAnnotatorTests.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AllAnnotatorTests.java @@ -8,7 +8,6 @@ import org.junit.runners.Suite.SuiteClasses; @SuiteClasses({ AnnotatorExceptionTest.class, AnnotatorExceptionTest.class, BrendaAnnotatorTest.class, - BiocompendiumAnnotatorTest.class, CazyAnnotatorTest.class, ChebiAnnotatorTest.class, ElementAnnotatorTest.class, diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/BiocompendiumAnnotatorTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/BiocompendiumAnnotatorTest.java deleted file mode 100644 index 490032e67e147414ac2d8aa94b63423c8a7409f3..0000000000000000000000000000000000000000 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/BiocompendiumAnnotatorTest.java +++ /dev/null @@ -1,363 +0,0 @@ -package lcsb.mapviewer.annotation.services.annotators; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.Map; - -import org.apache.logging.log4j.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; - -import lcsb.mapviewer.annotation.AnnotationTestFunctions; -import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; -import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCacheInterface; -import lcsb.mapviewer.annotation.cache.SourceNotAvailable; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamType; - -public class BiocompendiumAnnotatorTest extends AnnotationTestFunctions { - Logger logger = LogManager.getLogger(BiocompendiumAnnotatorTest.class); - - MiriamData camk4 = new MiriamData(MiriamType.HGNC_SYMBOL, "CAMK4"); - MiriamData slc25a27 = new MiriamData(MiriamType.HGNC_SYMBOL, "SLC25A27"); - MiriamData nsmf = new MiriamData(MiriamType.HGNC_SYMBOL, "NSMF"); - MiriamData mir449a = new MiriamData(MiriamType.HGNC_SYMBOL, "MIR449A"); - - @Autowired - private GeneralCacheInterface cache; - - @Autowired - private PermanentDatabaseLevelCacheInterface permanentDatabaseLevelCache; - - @Autowired - private BiocompendiumAnnotator restService; - - @Before - public void setUp() { - } - - @After - public void tearDown() throws Exception { - } - - @Test - @Ignore("Bug 32") - public void testGetAnnotationsForSpecies() throws Exception { - try { - String response = restService.getAnnotation(camk4); - assertNotNull(response); - assertTrue(response.contains("Symbol: CAMK4")); - - response = restService.getAnnotation(slc25a27); - assertNotNull(response); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() throws Exception { - try { - assertNotNull(restService.getCommonName()); - assertNotNull(restService.getUrl()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetAnnotationsForInvalidMiriam() throws Exception { - try { - restService.getAnnotation(new MiriamData()); - fail("Exception expected"); - - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXml() throws Exception { - BufferedReader reader; - try { - reader = new BufferedReader(new FileReader("testFiles/annotation/sampleResponse.xml")); - String line = null; - StringBuilder stringBuilder = new StringBuilder(); - String ls = System.getProperty("line.separator"); - - while ((line = reader.readLine()) != null) { - stringBuilder.append(line); - stringBuilder.append(ls); - } - reader.close(); - - Map<String, String> res = restService.getAnnotationsFromXml(stringBuilder.toString()); - - assertEquals(2, res.keySet().size()); - String response = res.get("CAMK4"); - assertNotNull(response); - assertTrue(response.contains("Symbol: CAMK4")); - - assertNotNull(res.get("SLC25A27")); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test(timeout = 10000) - @Ignore("Bug 32") - public void testGetAnnotationsForMiceSpecies() throws Exception { - ArrayList<String> names = new ArrayList<String>(); - - names.add("Fmo3"); - names.add("Nqo1"); - names.add("Abcc12"); - names.add("Mgst3"); - names.add("Txnrd1"); - names.add("Cbr3"); - names.add("Hspa1b"); - names.add("Prdx1"); - names.add("Ppard"); - names.add("Tgfb2"); - names.add("Fth1"); - names.add("Prdx6"); - names.add("Nr4a1"); - names.add("Tgfb1"); - names.add("Abcc4"); - names.add("Ager"); - names.add("Gsr"); - names.add("Sod3"); - names.add("Maff"); - names.add("Eif2ak3"); - names.add("Tgfa"); - names.add("Hbegf"); - names.add("Mafg"); - names.add("Adh7"); - names.add("Slc7a11"); - names.add("Epha3"); - names.add("Blvrb"); - // problematic one - // names.add("Me1"); - names.add("Csnk2a2"); - names.add("Gpx3"); - names.add("Mapk8"); - names.add("Gclm"); - names.add("Epha2"); - names.add("Bdnf"); - // problematic one - // names.add("ACC2"); - names.add("Ptgr1"); - names.add("Pdgfb"); - names.add("Mapk7"); - names.add("Cbr1"); - names.add("Hsp90aa1"); - names.add("Pgd"); - names.add("Sqstm1"); - names.add("Aldh9a1"); - names.add("Txn"); - names.add("Txnrd3"); - names.add("Srxn1"); - names.add("Gpx2"); - names.add("Npas4"); - names.add("Mapk1"); - names.add("Nrg1"); - names.add("Cbr"); - names.add("Hspa1a"); - names.add("Mgst2"); - names.add("Tgfbr2"); - names.add("Ephx1"); - names.add("Dnajb1"); - names.add("Abcc2"); - names.add("Gclc"); - names.add("Abcc5"); - names.add("Ggt1"); - names.add("Ftl"); - names.add("Egr1"); - names.add("Fgf13"); - // problematic one - // names.add("Hgf"); - // problematic one - // names.add("UbcH7"); - names.add("Abcc3"); - names.add("Nfe2l2"); - // problematic one - // names.add("Hsp70"); - names.add("Hsp90ab1"); - - try { - for (int i = 0; i < names.size(); i++) { - String geneName = names.get(i); - String annotation = restService.getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, geneName)); - assertNotNull("Problem with annotation of mouse gene: " + geneName, annotation); - assertTrue("Problem with annotation of mouse gene: " + geneName, !annotation.trim().equals("")); - } - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - @Ignore("Bug 451") - public void testGetAnnotationsForNSMF() throws Exception { - try { - String response = restService.getAnnotation(nsmf); - assertNotNull(response); - assertFalse(response.trim().equals("")); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - @Ignore("Bug 451") - public void testGetAnnotationsForMIR449A() throws Exception { - try { - String response = restService.getAnnotation(mir449a); - assertNotNull(response); - assertFalse(response.trim().equals("")); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test(timeout = 15000) - public void testCachableInterfaceInvalidate() throws Exception { - String query = "GLUD1"; - try { - String newRes = "hello"; - - cache.setCachedQuery(query, restService.getCacheType(), newRes); - String res = cache.getStringByQuery(query, restService.getCacheType()); - assertEquals(newRes, res); - cache.invalidateByQuery(query, restService.getCacheType()); - - permanentDatabaseLevelCache.waitToFinishTasks(); - - res = cache.getStringByQuery(query, restService.getCacheType()); - - assertNotNull(res); - - assertFalse("Value wasn't refreshed from db", newRes.equals(res)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testNameWithNewLine() throws Exception { - try { - String response = restService.getAnnotation(new MiriamData(MiriamType.HGNC_SYMBOL, "some\nname")); - assertNotNull(response); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testRefreshInvalidValue() throws Exception { - try { - restService.refreshCacheQuery(new Object()); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - assertTrue(e.getMessage().contains("Don't know what to do ")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testRefreshValueWhenProblemWithSource() throws Exception { - try { - BiocompendiumAnnotator annotatorUnderTest = Mockito.mock(BiocompendiumAnnotator.class, - Mockito.CALLS_REAL_METHODS); - when(annotatorUnderTest.getAnnotationsFromXml(anyString())).thenThrow(InvalidXmlSchemaException.class); - annotatorUnderTest.refreshCacheQuery(camk4.getResource()); - fail("Exception expected"); - } catch (SourceNotAvailable e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetInvalidAnnotations() throws Exception { - try { - restService.getAnnotation(new MiriamData(MiriamType.WIKIPEDIA, "world")); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testInvalidDataToStrubg() throws Exception { - try { - restService.dataToString(new MiriamData(MiriamType.WIKIPEDIA, "world")); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetAnnotationsFromInvaldXml() throws Exception { - try { - Map<String, String> map = restService.getAnnotationsFromXml(""); - assertEquals(0, map.size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetAnnotationsFromInvaldXml2() throws Exception { - try { - Map<String, String> map = restService.getAnnotationsFromXml(null); - assertEquals(0, map.size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/MultipleAnnotatorsTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/MultipleAnnotatorsTest.java index b5be651fd106a6efc1ccf907f77f5e2917bf5d54..56fbb37765ae5c052c3cf1c6903a1eabf6c3bb3e 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/MultipleAnnotatorsTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/MultipleAnnotatorsTest.java @@ -24,9 +24,6 @@ public class MultipleAnnotatorsTest extends AnnotationTestFunctions { @Autowired HgncAnnotator hgncAnnotator; - @Autowired - BiocompendiumAnnotator biocompendiumAnnotator; - @Before public void setUp() throws Exception { } diff --git a/persist/src/main/resources/db/migration/14.0.0~alpha.0/V14.0.0.20190516__remove_biocompendium.sql b/persist/src/main/resources/db/migration/14.0.0~alpha.0/V14.0.0.20190516__remove_biocompendium.sql new file mode 100644 index 0000000000000000000000000000000000000000..e5862917259cabf98b9344fbe21ab7b6e4670ea0 --- /dev/null +++ b/persist/src/main/resources/db/migration/14.0.0~alpha.0/V14.0.0.20190516__remove_biocompendium.sql @@ -0,0 +1,2 @@ +delete from cache_query_table where type in (select id from cache_type_table where class_name ='lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator'); +delete from cache_type_table where class_name ='lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator'; diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/cache/CacheTypeDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/cache/CacheTypeDaoTest.java index 87761eb39105d42f3a3e37f26b18cd679fa2019a..889686fc69e068dd0a57ce0ad98309e87f6028d3 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/cache/CacheTypeDaoTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/cache/CacheTypeDaoTest.java @@ -43,18 +43,6 @@ public class CacheTypeDaoTest extends PersistTestFunctions { } } - @Test - public void testBiocompendiumCacheData() throws Exception { - try { - CacheType cacheType = cacheTypeDao.getByClassName("lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator"); - assertNotNull(cacheType); - assertEquals(1,cacheType.getId()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test public void testChemblCacheData() throws Exception { try { diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/ExternalServicesService.java b/service/src/main/java/lcsb/mapviewer/services/impl/ExternalServicesService.java deleted file mode 100644 index 06cc9a768d1af2f4b37df8cc75d489211dd0c54a..0000000000000000000000000000000000000000 --- a/service/src/main/java/lcsb/mapviewer/services/impl/ExternalServicesService.java +++ /dev/null @@ -1,187 +0,0 @@ -package lcsb.mapviewer.services.impl; - -import java.util.ArrayList; -import java.util.List; - -import lcsb.mapviewer.annotation.services.ChEMBLParser; -import lcsb.mapviewer.annotation.services.DrugbankHTMLParser; -import lcsb.mapviewer.annotation.services.ExternalServiceStatus; -import lcsb.mapviewer.annotation.services.IExternalService; -import lcsb.mapviewer.annotation.services.MiriamConnector; -import lcsb.mapviewer.annotation.services.PubmedParser; -import lcsb.mapviewer.annotation.services.ChemicalParser; -import lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator; -import lcsb.mapviewer.annotation.services.annotators.ChebiAnnotator; -import lcsb.mapviewer.annotation.services.annotators.EnsemblAnnotator; -import lcsb.mapviewer.annotation.services.annotators.EntrezAnnotator; -import lcsb.mapviewer.annotation.services.annotators.GoAnnotator; -import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator; -import lcsb.mapviewer.annotation.services.annotators.UniprotAnnotator; -import lcsb.mapviewer.persist.DbUtils; -import lcsb.mapviewer.services.interfaces.IExternalServicesService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * Implementation of the service that retrieves information about services that - * access external resources (like chebi, chembl, etc.). - * - * @author Piotr Gawron - * - */ -@Service -public class ExternalServicesService implements IExternalServicesService { - - /** - * List of services that should be checked for status. - */ - private List<IExternalService> services = new ArrayList<IExternalService>(); - - /** - * Service accessing <a href="http://www.drugbank.ca/">drugbank</a>. - */ - private DrugbankHTMLParser drugbankHTMLParser; - - - /** - * Service accessing <a href="http://ctdbase.org/">ctd</a>. - */ - private ChemicalParser ctdParser; - - /** - * Service accessing <a - * href="https://www.ebi.ac.uk/chembl/compound/inspect/">chembl</a>. - */ - private ChEMBLParser chEMBLParser; - - /** - * Service accessing <a - * href="http://www.ebi.ac.uk/chebi/webServices.do">chebi</a>. - */ - private ChebiAnnotator chebiBackend; - - /** - * Service accessing <a - * href="http://europepmc.org/RestfulWebService">pubmed</a>. - */ - private PubmedParser pubmedParser; - - /** - * Service accessing <a href= "http://www.ebi.ac.uk/miriam/main/" >miriam - * registry</a>. - */ - private MiriamConnector miriamConnector; - - /** - * Service accessing <a href= "http://biocompendium.embl.de/" >internal - * annotating service</a>. - */ - private BiocompendiumAnnotator annotationRestService; - - /** - * Service accessing <a href= "http://www.uniprot.org/" >uniprot</a>. - */ - private UniprotAnnotator uniprotAnnotator; - - /** - * Service accessing Ensembl database. - */ - private EnsemblAnnotator ensemblAnnotator; - - /** - * Service accessing Entrez database. - */ - private EntrezAnnotator entrezAnnotator; - - /** - * Service accessing <a href= "http://www.ebi.ac.uk/QuickGO/" >Gene - * Ontology</a>. - */ - private GoAnnotator goBackend; - - /** - * Service accessing HGNC restfull API . - */ - private HgncAnnotator hgncBackend; - - /** - * Utils that help to manage the sessions in custom multithreaded - * implementation. - */ - private DbUtils dbUtils; - - @Autowired - public ExternalServicesService(DrugbankHTMLParser drugbankHTMLParser, - ChemicalParser ctdParser, - ChEMBLParser chEMBLParser, - ChebiAnnotator chebiBackend, - PubmedParser pubmedParser, - MiriamConnector miriamConnector, - BiocompendiumAnnotator annotationRestService, - UniprotAnnotator uniprotAnnotator, - EnsemblAnnotator ensemblAnnotator, - EntrezAnnotator entrezAnnotator, - GoAnnotator goBackend, - HgncAnnotator hgncBackend, - DbUtils dbUtils) { - this.drugbankHTMLParser = drugbankHTMLParser; - this.ctdParser = ctdParser; - this.chEMBLParser = chEMBLParser; - this.chebiBackend = chebiBackend; - this.pubmedParser = pubmedParser; - this.miriamConnector = miriamConnector; - this.annotationRestService = annotationRestService; - this.uniprotAnnotator = uniprotAnnotator; - this.ensemblAnnotator = ensemblAnnotator; - this.entrezAnnotator = entrezAnnotator; - this.goBackend = goBackend; - this.hgncBackend = hgncBackend; - this.dbUtils = dbUtils; - } - - @Override - public List<ExternalServiceStatus> getExternalServiceStatuses() { - List<ExternalServiceStatus> result = new ArrayList<ExternalServiceStatus>(); - for (IExternalService service : services) { - boolean sessionOpened = false; - if (!dbUtils.isCustomSessionForCurrentThread()) { - sessionOpened = true; - dbUtils.createSessionForCurrentThread(); - } - result.add(service.getServiceStatus()); - if (sessionOpened) { - dbUtils.closeSessionForCurrentThread(); - } - } - return result; - } - - @Override - public void registerService(IExternalService service) { - services.add(service); - - } - - @Override - public void registerDefaultServices() { - registerService(drugbankHTMLParser); - registerService(chEMBLParser); - registerService(chebiBackend); - registerService(pubmedParser); - registerService(miriamConnector); - registerService(annotationRestService); - registerService(ensemblAnnotator); - registerService(entrezAnnotator); - registerService(goBackend); - registerService(ctdParser); - registerService(hgncBackend); - registerService(uniprotAnnotator); - } - - @Override - public void clearServices() { - services.clear(); - - } -} diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/IExternalServicesService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/IExternalServicesService.java deleted file mode 100644 index 241fdc2422aadcf35674235c59bb7584ace569c8..0000000000000000000000000000000000000000 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/IExternalServicesService.java +++ /dev/null @@ -1,42 +0,0 @@ -package lcsb.mapviewer.services.interfaces; - -import java.util.List; - -import lcsb.mapviewer.annotation.services.ExternalServiceStatus; -import lcsb.mapviewer.annotation.services.IExternalService; - -/** - * Service that retrieves information about services that access external - * resources (like chebi, chembl, etc.). - * - * @author Piotr Gawron - * - */ -public interface IExternalServicesService { - - /** - * Returns status information about all services. - * - * @return status information about all services - */ - List<ExternalServiceStatus> getExternalServiceStatuses(); - - /** - * Registers service that access external resource. - * - * @param service - * service that access external resource - */ - void registerService(IExternalService service); - - /** - * Registers default list of services. - */ - void registerDefaultServices(); - - /** - * Clears list of known services. - */ - void clearServices(); - -} diff --git a/service/src/test/java/lcsb/mapviewer/services/ServiceTestFunctions.java b/service/src/test/java/lcsb/mapviewer/services/ServiceTestFunctions.java index ebc58a093a5a415e6c5082c8002581354261bc07..60fddfd73959e50564066e2707383f0e26f535c7 100644 --- a/service/src/test/java/lcsb/mapviewer/services/ServiceTestFunctions.java +++ b/service/src/test/java/lcsb/mapviewer/services/ServiceTestFunctions.java @@ -1,36 +1,14 @@ package lcsb.mapviewer.services; -import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.apache.logging.log4j.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.LogEvent; - import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; @@ -40,38 +18,22 @@ import org.springframework.test.annotation.Rollback; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import lcsb.mapviewer.annotation.services.ChEMBLParser; import lcsb.mapviewer.annotation.services.DrugbankHTMLParser; import lcsb.mapviewer.annotation.services.ModelAnnotator; -import lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator; - import lcsb.mapviewer.common.MinervaLoggerAppender; -import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.persist.DbUtils; -import lcsb.mapviewer.persist.dao.ConfigurationDao; import lcsb.mapviewer.persist.dao.ProjectDao; -import lcsb.mapviewer.persist.dao.cache.CacheQueryDao; -import lcsb.mapviewer.persist.dao.graphics.PolylineDao; import lcsb.mapviewer.persist.dao.map.CommentDao; import lcsb.mapviewer.persist.dao.map.ModelDao; -import lcsb.mapviewer.persist.dao.map.ReactionDao; -import lcsb.mapviewer.persist.dao.map.species.ElementDao; import lcsb.mapviewer.persist.dao.map.statistics.SearchHistoryDao; -import lcsb.mapviewer.persist.dao.user.PrivilegeDao; import lcsb.mapviewer.persist.dao.user.UserDao; import lcsb.mapviewer.services.interfaces.ICommentService; import lcsb.mapviewer.services.interfaces.IConfigurationService; -import lcsb.mapviewer.services.interfaces.IExternalServicesService; import lcsb.mapviewer.services.interfaces.ILayoutService; import lcsb.mapviewer.services.interfaces.IModelService; import lcsb.mapviewer.services.interfaces.IProjectService; @@ -87,18 +49,12 @@ import lcsb.mapviewer.services.search.drug.IDrugService; public abstract class ServiceTestFunctions { private Logger logger = LogManager.getLogger(ServiceTestFunctions.class); - @Autowired - protected ChEMBLParser chemblParser; - @Autowired protected DrugbankHTMLParser drugBankHTMLParser; @Autowired protected ModelAnnotator modelAnnotator; - @Autowired - protected BiocompendiumAnnotator restService; - public double EPSILON = 1e-6; @Autowired @@ -107,9 +63,6 @@ public abstract class ServiceTestFunctions { @Autowired protected IModelService modelService; - @Autowired - protected IExternalServicesService externalServicesService; - @Autowired protected ILayoutService layoutService; @@ -122,9 +75,6 @@ public abstract class ServiceTestFunctions { @Autowired protected IUserService userService; - @Autowired - protected ConfigurationDao configurationDao; - @Autowired protected ISearchService searchService; @@ -140,12 +90,6 @@ public abstract class ServiceTestFunctions { @Autowired protected ProjectDao projectDao; - @Autowired - protected CacheQueryDao cacheQueryDao; - - @Autowired - protected PolylineDao polylineDao; - @Autowired protected ModelDao modelDao; @@ -155,24 +99,12 @@ public abstract class ServiceTestFunctions { @Autowired protected UserDao userDao; - @Autowired - protected PrivilegeDao privilegeDao; - @Autowired protected CommentDao commentDao; @Autowired protected DbUtils dbUtils; - @Autowired - protected ReactionDao reactionDao; - - @Autowired - protected ElementDao aliasDao; - - private User user; - protected User user2 = null; - private MinervaLoggerAppender appender; @Before @@ -199,78 +131,12 @@ public abstract class ServiceTestFunctions { return appender.getInfos(); } - protected String readFile(String file) throws IOException { - StringBuilder stringBuilder = new StringBuilder(); - BufferedReader reader = new BufferedReader(new FileReader(file)); - try { - String line = null; - String ls = System.getProperty("line.separator"); - - while ((line = reader.readLine()) != null) { - stringBuilder.append(line); - stringBuilder.append(ls); - } - } finally { - reader.close(); - } - - return stringBuilder.toString(); - } - - protected Node getNodeFromXmlString(String text) throws InvalidXmlSchemaException { - InputSource is = new InputSource(); - is.setCharacterStream(new StringReader(text)); - return getXmlDocumentFromInputSource(is).getChildNodes().item(0); - } - - protected Document getXmlDocumentFromFile(String fileName) throws InvalidXmlSchemaException, IOException { - File file = new File(fileName); - InputStream inputStream = new FileInputStream(file); - Reader reader = null; - try { - reader = new InputStreamReader(inputStream, "UTF-8"); - InputSource is = new InputSource(reader); - - Document result = getXmlDocumentFromInputSource(is); - inputStream.close(); - return result; - } catch (UnsupportedEncodingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - protected Document getXmlDocumentFromInputSource(InputSource stream) throws InvalidXmlSchemaException { - DocumentBuilder db; - try { - db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - } catch (ParserConfigurationException e) { - throw new InvalidXmlSchemaException("Problem with xml parser"); - } - Document doc = null; - try { - doc = db.parse(stream); - } catch (SAXException e) { - logger.error(e); - } catch (IOException e) { - logger.error(e); - } - return doc; - } - - /** - * This method remove model with all connections from db (used only when the db - * must be handled manually) - * - * @param id - */ - protected void removeModelById(int id) { - modelDao.delete(modelDao.getById(id)); + protected User createUser() { + return createUser("john.doe"); } - protected User createUser() { - user = userDao.getUserByLogin("john.doe"); + protected User createUser(String login) { + User user = userDao.getUserByLogin(login); if (user != null) { logger.debug("remove user"); userDao.delete(user); @@ -280,26 +146,12 @@ public abstract class ServiceTestFunctions { user.setName("John"); user.setSurname("Doe"); user.setEmail("john.doe@uni.lu"); - user.setLogin("john.doe"); + user.setLogin(login); user.setCryptedPassword(passwordEncoder.encode("passwd")); userDao.add(user); return user; } - protected void createUser2() { - user2 = userDao.getUserByLogin("john.doe.bis"); - if (user2 != null) { - userDao.delete(user2); - } - user2 = new User(); - user2.setName("John"); - user2.setSurname("Doe BIS"); - user2.setEmail("john.doe@uni.lux"); - user2.setLogin("john.doe.bis"); - user2.setCryptedPassword(passwordEncoder.encode("passwd")); - userDao.add(user2); - } - private static Map<String, Model> models = new HashMap<String, Model>(); protected Model getModelForFile(String fileName, boolean fromCache) throws Exception { @@ -318,80 +170,6 @@ public abstract class ServiceTestFunctions { return result; } - protected String createTmpFileName() { - try { - File f = File.createTempFile("prefix", ".txt"); - String filename = f.getName(); - f.delete(); - return filename; - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - protected String nodeToString(Node node) { - return nodeToString(node, false); - } - - protected String nodeToString(Node node, boolean includeHeadNode) { - if (node == null) - return null; - StringWriter sw = new StringWriter(); - try { - Transformer t = TransformerFactory.newInstance().newTransformer(); - t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - t.setOutputProperty(OutputKeys.INDENT, "yes"); - t.setOutputProperty(OutputKeys.METHOD, "xml"); - - NodeList list = node.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node element = list.item(i); - t.transform(new DOMSource(element), new StreamResult(sw)); - } - } catch (TransformerException te) { - logger.debug("nodeToString Transformer Exception"); - } - if (includeHeadNode) { - return "<" + node.getNodeName() + ">" + sw.toString() + "</" + node.getNodeName() + ">"; - } - return sw.toString(); - } - - protected boolean equalFiles(String fileA, String fileB) throws IOException { - int BLOCK_SIZE = 65536; - FileInputStream inputStreamA = new FileInputStream(fileA); - FileInputStream inputStreamB = new FileInputStream(fileB); - // vary BLOCK_SIZE to suit yourself. - // it should probably a factor or multiple of the size of a disk - // sector/cluster. - // Note that your max heap size may need to be adjused - // if you have a very big block size or lots of these comparators. - - // assume inputStreamA and inputStreamB are streams from your two files. - byte[] streamABlock = new byte[BLOCK_SIZE]; - byte[] streamBBlock = new byte[BLOCK_SIZE]; - boolean match = true; - int bytesReadA = 0; - int bytesReadB = 0; - do { - bytesReadA = inputStreamA.read(streamABlock); - bytesReadB = inputStreamB.read(streamBBlock); - match = ((bytesReadA == bytesReadB) && Arrays.equals(streamABlock, streamBBlock)); - } while (match && (bytesReadA > -1)); - inputStreamA.close(); - inputStreamB.close(); - return match; - } - - public PrivilegeDao getPrivilegeDao() { - return privilegeDao; - } - - public void setPrivilegeDao(PrivilegeDao privilegeDao) { - this.privilegeDao = privilegeDao; - } - public File createTempDirectory() throws IOException { final File temp; @@ -407,18 +185,4 @@ public abstract class ServiceTestFunctions { return (temp); } - - protected String getWebpage(String accessUrl) throws IOException { - String inputLine; - StringBuilder tmp = new StringBuilder(); - URL url = new URL(accessUrl); - URLConnection urlConn = url.openConnection(); - BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); - - while ((inputLine = in.readLine()) != null) { - tmp.append(inputLine); - } - in.close(); - return tmp.toString(); - } } diff --git a/service/src/test/java/lcsb/mapviewer/services/impl/AllImplServiceTests.java b/service/src/test/java/lcsb/mapviewer/services/impl/AllImplServiceTests.java index cc2d3256ee8978e95d67e8393838719d1f42c26e..8f0f6c8e27e20a9e51e87b40406efc898142a125 100644 --- a/service/src/test/java/lcsb/mapviewer/services/impl/AllImplServiceTests.java +++ b/service/src/test/java/lcsb/mapviewer/services/impl/AllImplServiceTests.java @@ -7,7 +7,6 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ CommentServiceTest.class, ConfigurationServiceTest.class, - ExternalServicesServiceTest.class, LayoutServiceTest.class, LdapServiceTest.class, Md5PasswordEncoderTest.class, diff --git a/service/src/test/java/lcsb/mapviewer/services/impl/ExternalServicesServiceTest.java b/service/src/test/java/lcsb/mapviewer/services/impl/ExternalServicesServiceTest.java deleted file mode 100644 index 8b1db0dd70a9f843ffce67bf3e115f37b694ddb8..0000000000000000000000000000000000000000 --- a/service/src/test/java/lcsb/mapviewer/services/impl/ExternalServicesServiceTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package lcsb.mapviewer.services.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import lcsb.mapviewer.annotation.services.ExternalServiceStatus; -import lcsb.mapviewer.annotation.services.ExternalServiceStatusType; -import lcsb.mapviewer.services.ServiceTestFunctions; - -public class ExternalServicesServiceTest extends ServiceTestFunctions { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test(timeout = 60000) - @Ignore("Bug 451") - public void testDefaultServices() throws Exception { - try { - externalServicesService.clearServices(); - externalServicesService.registerDefaultServices(); - List<ExternalServiceStatus> statuses = externalServicesService.getExternalServiceStatuses(); - assertNotNull(statuses); - assertTrue(statuses.size() > 0); - - for (ExternalServiceStatus externalServiceStatus : statuses) { - assertEquals(externalServiceStatus.getName() + " is down", ExternalServiceStatusType.OK, externalServiceStatus.getStatus()); - } - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testRegister() throws Exception { - try { - externalServicesService.clearServices(); - externalServicesService.registerService(new OkServiceMock()); - externalServicesService.registerService(new FailServiceMock()); - - List<ExternalServiceStatus> statuses = externalServicesService.getExternalServiceStatuses(); - assertNotNull(statuses); - assertEquals(2, statuses.size()); - - assertEquals(ExternalServiceStatusType.OK, statuses.get(0).getStatus()); - assertEquals(ExternalServiceStatusType.DOWN, statuses.get(1).getStatus()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} diff --git a/service/src/test/java/lcsb/mapviewer/services/impl/LayoutServiceTest.java b/service/src/test/java/lcsb/mapviewer/services/impl/LayoutServiceTest.java index 2f9b320135d077d196f1419e57dac0f92f2a411c..728ba963c24b18d274a2f4f97f965988d1a8d772 100644 --- a/service/src/test/java/lcsb/mapviewer/services/impl/LayoutServiceTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/impl/LayoutServiceTest.java @@ -71,7 +71,7 @@ public class LayoutServiceTest extends ServiceTestFunctions { String adminToken; String token; - User user; + private User user, user2; ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN, Color.BLUE); @@ -107,7 +107,7 @@ public class LayoutServiceTest extends ServiceTestFunctions { projectService.addProject(project); user = createUser(); - createUser2(); + user2 = createUser("john.doe.bis"); originalSender = layoutService.getEmailSender(); layoutService.setEmailSender(Mockito.mock(EmailSender.class));