Commit fa0faeef authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'webpagedownloader-post' into 'master'

Webpagedownloader supporting different HTTP requests

See merge request !65
parents b57781b2 4b8c4701
Pipeline #2315 passed with stage
in 43 seconds
......@@ -161,9 +161,9 @@ public abstract class CachableInterface extends XmlParser {
public final void setCache(GeneralCacheInterface cache) {
this.cache = cache;
}
/**
* Returns a content of the webpage for a given url.
* Returns a content of the webpage for a given url using GET request.
*
* @param accessUrl
* webpage url address
......@@ -172,13 +172,36 @@ public abstract class CachableInterface extends XmlParser {
* thrown when there are problems with connection to ChEMBL database
*/
protected final String getWebPageContent(String accessUrl) throws IOException {
return getWebPageContent(accessUrl, "GET", null);
}
/**
* Returns a content of the webpage for a given url. If postData is not null,
* the page will be accessed using POST request. Otherwise GET will be used.
*
* @param accessUrl
* webpage url address
* @param httpRequestMethod
* type of HTTP request (GET, POST, PUT, PATCH, DELETE, ...)
* @param postData
* string to be sent in the body of the request
* @return content of the webpage
* @throws IOException
* thrown when there are problems with connection to ChEMBL database
*/
protected final String getWebPageContent(String accessUrl, String httpRequestMethod, String data) throws IOException {
// check if we have the page in our internal cache
String cacheKey = accessUrl;
if (data != null) {
cacheKey += data;
}
String result = getCacheValue(accessUrl);
String result = getCacheValue(cacheKey);
if (result == null) {
result = webPageDownloader.getFromNetwork(accessUrl);
result = webPageDownloader.getFromNetwork(accessUrl, httpRequestMethod, data);
if (result != null) {
setCacheValue(accessUrl, result);
setCacheValue(cacheKey, result);
}
}
return result;
......
......@@ -4,6 +4,7 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.DataOutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
......@@ -26,6 +27,10 @@ import lcsb.mapviewer.annotation.services.WrongResponseCodeIOException;
* @author Piotr Gawron
*
*/
/**
* @author Piotr Gawron
*
*/
public class WebPageDownloader {
/**
......@@ -50,17 +55,39 @@ public class WebPageDownloader {
* receiving INTERNAL SERVER ERROR http response.
*/
private static final int HTTP_INTERNAL_ERROR_RECONNECT_TIMES = 2;
/**
* Returns content of the webpage identified by url.
* Returns content of the webpage identified by url using GET.
*
* @param accessUrl
* url of a webpage
* @return content of the webpage identified by url
* @throws IOException
* thrown when there is any problem with accesing webpage
* thrown when there is any problem with accessing webpage
*/
public String getFromNetwork(String accessUrl) throws IOException {
return getFromNetwork(accessUrl, "GET", null);
}
/**
* Returns content of the webpage identified by url. The HTTP query is done
* using the provided POST if postData is not null.
*
*
* @param accessUrl
* url of a webpage
* @param httpRequestMethod
* type of HTTP request (GET, POST, PUT, PATCH, DELETE, ...)
* @param data
* string to be sent in the body of the
* @return content of the webpage identified by url
* @throws IOException
* thrown when there is any problem with accessing webpage
*/
public String getFromNetwork(String accessUrl, String httpRequestMethod, String data) throws IOException {
/**
* Tasks that retrieves content from webpage
......@@ -77,12 +104,20 @@ public class WebPageDownloader {
int code = HttpURLConnection.HTTP_INTERNAL_ERROR;
HttpURLConnection urlConn = null;
// connect to the server, if HTTP_INTERNAL_ERROR occurres then try to
// connect to the server, if HTTP_INTERNAL_ERROR occurred then try to
// reconnect HTTP_INTERNAL_ERROR_RECONNECT_TIMES times
while (code == HttpURLConnection.HTTP_INTERNAL_ERROR || code == HttpURLConnection.HTTP_NOT_FOUND) {
urlConn = openConnection(accessUrl);
urlConn.setRequestMethod("GET");
urlConn = openConnection(accessUrl);
urlConn.addRequestProperty("User-Agent", "minerva-framework");
urlConn.setRequestMethod(httpRequestMethod);
if (data != null) {
urlConn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(urlConn.getOutputStream());
wr.writeBytes(data);
wr.close();
}
try {
urlConn.connect();
code = urlConn.getResponseCode();
......
......@@ -50,6 +50,27 @@ public class CachableInterfaceTest extends AnnotationTestFunctions {
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());
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 {
......
package lcsb.mapviewer.annotation.cache;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.net.HttpURLConnection;
......@@ -61,5 +62,37 @@ public class WebPageDownloaderTest {
} catch (IOException e) {
}
}
@Test
public void testSend1() {
WebPageDownloader downloader = new WebPageDownloader();
try {
String result = downloader.getFromNetwork("https://www.google.com/");
assertNotNull("GET request to Google should return non-null result", result);
} catch (IOException e) {
}
}
@Test
public void testPost1() {
WebPageDownloader downloader = new WebPageDownloader();
try {
String result = downloader.getFromNetwork("https://www.ebi.ac.uk/pdbe/api/mappings/best_structures/", "POST", "P29373");
assertNotNull("POST request to Uniprot should return non-null result", result);
} catch (IOException e) {
}
}
@Test
public void testInvalidHttpRequestType() {
WebPageDownloader downloader = new WebPageDownloader();
try {
String result = downloader.getFromNetwork("https://www.ebi.ac.uk/pdbe/api/mappings/best_structures/", "XXX", "P29373");
fail("Invalid request exception expected");
} catch (IOException e) {
}
}
}
......@@ -297,7 +297,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("invalid xml");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("invalid xml");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetFromId(new MiriamData(MiriamType.CHEMBL_TARGET, "water"));
fail("Exception expected");
......@@ -319,7 +319,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("invalid xml");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("invalid xml");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.findDrug("test");
fail("Exception expected");
......@@ -341,7 +341,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetFromId(new MiriamData(MiriamType.CHEMBL_TARGET, "water"));
fail("Exception expected");
......@@ -403,7 +403,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("<target><unk/></target>");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("<target><unk/></target>");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetFromId(new MiriamData(MiriamType.CHEMBL_TARGET, "water"));
assertEquals(1, getWarnings().size());
......@@ -422,7 +422,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("<target><target_components><target_component/></target_components></target>");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("<target><target_components><target_component/></target_components></target>");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetFromId(new MiriamData(MiriamType.CHEMBL_TARGET, "water"));
assertEquals(1, getWarnings().size());
......@@ -441,7 +441,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("<target><target_chembl_id>inv id</target_chembl_id></target>");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("<target><target_chembl_id>inv id</target_chembl_id></target>");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetFromId(new MiriamData(MiriamType.CHEMBL_TARGET, "water"));
assertEquals(1, getWarnings().size());
......@@ -836,7 +836,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
// simulate problem with downloading
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.refreshCacheQuery("http://google.pl/");
fail("Exception expected");
......@@ -860,7 +860,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
// simulate problem with downloading
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getDrugsByChemblTarget(new MiriamData());
......@@ -886,7 +886,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
// simulate problem with downloading
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getDrugsByChemblTarget(new MiriamData());
......@@ -914,7 +914,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
// simulate problem with downloading
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.refreshCacheQuery(query);
fail("Exception expected");
......@@ -943,7 +943,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = chemblParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.DOWN, chemblParser.getServiceStatus().getStatus());
} catch (Exception e) {
......@@ -959,7 +959,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = chemblParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("<response><molecules/></response>");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("<response><molecules/></response>");
chemblParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.CHANGED, chemblParser.getServiceStatus().getStatus());
} catch (Exception e) {
......@@ -977,7 +977,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
// valid xml but with empty data
when(mockDownloader.getFromNetwork(anyString())).thenReturn(
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn(
"<response><molecules>" + "<molecule><pref_name/><max_phase/><molecule_chembl_id/><molecule_synonyms/></molecule>"
+ "</molecules><mechanisms/><molecule_forms/></response>");
chemblParser.setWebPageDownloader(mockDownloader);
......@@ -1016,7 +1016,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("invalid xml");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("invalid xml");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetsByDrugId(new MiriamData(MiriamType.CHEMBL_COMPOUND, "123"));
fail("Exception expected");
......@@ -1036,7 +1036,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetsByDrugId(new MiriamData(MiriamType.CHEMBL_COMPOUND, "123"));
fail("Exception expected");
......@@ -1056,7 +1056,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getDrugListByTarget(new MiriamData(MiriamType.UNIPROT, "O60391"));
fail("Exception expected");
......@@ -1077,7 +1077,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("invalid xml");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("invalid xml");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getDrugListByTarget(new MiriamData(MiriamType.UNIPROT, "O60391"));
fail("Exception expected");
......@@ -1140,7 +1140,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("invalid xml");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("invalid xml");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getDrugById(new MiriamData(MiriamType.CHEMBL_COMPOUND, ""));
fail("Exception expected");
......@@ -1160,7 +1160,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getDrugById(new MiriamData(MiriamType.CHEMBL_COMPOUND, ""));
fail("Exception expected");
......@@ -1193,7 +1193,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetsForChildElements(new MiriamData());
fail("Exception expected");
......@@ -1213,7 +1213,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("invalid xml");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("invalid xml");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetsForChildElements(new MiriamData());
fail("Exception expected");
......@@ -1233,7 +1233,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
try {
chemblParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("<response><molecule_forms><node/></molecule_forms></response>");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("<response><molecule_forms><node/></molecule_forms></response>");
chemblParser.setWebPageDownloader(mockDownloader);
chemblParser.getTargetsForChildElements(new MiriamData());
assertEquals(1, getWarnings().size());
......
......@@ -77,7 +77,7 @@ 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())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemicalParser.setWebPageDownloader(mockDownloader);
// Parkinson disease
MiriamData diseaseID = new MiriamData(MiriamType.MESH_2012, "D010300");
......@@ -431,7 +431,7 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
// simulate problem with downloading
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("");
chemicalParser.setWebPageDownloader(mockDownloader);
chemicalParser.refreshCacheQuery(query);
fail("Exception expected");
......@@ -460,7 +460,7 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = chemicalParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemicalParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.DOWN, chemicalParser.getServiceStatus().getStatus());
} catch (Exception e) {
......@@ -476,7 +476,7 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = chemicalParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("");
chemicalParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.CHANGED, chemicalParser.getServiceStatus().getStatus());
} catch (Exception e) {
......@@ -559,7 +559,7 @@ public class ChemicalParserTest extends AnnotationTestFunctions {
chemicalParser.setCache(new GeneralCacheWithExclusion(chemicalParser.getCache(), 1));
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
chemicalParser.setWebPageDownloader(mockDownloader);
try {
chemicalParser.getChemicals(diseaseID, idsList);
......
......@@ -597,7 +597,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = drugBankHTMLParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
drugBankHTMLParser.setWebPageDownloader(mockDownloader);
drugBankHTMLParser.refreshCacheQuery("http://google.pl/");
fail("Exception expected");
......@@ -616,7 +616,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
GeneralCacheInterface cache = drugBankHTMLParser.getCache();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
drugBankHTMLParser.setWebPageDownloader(mockDownloader);
drugBankHTMLParser.setCache(null);
......@@ -709,7 +709,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = drugBankHTMLParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
drugBankHTMLParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.DOWN, drugBankHTMLParser.getServiceStatus().getStatus());
} catch (Exception e) {
......@@ -725,7 +725,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = drugBankHTMLParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("");
drugBankHTMLParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.CHANGED, drugBankHTMLParser.getServiceStatus().getStatus());
} catch (Exception e) {
......
......@@ -169,7 +169,7 @@ public class MeSHParserTest extends AnnotationTestFunctions {
MiriamData meshID = new MiriamData(MiriamType.MESH_2012, "D004298");
MeSHParser parserUnderTest = new MeSHParser();
WebPageDownloader webPageDownloader = Mockito.mock(WebPageDownloader.class);
when(webPageDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(webPageDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
parserUnderTest.setWebPageDownloader(webPageDownloader);
parserUnderTest.getMeSH(meshID);
......@@ -276,7 +276,7 @@ public class MeSHParserTest extends AnnotationTestFunctions {
try {
meshParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
meshParser.setWebPageDownloader(mockDownloader);
MiriamData meshID = new MiriamData(MiriamType.MESH_2012, "D010300");
......@@ -299,7 +299,7 @@ public class MeSHParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = meshParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
meshParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.DOWN, meshParser.getServiceStatus().getStatus());
} catch (Exception e) {
......@@ -315,7 +315,7 @@ public class MeSHParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = meshParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new WrongResponseCodeIOException(null, HttpStatus.SC_NOT_FOUND));
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new WrongResponseCodeIOException(null, HttpStatus.SC_NOT_FOUND));
meshParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.CHANGED, meshParser.getServiceStatus().getStatus());
} catch (Exception e) {
......
......@@ -227,7 +227,7 @@ public class MiriamConnectorTest extends AnnotationTestFunctions {
// exclude first cached value
miriamConnector.setCache(new GeneralCacheWithExclusion(cache, 1));
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
miriamConnector.setWebPageDownloader(mockDownloader);
miriamConnector.getUrlString2(TaxonomyBackend.HUMAN_TAXONOMY);
......@@ -251,7 +251,7 @@ public class MiriamConnectorTest extends AnnotationTestFunctions {
// exclude first cached value
miriamConnector.setCache(new GeneralCacheWithExclusion(cache, 1));
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenReturn("");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("");
miriamConnector.setWebPageDownloader(mockDownloader);
miriamConnector.getUrlString2(TaxonomyBackend.HUMAN_TAXONOMY);
......@@ -273,7 +273,7 @@ public class MiriamConnectorTest extends AnnotationTestFunctions {
WebPageDownloader downloader = miriamConnector.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
miriamConnector.setWebPageDownloader(mockDownloader);
miriamConnector.refreshCacheQuery("http://google.pl/");
fail("Exception expected");
......
......@@ -232,7 +232,7 @@ public class PubmedParserTest extends AnnotationTestFunctions {
try {
pubmedParser.setCache(null);
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException());
pubmedParser.setWebPageDownloader(mockDownloader);
String query = PubmedParser.PUBMED_PREFIX + PubmedParser.SERVICE_STATUS_PUBMED_ID;
......@@ -289,7 +289,7 @@ public class PubmedParserTest extends AnnotationTestFunctions {
WebPageDownloader downloader = pubmedParser.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);