diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/PubmedParser.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/PubmedParser.java index 15bacd4c643e0d7321abcf12b01f2d0013097498..32a11b6dfda8deff66377492939c558927d2219d 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/PubmedParser.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/PubmedParser.java @@ -23,7 +23,6 @@ import lcsb.mapviewer.annotation.cache.SourceNotAvailable; import lcsb.mapviewer.annotation.cache.WebPageDownloader; import lcsb.mapviewer.annotation.cache.XmlSerializer; import lcsb.mapviewer.annotation.data.Article; -import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamType; @@ -100,8 +99,8 @@ public class PubmedParser extends CachableInterface implements IExternalService } /** - * Constructor. Initializes structures used for transforming - * {@link Article} from/to xml. + * Constructor. Initializes structures used for transforming {@link Article} + * from/to xml. */ @Autowired public PubmedParser(MiriamConnector miriamConnector) { @@ -209,7 +208,7 @@ public class PubmedParser extends CachableInterface implements IExternalService } public Article getPubmedArticleById(String id) throws PubmedSearchException { - if (id==null) { + if (id == null) { return null; } return getPubmedArticleById(Integer.valueOf(id.trim())); diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/ChEMBLParserTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/ChEMBLParserTest.java index c4c0151c50e86e47c3ad378437224eb04c4d0c0a..0b4f0d4dd5f38e0d2dae09e2d16cd72dcf0f2e24 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/ChEMBLParserTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/ChEMBLParserTest.java @@ -24,7 +24,6 @@ import org.w3c.dom.Node; import lcsb.mapviewer.annotation.AnnotationTestFunctions; import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; -import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCache; import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCacheInterface; import lcsb.mapviewer.annotation.cache.SourceNotAvailable; import lcsb.mapviewer.annotation.cache.WebPageDownloader; diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/ChemicalParserTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/ChemicalParserTest.java index 0ef26253308c893606da6664106e753b9931e215..c718c9afebb7f805e564027ba56044e20b3d284c 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/ChemicalParserTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/ChemicalParserTest.java @@ -5,9 +5,9 @@ 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.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.when; import java.io.IOException; @@ -23,8 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.annotation.AnnotationTestFunctions; import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; -import lcsb.mapviewer.annotation.cache.GeneralCacheWithExclusion; -import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCache; import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCacheInterface; import lcsb.mapviewer.annotation.cache.SourceNotAvailable; import lcsb.mapviewer.annotation.cache.WebPageDownloader; @@ -82,7 +80,8 @@ public class ChemicalParserTest extends AnnotationTestFunctions { // skip first call to cache, so we will have to at least parse the data chemicalParser.setCache(null); WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))).thenThrow(new IOException()); + when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))) + .thenThrow(new IOException()); chemicalParser.setWebPageDownloader(mockDownloader); // Parkinson disease chemicalParser.getChemicalsForDisease(parkinsonDiseaseId); @@ -447,7 +446,8 @@ public class ChemicalParserTest extends AnnotationTestFunctions { WebPageDownloader downloader = chemicalParser.getWebPageDownloader(); try { WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))).thenThrow(new IOException()); + when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))) + .thenThrow(new IOException()); chemicalParser.setWebPageDownloader(mockDownloader); assertEquals(ExternalServiceStatusType.DOWN, chemicalParser.getServiceStatus().getStatus()); } catch (Exception e) { @@ -544,7 +544,8 @@ public class ChemicalParserTest extends AnnotationTestFunctions { chemicalParser.setCache(null); WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))).thenThrow(new IOException()); + when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))) + .thenThrow(new IOException()); chemicalParser.setWebPageDownloader(mockDownloader); try { chemicalParser.getChemicals(parkinsonDiseaseId, idsList); diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParserTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParserTest.java index b230cba338260aaa0e2cc7466825e0da2230640c..a9b5ee9131e7d30c79218b57138e2336aadf7a89 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParserTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParserTest.java @@ -6,8 +6,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.when; import java.io.IOException; @@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.annotation.AnnotationTestFunctions; import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; -import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCache; import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCacheInterface; import lcsb.mapviewer.annotation.cache.SourceNotAvailable; import lcsb.mapviewer.annotation.cache.WebPageDownloader; @@ -549,7 +548,8 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions { WebPageDownloader downloader = drugBankHTMLParser.getWebPageDownloader(); try { WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))).thenThrow(new IOException()); + when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))) + .thenThrow(new IOException()); drugBankHTMLParser.setWebPageDownloader(mockDownloader); drugBankHTMLParser.refreshCacheQuery("http://google.pl/"); fail("Exception expected"); @@ -568,7 +568,8 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions { GeneralCacheInterface cache = drugBankHTMLParser.getCache(); try { WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))).thenThrow(new IOException()); + when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))) + .thenThrow(new IOException()); drugBankHTMLParser.setWebPageDownloader(mockDownloader); drugBankHTMLParser.setCache(null); @@ -661,7 +662,8 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions { WebPageDownloader downloader = drugBankHTMLParser.getWebPageDownloader(); try { WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))).thenThrow(new IOException()); + when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class))) + .thenThrow(new IOException()); drugBankHTMLParser.setWebPageDownloader(mockDownloader); assertEquals(ExternalServiceStatusType.DOWN, drugBankHTMLParser.getServiceStatus().getStatus()); } catch (Exception e) { diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/MiRNAParserTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/MiRNAParserTest.java index ac1e12c007a1b3cdcc779573c752409b8ce0e228..8132a0fd81c9c0322921e36f3b82e1cf4f84950e 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/MiRNAParserTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/MiRNAParserTest.java @@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.annotation.AnnotationTestFunctions; import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; -import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCache; import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCacheInterface; import lcsb.mapviewer.annotation.cache.SourceNotAvailable; import lcsb.mapviewer.annotation.data.MiRNA; diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/ModelAnnotatorTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/ModelAnnotatorTest.java index fe7b5e52e484c45266a6bd501b1dc6e1b383c705..7918cb4ca6c1316afebd99f7f1369b4154cc21d1 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/ModelAnnotatorTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/ModelAnnotatorTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import java.util.ArrayList; import java.util.Collection; @@ -25,7 +25,6 @@ import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.annotation.AnnotationTestFunctions; -import lcsb.mapviewer.annotation.services.annotators.AnnotationParameters; import lcsb.mapviewer.annotation.services.annotators.AnnotatorException; import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator; import lcsb.mapviewer.annotation.services.annotators.ReconAnnotator; diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/PubmedParserTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/PubmedParserTest.java index b8c100cc028f3af61bb4600a1f7fde2307200827..5d2f97a890d5fae1973e481717c6c1f0bc1a2946 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/PubmedParserTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/PubmedParserTest.java @@ -6,8 +6,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.when; import java.io.IOException; @@ -18,7 +18,6 @@ import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/genome/UcscReferenceGenomeConnectorTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/genome/UcscReferenceGenomeConnectorTest.java index ef6138383b8ff2e866f5e8cdfe6551343a8f3574..3566680735812abfa8b0198678ab69dedba47d4f 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/genome/UcscReferenceGenomeConnectorTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/genome/UcscReferenceGenomeConnectorTest.java @@ -5,10 +5,10 @@ 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.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.when; import java.io.IOException; @@ -26,7 +26,6 @@ import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; diff --git a/commons/src/test/java/lcsb/mapviewer/common/XmlParserTest.java b/commons/src/test/java/lcsb/mapviewer/common/XmlParserTest.java index a796375a3ca3fd7a4e5b880dcf9e1da55f74def2..99070dc3729a839ec2afa04f9542545afca6d15f 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/XmlParserTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/XmlParserTest.java @@ -11,14 +11,9 @@ import java.awt.Color; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.util.List; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - import org.apache.log4j.Logger; import org.apache.xerces.dom.DocumentImpl; import org.apache.xerces.dom.ElementImpl; @@ -32,391 +27,395 @@ import org.w3c.dom.Node; import org.xml.sax.InputSource; import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; public class XmlParserTest { - Logger logger = Logger.getLogger(XmlParserTest.class); - - XmlParser parser = new XmlParser(); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testColorParsing() { - try { - String strColor = "ffcbcd09"; - - Color c = parser.stringToColor(strColor); - String resultString = parser.colorToString(c); - assertTrue("Different string representation: " + strColor + " - " + resultString, strColor.equalsIgnoreCase(resultString)); - - Color c2 = parser.stringToColor(resultString); - - assertEquals(c.getRed(), c2.getRed()); - assertEquals(c.getGreen(), c2.getGreen()); - assertEquals(c.getBlue(), c2.getBlue()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidColorParsing() { - try { - String strColor = "hello world"; - - parser.stringToColor(strColor); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testColorParsingWithAlpha() { - try { - String strColor = "fecbcd09"; - - Color c = parser.stringToColor(strColor); - String resultString = parser.colorToString(c); - assertTrue("Different string representation: " + strColor + " - " + resultString, strColor.equalsIgnoreCase(resultString)); - - Color c2 = parser.stringToColor(resultString); - - assertEquals(c.getRed(), c2.getRed()); - assertEquals(c.getGreen(), c2.getGreen()); - assertEquals(c.getBlue(), c2.getBlue()); - assertEquals(c.getAlpha(), c2.getAlpha()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetXmlDocumentFromString() throws Exception { - try { - Document validDoc = parser.getXmlDocumentFromString("<node>test</node>"); - assertNotNull(validDoc); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testNodeToString() throws Exception { - try { - String xml = "<test_node>test_x</test_node>"; - Document validDoc = parser.getXmlDocumentFromString(xml); - String str = parser.nodeToString(validDoc); - assertEquals(xml.trim(), str.trim()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testEmptyNodeToString() throws Exception { - try { - String str = parser.nodeToString(null); - assertNull(str); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testNodeToStringWithHeader() throws Exception { - try { - String xml = "<test_node>test_x</test_node>"; - Document validDoc = parser.getXmlDocumentFromString(xml); - String str = parser.nodeToString(validDoc, true); - assertTrue(str.contains(xml)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidNodeToString() throws Exception { - try { - final DocumentImpl xmlDoc = new DocumentImpl(); - - Element root = xmlDoc.createElement("booking"); - - class Tmp extends ElementImpl { - /** - * - */ - private static final long serialVersionUID = 1L; - - public Tmp() { - this.ownerDocument = xmlDoc; - } - - @Override - public NamedNodeMap getAttributes() { - return null; - } - - } - ; - Element el = new Tmp(); - root.appendChild(el); - assertNotNull(parser.nodeToString(root, true)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetXmlDocumentFromInvalidString() throws Exception { - try { - parser.getXmlDocumentFromString("<node>test<node>"); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetXmlDocumentFromInvalidInputStream() throws Exception { - try { - parser.getXmlDocumentFromInputSource(new InputSource(), true); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testEscapeXml() throws Exception { - try { - String str = parser.escapeXml("<xml>node</xml>"); - assertFalse(str.contains("<")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testEscapeNullXml() throws Exception { - try { - String str = parser.escapeXml(null); - assertNull(str); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testFileToString() throws Exception { - try { - String str = parser.fileToString("testFiles/test.txt"); - assertTrue(str.contains("test")); - assertTrue(str.contains("file")); - assertTrue(str.contains("with some content")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testInputStreamToString() throws Exception { - try { - InputStream stream = new ByteArrayInputStream("stream string".getBytes(StandardCharsets.UTF_8)); - String str = parser.inputStreamToString(stream); - assertEquals("stream string", str); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNodeValue() throws Exception { - try { - Document document = parser.getXmlDocumentFromString("<node>content</node>"); - Node node = parser.getNode("node", document); - String str = parser.getNodeValue(node); - assertEquals("content", str); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNodeValue2() throws Exception { - try { - String str = parser.getNodeValue(null); - assertEquals("", str); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNodeValue3() throws Exception { - try { - Document document = parser.getXmlDocumentFromString("<node></node>"); - Node node = parser.getNode("node", document); - String str = parser.getNodeValue(node); - assertEquals("", str); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNodeValue4() throws Exception { - try { - Document document = parser.getXmlDocumentFromString("<node><subnode/></node>"); - Node node = parser.getNode("node", document); - String str = parser.getNodeValue(node); - assertEquals("", str); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testInputStreamToStringThrowsException() throws Exception { - try { - parser.inputStreamToString(new InputStream() { - @Override - public int read() throws IOException { - throw new IOException(); - } - }); - fail("Exception expected"); - } catch (IOException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testFileToStringThrowsException() throws Exception { - try { - parser.fileToString("testFiles/unknown file.txt"); - fail("Exception expected"); - } catch (IOException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNodeAttr() throws Exception { - try { - Document document = parser.getXmlDocumentFromString("<node attr=\"val\">content</node>"); - Node node = parser.getNode("node", document); - String str = parser.getNodeAttr("attr", node); - assertEquals("val", str); - str = parser.getNodeAttr("attr2", node); - assertEquals("", str); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNodes() throws Exception { - try { - Document document = parser.getXmlDocumentFromString("<node><subnode>content1</subnode><subnode>content2</subnode><other/></node>"); - Node node = parser.getNode("node", document); - List<Node> nodes = parser.getNodes("subnode", node.getChildNodes()); - assertEquals(2, nodes.size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNode() throws Exception { - try { - Document document = parser.getXmlDocumentFromString("<node><subnode>content1</subnode><subnode>content2</subnode><other/></node>"); - Node node = parser.getNode("node", document); - Node child = parser.getNode("other", node.getChildNodes()); - assertNotNull(child); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNode2() throws Exception { - try { - Document document = parser.getXmlDocumentFromString("<node attr=\"x\"><subnode>content1</subnode><subnode>content2</subnode><other/></node>"); - Node node = parser.getNode("node", document); - Node child = parser.getNode("other2", node.getChildNodes()); - assertNull(child); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetNode3() throws Exception { - try { - Document document = parser.getXmlDocumentFromString("<node attr=\"x\">xxx</node>"); - Node node = parser.getNode("node", document); - Node child = parser.getNode("other2", node.getChildNodes()); - assertNull(child); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Logger logger = Logger.getLogger(XmlParserTest.class); + + XmlParser parser = new XmlParser(); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testColorParsing() { + try { + String strColor = "ffcbcd09"; + + Color c = parser.stringToColor(strColor); + String resultString = parser.colorToString(c); + assertTrue("Different string representation: " + strColor + " - " + resultString, + strColor.equalsIgnoreCase(resultString)); + + Color c2 = parser.stringToColor(resultString); + + assertEquals(c.getRed(), c2.getRed()); + assertEquals(c.getGreen(), c2.getGreen()); + assertEquals(c.getBlue(), c2.getBlue()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidColorParsing() { + try { + String strColor = "hello world"; + + parser.stringToColor(strColor); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testColorParsingWithAlpha() { + try { + String strColor = "fecbcd09"; + + Color c = parser.stringToColor(strColor); + String resultString = parser.colorToString(c); + assertTrue("Different string representation: " + strColor + " - " + resultString, + strColor.equalsIgnoreCase(resultString)); + + Color c2 = parser.stringToColor(resultString); + + assertEquals(c.getRed(), c2.getRed()); + assertEquals(c.getGreen(), c2.getGreen()); + assertEquals(c.getBlue(), c2.getBlue()); + assertEquals(c.getAlpha(), c2.getAlpha()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetXmlDocumentFromString() throws Exception { + try { + Document validDoc = parser.getXmlDocumentFromString("<node>test</node>"); + assertNotNull(validDoc); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testNodeToString() throws Exception { + try { + String xml = "<test_node>test_x</test_node>"; + Document validDoc = parser.getXmlDocumentFromString(xml); + String str = parser.nodeToString(validDoc); + assertEquals(xml.trim(), str.trim()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testEmptyNodeToString() throws Exception { + try { + String str = parser.nodeToString(null); + assertNull(str); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testNodeToStringWithHeader() throws Exception { + try { + String xml = "<test_node>test_x</test_node>"; + Document validDoc = parser.getXmlDocumentFromString(xml); + String str = parser.nodeToString(validDoc, true); + assertTrue(str.contains(xml)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidNodeToString() throws Exception { + try { + final DocumentImpl xmlDoc = new DocumentImpl(); + + Element root = xmlDoc.createElement("booking"); + + class Tmp extends ElementImpl { + /** + * + */ + private static final long serialVersionUID = 1L; + + public Tmp() { + this.ownerDocument = xmlDoc; + } + + @Override + public NamedNodeMap getAttributes() { + return null; + } + + } + ; + Element el = new Tmp(); + root.appendChild(el); + assertNotNull(parser.nodeToString(root, true)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetXmlDocumentFromInvalidString() throws Exception { + try { + parser.getXmlDocumentFromString("<node>test<node>"); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetXmlDocumentFromInvalidInputStream() throws Exception { + try { + parser.getXmlDocumentFromInputSource(new InputSource(), true); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testEscapeXml() throws Exception { + try { + String str = parser.escapeXml("<xml>node</xml>"); + assertFalse(str.contains("<")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testEscapeNullXml() throws Exception { + try { + String str = parser.escapeXml(null); + assertNull(str); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testFileToString() throws Exception { + try { + String str = parser.fileToString("testFiles/test.txt"); + assertTrue(str.contains("test")); + assertTrue(str.contains("file")); + assertTrue(str.contains("with some content")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testInputStreamToString() throws Exception { + try { + InputStream stream = new ByteArrayInputStream("stream string".getBytes(StandardCharsets.UTF_8)); + String str = parser.inputStreamToString(stream); + assertEquals("stream string", str); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNodeValue() throws Exception { + try { + Document document = parser.getXmlDocumentFromString("<node>content</node>"); + Node node = parser.getNode("node", document); + String str = parser.getNodeValue(node); + assertEquals("content", str); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNodeValue2() throws Exception { + try { + String str = parser.getNodeValue(null); + assertEquals("", str); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNodeValue3() throws Exception { + try { + Document document = parser.getXmlDocumentFromString("<node></node>"); + Node node = parser.getNode("node", document); + String str = parser.getNodeValue(node); + assertEquals("", str); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNodeValue4() throws Exception { + try { + Document document = parser.getXmlDocumentFromString("<node><subnode/></node>"); + Node node = parser.getNode("node", document); + String str = parser.getNodeValue(node); + assertEquals("", str); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testInputStreamToStringThrowsException() throws Exception { + try { + parser.inputStreamToString(new InputStream() { + @Override + public int read() throws IOException { + throw new IOException(); + } + }); + fail("Exception expected"); + } catch (IOException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testFileToStringThrowsException() throws Exception { + try { + parser.fileToString("testFiles/unknown file.txt"); + fail("Exception expected"); + } catch (IOException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNodeAttr() throws Exception { + try { + Document document = parser.getXmlDocumentFromString("<node attr=\"val\">content</node>"); + Node node = parser.getNode("node", document); + String str = parser.getNodeAttr("attr", node); + assertEquals("val", str); + str = parser.getNodeAttr("attr2", node); + assertEquals("", str); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNodes() throws Exception { + try { + Document document = parser + .getXmlDocumentFromString("<node><subnode>content1</subnode><subnode>content2</subnode><other/></node>"); + Node node = parser.getNode("node", document); + List<Node> nodes = parser.getNodes("subnode", node.getChildNodes()); + assertEquals(2, nodes.size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNode() throws Exception { + try { + Document document = parser + .getXmlDocumentFromString("<node><subnode>content1</subnode><subnode>content2</subnode><other/></node>"); + Node node = parser.getNode("node", document); + Node child = parser.getNode("other", node.getChildNodes()); + assertNotNull(child); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNode2() throws Exception { + try { + Document document = parser.getXmlDocumentFromString( + "<node attr=\"x\"><subnode>content1</subnode><subnode>content2</subnode><other/></node>"); + Node node = parser.getNode("node", document); + Node child = parser.getNode("other2", node.getChildNodes()); + assertNull(child); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetNode3() throws Exception { + try { + Document document = parser.getXmlDocumentFromString("<node attr=\"x\">xxx</node>"); + Node node = parser.getNode("node", document); + Node child = parser.getNode("other2", node.getChildNodes()); + assertNull(child); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java index 0928447874812b444a8054ae552c8d62b8435fcd..d529314f4a9be7f6e57c4f776532784c294cea3b 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java @@ -1,10 +1,10 @@ package lcsb.mapviewer.converter.graphics.bioEntity.reaction; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyDouble; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyDouble; -import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -41,7 +41,6 @@ import lcsb.mapviewer.model.map.reaction.Product; import lcsb.mapviewer.model.map.reaction.Reactant; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.SplitOperator; -import lcsb.mapviewer.model.map.reaction.type.KnownTransitionOmittedReaction; import lcsb.mapviewer.model.map.reaction.type.UnknownTransitionReaction; import lcsb.mapviewer.model.map.species.GenericProtein; diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java index f0fddefe0a1bb12c06b36b5e3bb7d289fdec430f..b6d037fd550412790b999f9687c61c054610723e 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java @@ -19,7 +19,6 @@ import org.sbml.jsbml.ext.SBasePlugin; import org.sbml.jsbml.ext.layout.Layout; import org.sbml.jsbml.ext.layout.LayoutModelPlugin; import org.sbml.jsbml.ext.multi.MultiModelPlugin; -import org.sbml.jsbml.ext.render.LocalStyle; import lcsb.mapviewer.commands.CommandExecutionException; import lcsb.mapviewer.commands.layout.ApplySimpleLayoutModelCommand; diff --git a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/GenericSbmlToXmlParserTest.java b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/GenericSbmlToXmlParserTest.java index 327a0049438001361e51d172762d9351aa0a0084..e2ddd817d450483be08464bca6f5bc854ffe71b6 100644 --- a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/GenericSbmlToXmlParserTest.java +++ b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/GenericSbmlToXmlParserTest.java @@ -19,7 +19,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import lcsb.mapviewer.converter.ConverterParams; -import lcsb.mapviewer.converter.IConverter; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelComparator; diff --git a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/SbmlParserTest.java b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/SbmlParserTest.java index eec9afd5e7ce0630275fc1a9f336767476dca191..1e2ecd69f2fe52546509453e9edc7ed2e6dbebf2 100644 --- a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/SbmlParserTest.java +++ b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/SbmlParserTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.awt.Color; import java.io.FileNotFoundException; import java.util.List; @@ -15,7 +14,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.EventStorageLoggerAppender; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.InvalidInputDataExecption; @@ -199,7 +197,8 @@ public class SbmlParserTest { @Test public void testParseConflictingTypesFromMulti() throws Exception { - Model model = parser.createModel(new ConverterParams().filename("testFiles/multi_features/conflicting_species_type.xml")); + Model model = parser + .createModel(new ConverterParams().filename("testFiles/multi_features/conflicting_species_type.xml")); assertTrue(model.getElementByElementId("species_0") instanceof GenericProtein); assertEquals(1, getWarnings().size()); } diff --git a/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java b/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java index 175bbfd01674a95e95ee820f88dd980a1164fbce..639b864a4eaf6304406eb413437f44f96a29a595 100644 --- a/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java +++ b/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java @@ -5,11 +5,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Modifier; -import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/CopyCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/CopyCommand.java index c310515b20c0c9f5f29dd0fc36910d701a452a8a..6afd588a365b16021b2805ecd88fbac0a7399dfe 100644 --- a/model-command/src/main/java/lcsb/mapviewer/commands/CopyCommand.java +++ b/model-command/src/main/java/lcsb/mapviewer/commands/CopyCommand.java @@ -17,7 +17,6 @@ import lcsb.mapviewer.model.map.kinetics.SbmlFunction; import lcsb.mapviewer.model.map.kinetics.SbmlKinetics; import lcsb.mapviewer.model.map.kinetics.SbmlParameter; import lcsb.mapviewer.model.map.kinetics.SbmlUnit; -import lcsb.mapviewer.model.map.layout.Layout; import lcsb.mapviewer.model.map.layout.graphics.Layer; import lcsb.mapviewer.model.map.model.ElementSubmodelConnection; import lcsb.mapviewer.model.map.model.Model; diff --git a/model-command/src/test/java/lcsb/mapviewer/commands/CopyCommandTest.java b/model-command/src/test/java/lcsb/mapviewer/commands/CopyCommandTest.java index 6cc46e9d4266aaf4d7bf6ac25a376e4a7453f003..c19980657d23d3a5ff5ef3e85565a3dce6812190 100644 --- a/model-command/src/test/java/lcsb/mapviewer/commands/CopyCommandTest.java +++ b/model-command/src/test/java/lcsb/mapviewer/commands/CopyCommandTest.java @@ -10,7 +10,6 @@ import java.awt.geom.Point2D; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import org.junit.After; import org.junit.Before; diff --git a/model-command/src/test/java/lcsb/mapviewer/commands/SubModelCommandTest.java b/model-command/src/test/java/lcsb/mapviewer/commands/SubModelCommandTest.java index d4e7f30e6ed84db9ffad7a6caa4a5ebdacddf562..9056b2a2698be8f48ac5df373e5754e92ffb4299 100644 --- a/model-command/src/test/java/lcsb/mapviewer/commands/SubModelCommandTest.java +++ b/model-command/src/test/java/lcsb/mapviewer/commands/SubModelCommandTest.java @@ -2,7 +2,6 @@ package lcsb.mapviewer.commands; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import java.awt.geom.Path2D; import java.io.ByteArrayInputStream; diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/Reaction.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/Reaction.java index bcabc050f42a742757c05d55251d5b93a4a4ea52..737126987a4de8c0800caac394d8e5919c188deb 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/Reaction.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/Reaction.java @@ -36,7 +36,6 @@ import org.apache.log4j.Logger; import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; -import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.common.geometry.LineTransformation; import lcsb.mapviewer.model.map.BioEntity; diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/AntisenseRna.java b/model/src/main/java/lcsb/mapviewer/model/map/species/AntisenseRna.java index 801b026b7021fb5cbb736ffade5f55aa537d6feb..088eac1a1378914c5708dbfd61b19d00d299a6f5 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/AntisenseRna.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/AntisenseRna.java @@ -1,7 +1,6 @@ package lcsb.mapviewer.model.map.species; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import javax.persistence.DiscriminatorValue; diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/Rna.java b/model/src/main/java/lcsb/mapviewer/model/map/species/Rna.java index 5d41bcd193058162e9d164dfb992fd9c2ca443e3..d34d431b1cf6cf94b4833b6289d8966a7b4949b2 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/Rna.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/Rna.java @@ -1,7 +1,6 @@ package lcsb.mapviewer.model.map.species; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import javax.persistence.DiscriminatorValue; diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/SpeciesWithModificationResidue.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/SpeciesWithModificationResidue.java index da6163349278b52a898872ac0677692b6b694ef3..e9ad4b731bf03871e05af06c49ca68059b478c2e 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/SpeciesWithModificationResidue.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/SpeciesWithModificationResidue.java @@ -1,6 +1,5 @@ package lcsb.mapviewer.model.map.species.field; -import java.util.Collection; import java.util.List; /** diff --git a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelComparatorTest.java index f931b099c9a2e62ca1f9e2ed31866d518cba324a..c2baa22270230d405a116b002cf837cab7840cfb 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelComparatorTest.java @@ -17,7 +17,6 @@ import lcsb.mapviewer.model.map.MiriamRelationType; import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.PathwayCompartment; -import lcsb.mapviewer.model.map.layout.Layout; import lcsb.mapviewer.model.map.layout.graphics.Layer; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.type.TransportReaction; diff --git a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelDataTest.java b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelDataTest.java index 9881b49693d977ff83c3ffad9988e3ae1e2f79bb..54a8d516ab1b8fbe0f7433a72354f47339248d11 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelDataTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelDataTest.java @@ -20,7 +20,6 @@ import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.OverviewImage; import lcsb.mapviewer.model.map.layout.BlockDiagram; -import lcsb.mapviewer.model.map.layout.Layout; import lcsb.mapviewer.model.map.layout.graphics.Layer; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.Element; diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/GeneComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/GeneComparatorTest.java index 7b7d6d48694044e69cb299bedf6dd0663e3be914..4af40967c90ac8c0764e2c41f5fb376eb2c3724d 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/GeneComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/GeneComparatorTest.java @@ -12,7 +12,6 @@ import org.junit.Test; import org.mockito.Mockito; import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.species.field.AbstractSiteModification; import lcsb.mapviewer.model.map.species.field.ModificationSite; import lcsb.mapviewer.model.map.species.field.ModificationState; diff --git a/persist/src/main/java/lcsb/mapviewer/persist/DbUtils.java b/persist/src/main/java/lcsb/mapviewer/persist/DbUtils.java index 0cef750d7c6f32a15f312a2c731e0cdab6b0d169..6ac53ee658630da86304d224f86dbf92fe1c13f0 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/DbUtils.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/DbUtils.java @@ -5,8 +5,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Observable; -import javax.transaction.TransactionManager; - import org.apache.log4j.Logger; import org.hibernate.SQLQuery; import org.hibernate.Session; @@ -14,9 +12,9 @@ import org.hibernate.SessionFactory; import org.hibernate.dialect.Dialect; import org.hibernate.internal.SessionFactoryImpl; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import lcsb.mapviewer.common.exception.InvalidStateException; -import org.springframework.stereotype.Service; /** * This class contains a set of methods that allow to manage hibernate sessions diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/map/LayoutDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/map/LayoutDao.java index 64b93782826a93ef92076a719e964b20ae9a76d9..c754aef096bc03df8511ed6ca5d0ff789d5810c5 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/map/LayoutDao.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/dao/map/LayoutDao.java @@ -7,14 +7,13 @@ import org.apache.log4j.Logger; import org.hibernate.Criteria; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; +import org.springframework.stereotype.Repository; import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.layout.Layout; -import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.persist.dao.BaseDao; -import org.springframework.stereotype.Repository; /** * Data access object for {@link Layout} class. diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/CommentDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/CommentDaoTest.java index f44acde754fb9d737dfe59928134ee319654545c..4bd24a91427422c4ba0fb91be3fbd1b97b52415e 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/CommentDaoTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/CommentDaoTest.java @@ -25,7 +25,6 @@ import lcsb.mapviewer.model.map.reaction.type.TransportReaction; import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Species; -import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.Residue; import lcsb.mapviewer.persist.PersistTestFunctions; diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/model/ReactomePhysicalEntity.java b/reactome/src/main/java/lcsb/mapviewer/reactome/model/ReactomePhysicalEntity.java index 9638284291fd0ea37797e48c9d3fa96cf715f4ba..ef8691b527ed7900dbff0b7a130b020c2cffd1ca 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/model/ReactomePhysicalEntity.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/model/ReactomePhysicalEntity.java @@ -3,8 +3,6 @@ package lcsb.mapviewer.reactome.model; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; - /** * Object representing Reactome <a href= * "http://www.reactome.org/cgi-bin/classbrowser?DB=gk_current&CLASS=PhysicalEntity" diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndSimpleEntityComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndSimpleEntityComparator.java index 6c93422860e89a4988d3332aa8f2681fcf3e987b..099b291b908317e5324b54a50a0e5a41706095a4 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndSimpleEntityComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndSimpleEntityComparator.java @@ -3,15 +3,15 @@ package lcsb.mapviewer.reactome.utils.comparators; import java.util.HashSet; import java.util.Set; +import org.springframework.stereotype.Service; + import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamRelationType; import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.reactome.model.ReactomeReferenceEntity; import lcsb.mapviewer.reactome.model.ReactomeReferenceMolecule; import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; import lcsb.mapviewer.reactome.utils.ComparatorException; -import org.springframework.stereotype.Service; /** * This class allows to compare {@link Complex} element (internal diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndCatalystComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndCatalystComparator.java index 83e7bedd0ae39799fe1813b0e1a920be2c940639..e562eb8c69191b957f7d5340cec3f69f9d2027e5 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndCatalystComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndCatalystComparator.java @@ -1,5 +1,7 @@ package lcsb.mapviewer.reactome.utils.comparators; +import org.springframework.stereotype.Service; + import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.map.species.SimpleMolecule; import lcsb.mapviewer.reactome.model.ReactomeCatalystActivity; @@ -9,8 +11,6 @@ import lcsb.mapviewer.reactome.model.ReactomeEntityWithAccessionedSequence; import lcsb.mapviewer.reactome.model.ReactomePhysicalEntity; import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; import lcsb.mapviewer.reactome.utils.ComparatorException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; /** * This class allows to compare {@link SimpleMolecule} element (internal diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java index e7b443111d26d84cfb33fb20e40d476970389258..57916b9d19923dfdb612b95a445d9e2f4ac2014f 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java @@ -31,14 +31,11 @@ import lcsb.mapviewer.annotation.services.MiriamConnector; import lcsb.mapviewer.annotation.services.PubmedParser; import lcsb.mapviewer.annotation.services.PubmedSearchException; import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator; -import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.comparator.StringComparator; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.converter.IConverter; -import lcsb.mapviewer.converter.graphics.AbstractImageGenerator; -import lcsb.mapviewer.converter.graphics.ImageGenerators; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.converter.model.sbgnml.SbgnmlXmlConverter; import lcsb.mapviewer.converter.model.sbml.SbmlParser; @@ -320,8 +317,8 @@ public abstract class BaseRestImpl { */ public void setProjectService(IProjectService projectService) { this.projectService = projectService; - } - + } + protected IConverter getModelParser(String handlerClass) throws QueryException { for (IConverter converter : getModelConverters()) { if (converter.getClass().getCanonicalName().equals(handlerClass)) { @@ -338,7 +335,6 @@ public abstract class BaseRestImpl { result.add(new SbmlParser()); return result; } - protected String getFirstValue(List<Object> list) { if (list == null) { diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java index 0100b22104c53cc825ec7b473d04735cd6b3df9b..937aa13f666c2d931abebf2ce288be3fddc7fead 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java @@ -1,7 +1,7 @@ package lcsb.mapviewer.api.files; -import java.util.TreeMap; import java.util.Map; +import java.util.TreeMap; import org.apache.commons.lang3.ArrayUtils; import org.hibernate.QueryException; @@ -13,7 +13,6 @@ import lcsb.mapviewer.api.BaseRestImpl; import lcsb.mapviewer.api.ObjectNotFoundException; import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.model.cache.UploadedFileEntry; -import lcsb.mapviewer.model.user.PrivilegeType; import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao; import lcsb.mapviewer.services.SecurityException; diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java index 1da0a9b5261fd32b6957c8992c5fcf932362311b..a0177609c3388be8c71187d62e72959b1d3e8edc 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java @@ -1,7 +1,6 @@ package lcsb.mapviewer.api.projects; import java.awt.geom.Point2D; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.Serializable; import java.security.MessageDigest; @@ -16,7 +15,6 @@ import java.util.Set; import java.util.TreeMap; import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.MultiValueMap; diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/drugs/DrugRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/drugs/DrugRestImpl.java index b735ce360ec9e480c7254edf78006c017e99a8e7..549213de52c85a626fb6d97c7c056678324f063d 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/drugs/DrugRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/drugs/DrugRestImpl.java @@ -23,7 +23,6 @@ import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.services.SecurityException; -import lcsb.mapviewer.services.interfaces.IModelService; import lcsb.mapviewer.services.interfaces.IUserService; import lcsb.mapviewer.services.search.DbSearchCriteria; import lcsb.mapviewer.services.search.drug.IDrugService; diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesRestImpl.java index 3b1cf58d62fc68b7d0ecc0b41e7ecbf73441a2ee..256a9996a1a6729d15d41cf1bae8076514978ed1 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesRestImpl.java @@ -17,9 +17,7 @@ import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.services.SecurityException; import lcsb.mapviewer.services.UserAccessException; -import lcsb.mapviewer.services.interfaces.IModelService; import lcsb.mapviewer.services.interfaces.ISearchService; -import lcsb.mapviewer.services.interfaces.IUserService; @Transactional @Service diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/convert/ConvertRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/convert/ConvertRestImplTest.java index 2b29e95d8e015f4411f93dea2bdf25390f37b6a5..2e59795a7844cf6e5aa7ac136f4ec5d0f8e64f68 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/convert/ConvertRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/convert/ConvertRestImplTest.java @@ -4,13 +4,10 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -28,7 +25,6 @@ import org.junit.Test; import org.sbml.jsbml.SBMLException; import org.springframework.beans.factory.annotation.Autowired; - import lcsb.mapviewer.api.QueryException; import lcsb.mapviewer.api.RestTestFunctions; import lcsb.mapviewer.converter.ConverterException; @@ -56,314 +52,307 @@ public class ConvertRestImplTest extends RestTestFunctions { @After public void tearDown() throws Exception { } - - @SuppressWarnings("unchecked") + + @SuppressWarnings("unchecked") @Test public void testGetInformation() throws Exception { try { - Map<String, Object> result = convertRestImpl.getInformationImage(token); - assertTrue(result.keySet().size() == 2); - assertNotNull(result.get("inputs")); - assertNotNull(result.get("outputs")); - - List<Object> inputs = (List<Object>) result.get("inputs"); - List<Object> outputs = (List<Object>) result.get("outputs"); - - assertTrue(inputs.size() > 0); - assertTrue(outputs.size() > 0); - + Map<String, Object> result = convertRestImpl.getInformationImage(token); + assertTrue(result.keySet().size() == 2); + assertNotNull(result.get("inputs")); + assertNotNull(result.get("outputs")); + + List<Object> inputs = (List<Object>) result.get("inputs"); + List<Object> outputs = (List<Object>) result.get("outputs"); + + assertTrue(inputs.size() > 0); + assertTrue(outputs.size() > 0); + } catch (Exception e) { e.printStackTrace(); throw e; } } - + @SuppressWarnings("unchecked") @Test public void testGetInformationImage() throws Exception { try { - Map<String, Object> result = convertRestImpl.getInformationImage(token); - assertTrue(result.keySet().size() == 2); - assertNotNull(result.get("inputs")); - assertNotNull(result.get("outputs")); - - List<Object> inputs = (List<Object>) result.get("inputs"); - List<Object> outputs = (List<Object>) result.get("outputs"); - - assertTrue(inputs.size() > 0); - assertTrue(outputs.size() > 0); - + Map<String, Object> result = convertRestImpl.getInformationImage(token); + assertTrue(result.keySet().size() == 2); + assertNotNull(result.get("inputs")); + assertNotNull(result.get("outputs")); + + List<Object> inputs = (List<Object>) result.get("inputs"); + List<Object> outputs = (List<Object>) result.get("outputs"); + + assertTrue(inputs.size() > 0); + assertTrue(outputs.size() > 0); + } catch (Exception e) { e.printStackTrace(); throw e; } } - @Test public void testCelDesigner2Sbml1() throws Exception { try { - File file = new File("testFiles/convert/sample-cd.xml"); - String content = FileUtils.readFileToString(file); - String result = convertRestImpl.convert(token, "lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser", - "lcsb.mapviewer.converter.model.sbml.SbmlParser", content); - assertTrue(result.length() > 0); - assertTrue(result.contains("</layout:speciesReferenceGlyph>")); + File file = new File("testFiles/convert/sample-cd.xml"); + String content = FileUtils.readFileToString(file); + String result = convertRestImpl.convert(token, + "lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser", + "lcsb.mapviewer.converter.model.sbml.SbmlParser", content); + assertTrue(result.length() > 0); + assertTrue(result.contains("</layout:speciesReferenceGlyph>")); } catch (Exception e) { e.printStackTrace(); throw e; } } - + /* * this test does not work because the generator is not deterministic - @Test - public void testCelDesigner2Sbml2() throws Exception { - try { - File file = new File("testFiles/convert/sample-cd.xml"); - String content = FileUtils.readFileToString(file); - String result = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content); - //String result2 = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content); - String result2 = convertRestImpl.convert(token, "lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser", - "lcsb.mapviewer.converter.model.sbml.SbmlParser", content); - - assertTrue(result.equals(result2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - */ - + * + * @Test public void testCelDesigner2Sbml2() throws Exception { try { File file + * = new File("testFiles/convert/sample-cd.xml"); String content = + * FileUtils.readFileToString(file); String result = + * convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content); + * //String result2 = convertRestImpl.convert(token, "CellDesigner_SBML", + * "SBML", content); String result2 = convertRestImpl.convert(token, + * "lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser", + * "lcsb.mapviewer.converter.model.sbml.SbmlParser", content); + * + * assertTrue(result.equals(result2)); + * + * } catch (Exception e) { e.printStackTrace(); throw e; } } + */ + @Test public void testCelDesigner2Svg() throws Exception { try { - File file = new File("testFiles/convert/sample-cd.xml"); - String content = FileUtils.readFileToString(file); - String result = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", content).toString(); - - // FileOutputStream outputStream = new FileOutputStream("sample-cd.png"); - // outputStream.write(convertRestImpl.converToImage(token, "CellDesigner_SBML", "png", content).toByteArray()); - // outputStream.close(); - - assertTrue(result.contains("<rect")); + File file = new File("testFiles/convert/sample-cd.xml"); + String content = FileUtils.readFileToString(file); + String result = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", content).toString(); + + // FileOutputStream outputStream = new FileOutputStream("sample-cd.png"); + // outputStream.write(convertRestImpl.converToImage(token, "CellDesigner_SBML", + // "png", content).toByteArray()); + // outputStream.close(); + + assertTrue(result.contains("<rect")); } catch (Exception e) { e.printStackTrace(); throw e; } } - + @Test public void testCellDesigner2Sbml2Svg() throws Exception { try { - File file = new File("testFiles/convert/neuron_cd.xml"); - String content = FileUtils.readFileToString(file); - String resultSbml = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content).toString(); - String resultSvg = convertRestImpl.converToImage(token, "SBML", "svg", resultSbml).toString(); - - // FileOutputStream outputStream = new FileOutputStream("sample-cd.png"); - // outputStream.write(convertRestImpl.converToImage(token, "CellDesigner_SBML", "png", content).toByteArray()); - // outputStream.close(); - - assertTrue(resultSvg.contains("<rect")); + File file = new File("testFiles/convert/neuron_cd.xml"); + String content = FileUtils.readFileToString(file); + String resultSbml = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content).toString(); + String resultSvg = convertRestImpl.converToImage(token, "SBML", "svg", resultSbml).toString(); + + // FileOutputStream outputStream = new FileOutputStream("sample-cd.png"); + // outputStream.write(convertRestImpl.converToImage(token, "CellDesigner_SBML", + // "png", content).toByteArray()); + // outputStream.close(); + + assertTrue(resultSvg.contains("<rect")); } catch (Exception e) { e.printStackTrace(); throw e; } } - + @Test public void testCellDesigner2Sbml2CellDesignerSvg() throws Exception { try { - File file = new File("testFiles/convert/neuron_cd.xml"); - String content = FileUtils.readFileToString(file); - String resultSbml = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content).toString(); - String resultCellDesignerSbml = convertRestImpl.convert(token, "SBML", "CellDesigner_SBML", resultSbml).toString(); - String resultSvg = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", resultCellDesignerSbml).toString(); - - // FileOutputStream outputStream = new FileOutputStream("sample-cd.png"); - // outputStream.write(convertRestImpl.converToImage(token, "CellDesigner_SBML", "png", content).toByteArray()); - // outputStream.close(); - - assertTrue(resultSvg.contains("<rect")); + File file = new File("testFiles/convert/neuron_cd.xml"); + String content = FileUtils.readFileToString(file); + String resultSbml = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content).toString(); + String resultCellDesignerSbml = convertRestImpl.convert(token, "SBML", "CellDesigner_SBML", resultSbml) + .toString(); + String resultSvg = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", resultCellDesignerSbml) + .toString(); + + // FileOutputStream outputStream = new FileOutputStream("sample-cd.png"); + // outputStream.write(convertRestImpl.converToImage(token, "CellDesigner_SBML", + // "png", content).toByteArray()); + // outputStream.close(); + + assertTrue(resultSvg.contains("<rect")); } catch (Exception e) { e.printStackTrace(); throw e; } } - + @Test public void testScaling() throws Exception { try { - File file = new File("testFiles/convert/sample-cd.xml"); - String content = FileUtils.readFileToString(file); - String result1 = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", content, 50.0, 50.0).toString(); - String result2 = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", content, 100.0, 100.0).toString(); - - - Pattern pattern = Pattern.compile(".*scale\\(([0-9]+\\.[0-9]+),([0-9]+\\.[0-9]+)\\).*"); - Matcher matcher1 = pattern.matcher(result1); - Matcher matcher2 = pattern.matcher(result2); - - assertTrue(matcher1.find()); - assertTrue(matcher2.find()); - - assertFalse(matcher1.group(1).toString().equals(matcher2.group(1).toString())); - + File file = new File("testFiles/convert/sample-cd.xml"); + String content = FileUtils.readFileToString(file); + String result1 = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", content, 50.0, 50.0).toString(); + String result2 = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", content, 100.0, 100.0) + .toString(); + + Pattern pattern = Pattern.compile(".*scale\\(([0-9]+\\.[0-9]+),([0-9]+\\.[0-9]+)\\).*"); + Matcher matcher1 = pattern.matcher(result1); + Matcher matcher2 = pattern.matcher(result2); + + assertTrue(matcher1.find()); + assertTrue(matcher2.find()); + + assertFalse(matcher1.group(1).toString().equals(matcher2.group(1).toString())); + } catch (Exception e) { e.printStackTrace(); throw e; } } - + @Test public void test1() throws Exception { try { - File file = new File("testFiles/convert/glycolysis2.xml"); - String content = FileUtils.readFileToString(file); - - String result = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content); - ByteArrayOutputStream result1 = convertRestImpl.converToImage(token, "SBML", "svg", result); - - File output = new File("testFiles/convert/glycolysis2.svg"); - - FileOutputStream outputStream = new FileOutputStream(output); - outputStream.write(result1.toByteArray()); - outputStream.close(); - assertTrue(output.exists()); - output.delete(); - - + File file = new File("testFiles/convert/glycolysis2.xml"); + String content = FileUtils.readFileToString(file); + + String result = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content); + ByteArrayOutputStream result1 = convertRestImpl.converToImage(token, "SBML", "svg", result); + + File output = new File("testFiles/convert/glycolysis2.svg"); + + FileOutputStream outputStream = new FileOutputStream(output); + outputStream.write(result1.toByteArray()); + outputStream.close(); + assertTrue(output.exists()); + output.delete(); + } catch (Exception e) { e.printStackTrace(); throw e; } } - + @Test public void test2() throws Exception { try { - File file = new File("testFiles/convert/glycolysis2.xml"); - String content = FileUtils.readFileToString(file); - - String result = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content); - String result1 = convertRestImpl.convert(token, "SBML", "CellDesigner_SBML", result); - - + File file = new File("testFiles/convert/glycolysis2.xml"); + String content = FileUtils.readFileToString(file); + + String result = convertRestImpl.convert(token, "CellDesigner_SBML", "SBML", content); + String result1 = convertRestImpl.convert(token, "SBML", "CellDesigner_SBML", result); + } catch (Exception e) { e.printStackTrace(); throw e; } } - - + @Test public void testCelDesigner2Sbgn() throws Exception { try { - File file = new File("testFiles/convert/sample-cd.xml"); - String content = FileUtils.readFileToString(file); - String result = convertRestImpl.convert(token, "CellDesigner_SBML", "SBGN-ML", content).toString(); - assertTrue(result.contains("glyph class=\"complex\"")); + File file = new File("testFiles/convert/sample-cd.xml"); + String content = FileUtils.readFileToString(file); + String result = convertRestImpl.convert(token, "CellDesigner_SBML", "SBGN-ML", content).toString(); + assertTrue(result.contains("glyph class=\"complex\"")); } catch (Exception e) { e.printStackTrace(); throw e; } } - + /* * this test does not work because the generator is not deterministic - @Test - public void testCelDesigner2Svg2() throws Exception { - try { - File file = new File("testFiles/convert/sample-cd.xml"); - String content = FileUtils.readFileToString(file); - String result = convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", content).toString(); - String result2 = convertRestImpl.converToImage(token, "CellDesigner_SBML", - "lcsb.mapviewer.converter.graphics.SvgImageGenerator", content).toString(); - - assertTrue(result.equals(result2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - */ - + * + * @Test public void testCelDesigner2Svg2() throws Exception { try { File file = + * new File("testFiles/convert/sample-cd.xml"); String content = + * FileUtils.readFileToString(file); String result = + * convertRestImpl.converToImage(token, "CellDesigner_SBML", "svg", + * content).toString(); String result2 = convertRestImpl.converToImage(token, + * "CellDesigner_SBML", "lcsb.mapviewer.converter.graphics.SvgImageGenerator", + * content).toString(); + * + * assertTrue(result.equals(result2)); + * + * } catch (Exception e) { e.printStackTrace(); throw e; } } + */ + @SuppressWarnings("unchecked") private List<String> extractIdsFromOutputs(Map<String, Object> infoObject) { - List<String> ids = new ArrayList<>(); - for (Map<String, List<String>> o : (List<Map<String, List<String>>>) infoObject.get("outputs")) { - ids.add(o.get("available_names").get(0)); - } - return ids; + List<String> ids = new ArrayList<>(); + for (Map<String, List<String>> o : (List<Map<String, List<String>>>) infoObject.get("outputs")) { + ids.add(o.get("available_names").get(0)); + } + return ids; } - - private void test2All(String content, String converter) - throws SBMLException, SecurityException, InvalidInputDataExecption, InconsistentModelException, - IOException, ConverterException, XMLStreamException, DrawingException, QueryException - { - - Map<String, Object> info = convertRestImpl.getInformation(token); - Map<String, Object> infoImage = convertRestImpl.getInformationImage(token); - - List<String> targets = new ArrayList<>(); - - targets.addAll(extractIdsFromOutputs(info)); - for (String target: targets) { - String result = convertRestImpl.convert(token, converter, target, content).toString(); - assertTrue(result.length() > 0); - } - - targets.clear(); - targets.addAll(extractIdsFromOutputs(infoImage)); - for (String target: targets) { - String result = convertRestImpl.converToImage(token, converter, target, content).toString(); - assertTrue(result.length() > 0); - } + + private void test2All(String content, String converter) + throws SBMLException, SecurityException, InvalidInputDataExecption, InconsistentModelException, + IOException, ConverterException, XMLStreamException, DrawingException, QueryException { + + Map<String, Object> info = convertRestImpl.getInformation(token); + Map<String, Object> infoImage = convertRestImpl.getInformationImage(token); + + List<String> targets = new ArrayList<>(); + + targets.addAll(extractIdsFromOutputs(info)); + for (String target : targets) { + String result = convertRestImpl.convert(token, converter, target, content).toString(); + assertTrue(result.length() > 0); + } + + targets.clear(); + targets.addAll(extractIdsFromOutputs(infoImage)); + for (String target : targets) { + String result = convertRestImpl.converToImage(token, converter, target, content).toString(); + assertTrue(result.length() > 0); + } } - + @Test public void testCelDesigner2All() throws Exception { - - try { - File file = new File("testFiles/convert/sample-cd.xml"); - String content = FileUtils.readFileToString(file); - test2All(content, "CellDesigner_SBML"); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } + + try { + File file = new File("testFiles/convert/sample-cd.xml"); + String content = FileUtils.readFileToString(file); + test2All(content, "CellDesigner_SBML"); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } } - + @Test public void testSbml2All() throws Exception { - - try { - File file = new File("testFiles/convert/sample-sbml.xml"); - String content = FileUtils.readFileToString(file); - test2All(content, "SBML"); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } + + try { + File file = new File("testFiles/convert/sample-sbml.xml"); + String content = FileUtils.readFileToString(file); + test2All(content, "SBML"); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } } - + @Test public void testSbgn2All() throws Exception { - - try { - File file = new File("testFiles/convert/sample.sbgn"); - String content = FileUtils.readFileToString(file); - test2All(content, "SBGN-ML"); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } + + try { + File file = new File("testFiles/convert/sample.sbgn"); + String content = FileUtils.readFileToString(file); + test2All(content, "SBGN-ML"); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } } - + } diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesControllerTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesControllerTest.java index 5b1aa78aef09f05c7a9230090d1049f0a9fe0a36..29e64d174a28381a8941ccd31f599bd8156db7b9 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesControllerTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesControllerTest.java @@ -2,11 +2,10 @@ package lcsb.mapviewer.api.projects.models.bioEntities; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import java.awt.geom.Point2D; -import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/SearchService.java b/service/src/main/java/lcsb/mapviewer/services/impl/SearchService.java index dcc5bfd727af2ba1b4e2c24f8f2ec9967d441932..a536521da9ea4706d6b94948d982d0286b74e17f 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/SearchService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/SearchService.java @@ -12,7 +12,6 @@ import java.util.Map; import java.util.Set; import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -25,7 +24,6 @@ import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.SearchIndex; -import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; import lcsb.mapviewer.model.map.reaction.Reaction; diff --git a/service/src/main/java/lcsb/mapviewer/services/search/mirna/MiRNAService.java b/service/src/main/java/lcsb/mapviewer/services/search/mirna/MiRNAService.java index d63e6838cc989d2c20cc499476f37bde37a931fa..67b670d25c880a6bb854078242ca273087642cab 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/mirna/MiRNAService.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/mirna/MiRNAService.java @@ -7,10 +7,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.annotation.PostConstruct; - import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/service/src/test/java/lcsb/mapviewer/services/impl/SearchServiceTest.java b/service/src/test/java/lcsb/mapviewer/services/impl/SearchServiceTest.java index 4a95ab7f9b6ec398b7e2265f8a82287ed0cb765f..3fd35f90e71b6aff2bbd283a057c2f90e41121c6 100644 --- a/service/src/test/java/lcsb/mapviewer/services/impl/SearchServiceTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/impl/SearchServiceTest.java @@ -23,8 +23,6 @@ import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamRelationType; import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.compartment.Compartment; -import lcsb.mapviewer.model.map.layout.Layout; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelFullIndexed; import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; @@ -153,19 +151,19 @@ public class SearchServiceTest extends ServiceTestFunctions { } } - @Test - public void testSearchByUnknwonElementId() throws Exception { - try { - Model model = createFullModel(); - Element element =model.getElements().iterator().next(); - element.setId(907); - List<BioEntity> global = searchService.searchByQuery(model, "species:90111117", 50, null, "127.0.0.1"); - assertEquals(0, global.size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } + @Test + public void testSearchByUnknwonElementId() throws Exception { + try { + Model model = createFullModel(); + Element element = model.getElements().iterator().next(); + element.setId(907); + List<BioEntity> global = searchService.searchByQuery(model, "species:90111117", 50, null, "127.0.0.1"); + assertEquals(0, global.size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; } + } @Test public void testSearchByName4() throws Exception {