Skip to content
Snippets Groups Projects
Commit b21c6b47 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

tests using invalidate method weere refactored to be more "unit-like tests"

parent b66b297b
No related branches found
No related tags found
1 merge request!976Resolve "Fix flakes in tests"
...@@ -60,14 +60,12 @@ public class MeSHParser extends CachableInterface implements IExternalService { ...@@ -60,14 +60,12 @@ public class MeSHParser extends CachableInterface implements IExternalService {
} }
@Override @Override
public String refreshCacheQuery(Object query) throws SourceNotAvailable { public Object refreshCacheQuery(Object query) throws SourceNotAvailable {
String result = null; Object result = null;
try { try {
if (query instanceof String) { if (query instanceof String) {
String identifier = (String) query; String identifier = (String) query;
if (identifier.startsWith("http")) { if (identifier.startsWith(MESH_PREFIX)) {
result = getWebPageContent(identifier);
} else if (identifier.startsWith(MESH_PREFIX)) {
String[] ids = identifier.split("\\:"); String[] ids = identifier.split("\\:");
if (ids.length == 2) { if (ids.length == 2) {
MiriamData meshID = new MiriamData(MiriamType.MESH_2012, ids[1]); MiriamData meshID = new MiriamData(MiriamType.MESH_2012, ids[1]);
...@@ -77,10 +75,10 @@ public class MeSHParser extends CachableInterface implements IExternalService { ...@@ -77,10 +75,10 @@ public class MeSHParser extends CachableInterface implements IExternalService {
throw new InvalidArgumentException("Problematic query: \"" + query + "\""); throw new InvalidArgumentException("Problematic query: \"" + query + "\"");
} }
} else { } else {
throw new InvalidArgumentException("Don't know what to do with string \"" + query + "\""); result = super.refreshCacheQuery(query);
} }
} else { } else {
throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass()); result = super.refreshCacheQuery(query);
} }
} catch (IOException e) { } catch (IOException e) {
throw new SourceNotAvailable("Problem with accessing Mesh database", e); throw new SourceNotAvailable("Problem with accessing Mesh database", e);
......
...@@ -253,20 +253,12 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions { ...@@ -253,20 +253,12 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
} }
@Test(timeout = 150000) @Test(timeout = 150000)
public void testCachableInterfaceInvalidateDrug() throws Exception { public void testRefreshCacheForDrug() throws Exception {
String query = "drug:amantadine"; String query = "drug:amantadine";
String newRes = "hello";
cache.setCachedQuery(query, drugBankHTMLParser.getCacheType(), newRes);
cache.invalidateByQuery(query, drugBankHTMLParser.getCacheType());
permanentDatabaseLevelCache.waitToFinishTasks();
String res = cache.getStringByQuery(query, drugBankHTMLParser.getCacheType()); String res = drugBankHTMLParser.refreshCacheQuery(query);
assertNotNull(res); assertNotNull(res);
assertFalse("Value wasn't refreshed from db", newRes.equals(res));
} }
@Test @Test
......
...@@ -86,12 +86,6 @@ public class MeSHParserTest extends AnnotationTestFunctions { ...@@ -86,12 +86,6 @@ public class MeSHParserTest extends AnnotationTestFunctions {
meshParser.getMeSH(null); meshParser.getMeSH(null);
} }
@Test
public void testRefreshCacheQuery() throws Exception {
Object res = meshParser.refreshCacheQuery("http://google.pl/");
assertNotNull(res);
}
@Test @Test
public void testGetRotenoneMesh() throws Exception { public void testGetRotenoneMesh() throws Exception {
// Rotenone disease -no synonyms // Rotenone disease -no synonyms
...@@ -143,19 +137,11 @@ public class MeSHParserTest extends AnnotationTestFunctions { ...@@ -143,19 +137,11 @@ public class MeSHParserTest extends AnnotationTestFunctions {
} }
@Test @Test
public void testCachableInterfaceInvalidateChemical() throws Exception { public void testRefreshCacheQuery() throws Exception {
MiriamData meshID = new MiriamData(MiriamType.MESH_2012, "D010300"); MiriamData meshID = new MiriamData(MiriamType.MESH_2012, "D010300");
MeSH mesh = meshParser.getMeSH(meshID);
assertNotNull(mesh);
cache.invalidateByQuery(meshParser.getIdentifier(meshID), meshParser.getCacheType());
permanentDatabaseLevelCache.waitToFinishTasks();
MeSH mesh2 = meshParser.getMeSH(meshID);
assertNotNull(mesh2);
assertFalse("Value wasn't refreshed from db", mesh.equals(mesh2)); Object result = meshParser.refreshCacheQuery(meshParser.getIdentifier(meshID));
assertNotNull(result);
} }
@Test @Test
......
...@@ -137,28 +137,6 @@ public class MiRNAParserTest extends AnnotationTestFunctions { ...@@ -137,28 +137,6 @@ public class MiRNAParserTest extends AnnotationTestFunctions {
} }
} }
@Test(timeout = 50000)
public void testCachableInterfaceInvalidateMiRNA() throws Exception {
List<String> listIds = new ArrayList<>();
listIds.add("gga-miR-489-3p");
List<MiRNA> list = miRNAParser.getMiRnasByNames(listIds);
assertTrue(!list.isEmpty());
assertEquals(1, list.get(0).getTargets().size());
cache.invalidateByQuery(MiRNAParser.MI_RNA_PREFIX + list.get(0).getName(), miRNAParser.getCacheType());
permanentDatabaseLevelCache.waitToFinishTasks();
listIds.clear();
listIds.add(list.get(0).getName());
List<MiRNA> list2 = miRNAParser.getMiRnasByNames(listIds);
assertNotNull(list2);
assertEquals(1, list2.size());
assertFalse("Value wasn't refreshed from db", list.get(0).equals(list2.get(0)));
assertTrue(list.get(0).getName().equals(list2.get(0).getName()));
}
@Test @Test
public void testGetMiRna() throws Exception { public void testGetMiRna() throws Exception {
String mirBaseName = "hsa-miR-296-5p"; String mirBaseName = "hsa-miR-296-5p";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment