Commit 4f57302c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

stacktrace is printed using junit rule

parent 45b2286e
......@@ -3,8 +3,7 @@ package lcsb.mapviewer.cdplugin;
import java.util.List;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.After;
import org.junit.Before;
import org.junit.*;
import org.mockito.Mockito;
import jp.sbi.celldesigner.plugin.PluginListOf;
......@@ -12,9 +11,13 @@ import jp.sbi.celldesigner.plugin.PluginReaction;
import jp.sbi.celldesigner.plugin.PluginSpecies;
import jp.sbi.celldesigner.plugin.PluginSpeciesAlias;
import lcsb.mapviewer.common.MinervaLoggerAppender;
import lcsb.mapviewer.common.UnitTestFailedWatcher;
public class CdPluginFunctions {
@Rule
public UnitTestFailedWatcher unitTestFailedWatcher = new UnitTestFailedWatcher();
String rdfString = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\">\n"
+
"<rdf:Description rdf:about=\"#s3\">\n" +
......
package lcsb.mapviewer.cdplugin.copypaste;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.*;
import java.util.Set;
import org.apache.logging.log4j.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import lcsb.mapviewer.cdplugin.CdPluginFunctions;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamRelationType;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.*;
public class CopyPasteAbstractActionTest {
public class CopyPasteAbstractActionTest extends CdPluginFunctions {
Logger logger = LogManager.getLogger(CopyPasteAbstractActionTest.class);
@Before
......@@ -29,102 +25,70 @@ public class CopyPasteAbstractActionTest {
@Test
public void testPaste() throws Exception {
try {
CopyPasteAbstractAction pa = new PasteAction();
String clipboardString = "[MIRIAM]\t" + MiriamRelationType.BQ_BIOL_IS.getStringRepresentation() + "\t"
+ MiriamType.CHEBI.getUris().get(0)
+ "\tCHEBI:12345\nasd";
Pair<Set<MiriamData>, String> res = pa.getAnnotationDataFromClipboardString(clipboardString);
assertNotNull(res);
assertNotNull(res.getLeft());
assertEquals(1, res.getLeft().size());
assertNotNull(res.getRight());
assertEquals("asd", res.getRight());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CopyPasteAbstractAction pa = new PasteAction();
String clipboardString = "[MIRIAM]\t" + MiriamRelationType.BQ_BIOL_IS.getStringRepresentation() + "\t"
+ MiriamType.CHEBI.getUris().get(0)
+ "\tCHEBI:12345\nasd";
Pair<Set<MiriamData>, String> res = pa.getAnnotationDataFromClipboardString(clipboardString);
assertNotNull(res);
assertNotNull(res.getLeft());
assertEquals(1, res.getLeft().size());
assertNotNull(res.getRight());
assertEquals("asd", res.getRight());
}
@Test
public void testCopyPaste() throws Exception {
try {
CopyPasteAbstractAction pa = new PasteAction();
String annString = "<rdf:RDF xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" "
+ "xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\" "
+ "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
+ "<rdf:Description rdf:about=\"#s1\">" + "<bqmodel:is>" + "<rdf:Bag>"
+ "<rdf:li rdf:resource=\"urn:miriam:hgnc:SNCA\"/>" + "</rdf:Bag>"
+ "</bqmodel:is>" + "</rdf:Description>" + "</rdf:RDF>";
String str = pa.getCopyString(annString, "notes");
Pair<Set<MiriamData>, String> res = pa.getAnnotationDataFromClipboardString(str);
assertNotNull(res);
assertNotNull(res.getLeft());
assertEquals(1, res.getLeft().size());
assertNotNull(res.getRight());
assertEquals("notes", res.getRight());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CopyPasteAbstractAction pa = new PasteAction();
String annString = "<rdf:RDF xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" "
+ "xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\" "
+ "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
+ "<rdf:Description rdf:about=\"#s1\">" + "<bqmodel:is>" + "<rdf:Bag>"
+ "<rdf:li rdf:resource=\"urn:miriam:hgnc:SNCA\"/>" + "</rdf:Bag>"
+ "</bqmodel:is>" + "</rdf:Description>" + "</rdf:RDF>";
String str = pa.getCopyString(annString, "notes");
Pair<Set<MiriamData>, String> res = pa.getAnnotationDataFromClipboardString(str);
assertNotNull(res);
assertNotNull(res.getLeft());
assertEquals(1, res.getLeft().size());
assertNotNull(res.getRight());
assertEquals("notes", res.getRight());
}
@Test
public void testSerializeMiriam() throws Exception {
try {
CopyPasteAbstractAction pa = new PasteAction();
MiriamData md = new MiriamData(MiriamType.CHEBI, "CH:12");
String string = pa.serialize(md);
MiriamData md2 = pa.deserialize(string);
assertEquals(md, md2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CopyPasteAbstractAction pa = new PasteAction();
MiriamData md = new MiriamData(MiriamType.CHEBI, "CH:12");
String string = pa.serialize(md);
MiriamData md2 = pa.deserialize(string);
assertEquals(md, md2);
}
@Test
public void testDeserializeMiriam() throws Exception {
try {
CopyPasteAbstractAction pa = new PasteAction();
MiriamData md = pa.deserialize("ASDASDAS");
assertNull(md);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CopyPasteAbstractAction pa = new PasteAction();
MiriamData md = pa.deserialize("ASDASDAS");
assertNull(md);
}
@Test
public void testDeserializeMiriam2() throws Exception {
try {
CopyPasteAbstractAction pa = new PasteAction();
MiriamData md = pa.deserialize(null);
assertNull(md);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CopyPasteAbstractAction pa = new PasteAction();
MiriamData md = pa.deserialize(null);
assertNull(md);
}
@Test
public void testDeserializeMiriam3() throws Exception {
try {
CopyPasteAbstractAction pa = new PasteAction();
MiriamData md = pa.deserialize("[MIRIAM]\tinvalid\ttype\tresource");
assertNull(md);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CopyPasteAbstractAction pa = new PasteAction();
MiriamData md = pa.deserialize("[MIRIAM]\tinvalid\ttype\tresource");
assertNull(md);
}
}
......@@ -30,9 +30,7 @@ import javax.xml.transform.stream.StreamResult;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.After;
import org.junit.Before;
import org.junit.*;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
......@@ -48,6 +46,7 @@ import org.xml.sax.SAXException;
import lcsb.mapviewer.annotation.cache.PermanentDatabaseLevelCacheInterface;
import lcsb.mapviewer.common.MinervaLoggerAppender;
import lcsb.mapviewer.common.UnitTestFailedWatcher;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
......@@ -60,6 +59,9 @@ import lcsb.mapviewer.persist.dao.cache.CacheTypeDao;
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class AnnotationTestFunctions extends AbstractTransactionalJUnit4SpringContextTests {
@Rule
public UnitTestFailedWatcher unitTestFailedWatcher = new UnitTestFailedWatcher();
@Autowired
protected PermanentDatabaseLevelCacheInterface cache;
......
package lcsb.mapviewer.annotation.cache;
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 org.apache.logging.log4j.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import org.w3c.dom.Node;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
......@@ -18,104 +14,89 @@ import lcsb.mapviewer.model.cache.CacheType;
public class ApplicationLevelCacheTest extends AnnotationTestFunctions {
Logger logger = LogManager.getLogger(ApplicationLevelCacheTest.class);
boolean status;
@Before
public void setUp() throws Exception {
status = Configuration.isApplicationCacheOn();
}
@After
public void tearDown() throws Exception {
Configuration.setApplicationCacheOn(status);
}
@Test
public void testApplicationCacheByQuery() {
try {
CacheType type = cacheTypeDao.getByClassName(PubmedParser.class.getCanonicalName());
String xml = "<hello/>";
String query = "blabla";
Node sourceNode = getNodeFromXmlString(xml);
ApplicationLevelCache cache = ApplicationLevelCache.getInstance();
cache.clearCache();
Node node = cache.getXmlNodeByQuery(query, type);
assertNull(node);
cache.setCachedQuery(query, type, sourceNode);
node = cache.getXmlNodeByQuery(query, type);
assertNotNull(node);
cache.clearCache();
node = cache.getXmlNodeByQuery(query, type);
assertNull(node);
} catch (Exception e) {
e.printStackTrace();
fail("Unknown exception");
}
}
@Test
public void testApplicationCacheOff() {
boolean value = Configuration.isApplicationCacheOn();
try {
Configuration.setApplicationCacheOn(false);
assertNull(ApplicationLevelCache.getInstance());
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
Configuration.setApplicationCacheOn(value);
}
}
@Test
public void testSetInvalidValue() {
try {
ApplicationLevelCache cache = ApplicationLevelCache.getInstance();
cache.setCachedQuery("bla", null, new Object());
} catch (CacheException e) {
assertTrue(e.getMessage().contains("Unknown object type"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testClearCacheWhenMemoryUsageIsHigh() throws Exception {
Double oldVal = Configuration.getMemorySaturationRatioTriggerClean();
try {
CacheType type = new CacheType();
type.setId(-13);
ApplicationLevelCache cache = ApplicationLevelCache.getInstance();
cache.setCachedQuery("bla", type, "test");
assertNotNull(cache.getStringByQuery("bla", type));
// fill cache with some dumb data
for (int i = 0; i < ApplicationLevelCache.MIN_CACHED_VALUES_BEFORE_CLEAN; i++) {
cache.setCachedQuery("bla" + i, type, "test");
}
assertNotNull(cache.getStringByQuery("bla", type));
Configuration.setMemorySaturationRatioTriggerClean(0.0);
cache.performMemoryBalance();
assertNull(cache.getStringByQuery("bla", type));
} catch (CacheException e) {
assertTrue(e.getMessage().contains("Unknown object type"));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
// restore old value
Configuration.setMemorySaturationRatioTriggerClean(oldVal);
}
}
Logger logger = LogManager.getLogger(ApplicationLevelCacheTest.class);
boolean status;
@Before
public void setUp() throws Exception {
status = Configuration.isApplicationCacheOn();
}
@After
public void tearDown() throws Exception {
Configuration.setApplicationCacheOn(status);
}
@Test
public void testApplicationCacheByQuery() throws Exception {
CacheType type = cacheTypeDao.getByClassName(PubmedParser.class.getCanonicalName());
String xml = "<hello/>";
String query = "blabla";
Node sourceNode = getNodeFromXmlString(xml);
ApplicationLevelCache cache = ApplicationLevelCache.getInstance();
cache.clearCache();
Node node = cache.getXmlNodeByQuery(query, type);
assertNull(node);
cache.setCachedQuery(query, type, sourceNode);
node = cache.getXmlNodeByQuery(query, type);
assertNotNull(node);
cache.clearCache();
node = cache.getXmlNodeByQuery(query, type);
assertNull(node);
}
@Test
public void testApplicationCacheOff() {
boolean value = Configuration.isApplicationCacheOn();
try {
Configuration.setApplicationCacheOn(false);
assertNull(ApplicationLevelCache.getInstance());
} finally {
Configuration.setApplicationCacheOn(value);
}
}
@Test
public void testSetInvalidValue() {
try {
ApplicationLevelCache cache = ApplicationLevelCache.getInstance();
cache.setCachedQuery("bla", null, new Object());
} catch (CacheException e) {
assertTrue(e.getMessage().contains("Unknown object type"));
}
}
@Test
public void testClearCacheWhenMemoryUsageIsHigh() throws Exception {
Double oldVal = Configuration.getMemorySaturationRatioTriggerClean();
try {
CacheType type = new CacheType();
type.setId(-13);
ApplicationLevelCache cache = ApplicationLevelCache.getInstance();
cache.setCachedQuery("bla", type, "test");
assertNotNull(cache.getStringByQuery("bla", type));
// fill cache with some dumb data
for (int i = 0; i < ApplicationLevelCache.MIN_CACHED_VALUES_BEFORE_CLEAN; i++) {
cache.setCachedQuery("bla" + i, type, "test");
}
assertNotNull(cache.getStringByQuery("bla", type));
Configuration.setMemorySaturationRatioTriggerClean(0.0);
cache.performMemoryBalance();
assertNull(cache.getStringByQuery("bla", type));
} catch (CacheException e) {
assertTrue(e.getMessage().contains("Unknown object type"));
} finally {
// restore old value
Configuration.setMemorySaturationRatioTriggerClean(oldVal);
}
}
}
package lcsb.mapviewer.annotation.cache;
import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.apache.logging.log4j.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import org.mockito.Mockito;
import org.w3c.dom.Node;
......@@ -15,121 +14,83 @@ import lcsb.mapviewer.annotation.AnnotationTestFunctions;
import lcsb.mapviewer.model.cache.CacheType;
import lcsb.mapviewer.persist.dao.cache.CacheTypeDao;
public class CachableInterfaceTest extends AnnotationTestFunctions {
Logger logger = LogManager.getLogger(CachableInterfaceTest.class);
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testGetWebPage() throws Exception {
try {
CachableInterfaceMock ci = new CachableInterfaceMock(CachableInterface.class);
String result = ci.getWebPageContent("http://www.drugbank.ca/biodb/polypeptides/P21728");
assertNotNull(result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetWebPage2() throws Exception {
try {
CachableInterfaceMock ci = new CachableInterfaceMock(CachableInterface.class);
String result = ci.getWebPageContent("http://www.drugbank.ca/drugs/DB00091");
assertNotNull(result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetWebPageGetCache() throws Exception {
try {
CachableInterfaceMock ci = new CachableInterfaceMock(CachableInterface.class);
CacheTypeDao mock = Mockito.mock(CacheTypeDao.class);
when(mock.getByClassName(anyString())).thenReturn(new CacheType());
ci.setCacheTypeDao(mock);
ci.setCache(new GeneralCache(null));
String cacheKey = "https://www.google.com/";
String result = ci.getWebPageContent(cacheKey);
assertNotNull(result);
String cacheValue = ci.getCacheValue(cacheKey);
assertTrue(result.equals(cacheValue));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetNode() throws Exception {
try {
CachableInterfaceMock ci = new CachableInterfaceMock(CachableInterface.class);
CacheTypeDao mock = Mockito.mock(CacheTypeDao.class);
when(mock.getByClassName(anyString())).thenReturn(new CacheType());
ci.setCacheTypeDao(mock);
String xml = "<xml><child/></xml>";
ci.setCache(new GeneralCache(null));
ci.setCacheNode("id", super.getNodeFromXmlString(xml));
Node node = ci.getCacheNode("id");
assertNotNull(node);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testNewLinesGetWebPage() throws Exception {
try {
CachableInterfaceMock ci = new CachableInterfaceMock(CachableInterface.class);
ci.setCache(null);
String result = ci.getWebPageContent("http://google.com/");
assertNotNull(result);
assertTrue(result.contains("\n"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCleanHtml() throws Exception {
try {
CachableInterfaceMock ci = new CachableInterfaceMock(CachableInterface.class);
String res = ci.cleanHtml("blabla <invalid_tag");
assertEquals("blabla ",res);
} catch (Exception e) {
e.printStackTrace();
throw e;