Commit 30c274cb authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fixes on unit tests

parent e5aaec92
Pipeline #2597 passed with stage
in 40 seconds
......@@ -86,7 +86,7 @@ public final class ApplicationLevelCache extends XmlParser implements QueryCache
@Override
public synchronized void setCachedQuery(String query, CacheType type, Object object) {
setCachedQuery(query, type, object, type.getValidity());
setCachedQuery(query, type, object, 0);
}
@Override
......
......@@ -574,6 +574,7 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
public void testGetEmptySuggestedQueryList() throws Exception {
try {
Project project = new Project();
project.setId(-1);
List<String> result = chemicalParser.getSuggestedQueryList(project, parkinsonDiseaseId);
......
......@@ -219,16 +219,16 @@ public class MiriamConnectorTest extends AnnotationTestFunctions {
}
}
@Test
public void testGetUrl2WithInvalidApiResponse() throws Exception {
WebPageDownloader downloader = miriamConnector.getWebPageDownloader();
GeneralCacheInterface cache = miriamConnector.getCache();
try {
// exclude first cached value
miriamConnector.setCache(new GeneralCacheWithExclusion(cache, 1));
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
miriamConnector.setWebPageDownloader(mockDownloader);
@Test
public void testGetUrl2WithInvalidApiResponse() throws Exception {
WebPageDownloader downloader = miriamConnector.getWebPageDownloader();
GeneralCacheInterface cache = miriamConnector.getCache();
try {
// exclude first cached value
miriamConnector.setCache(new GeneralCacheWithExclusion(cache, 1));
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
miriamConnector.setWebPageDownloader(mockDownloader);
miriamConnector.getUrlString2(TaxonomyBackend.HUMAN_TAXONOMY);
......@@ -243,49 +243,24 @@ public class MiriamConnectorTest extends AnnotationTestFunctions {
}
}
@Test
public void testGetUrl2WithInvalidApiResponse2() throws Exception {
WebPageDownloader downloader = miriamConnector.getWebPageDownloader();
GeneralCacheInterface cache = miriamConnector.getCache();
try {
// exclude first cached value
miriamConnector.setCache(new GeneralCacheWithExclusion(cache, 1));
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("");
miriamConnector.setWebPageDownloader(mockDownloader);
miriamConnector.getUrlString2(TaxonomyBackend.HUMAN_TAXONOMY);
} catch (AnnotationException e) {
assertTrue(e.getMessage().contains("Problem with parsing miriam REST API response"));
@Test
public void testRefreshCacheQueryNotAvailable() throws Exception {
WebPageDownloader downloader = miriamConnector.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
miriamConnector.setWebPageDownloader(mockDownloader);
miriamConnector.refreshCacheQuery("http://google.pl/");
fail("Exception expected");
} catch (SourceNotAvailable e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
miriamConnector.setWebPageDownloader(downloader);
miriamConnector.setCache(cache);
}
}
@Test
public void testRefreshCacheQueryNotAvailable() throws Exception {
WebPageDownloader downloader = miriamConnector.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
miriamConnector.setWebPageDownloader(mockDownloader);
miriamConnector.refreshCacheQuery("http://google.pl/");
fail("Exception expected");
} catch (SourceNotAvailable e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
miriamConnector.setWebPageDownloader(downloader);
}
}
@Test
public void testRefreshInvalidCacheQuery() throws Exception {
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment