Commit 0dcca279 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

provide credentials in the mocks

parent 68cbd242
Pipeline #45313 passed with stage
in 36 minutes and 51 seconds
......@@ -13,10 +13,21 @@ public class DrugBankDapiNoConnectionConfiguration {
@Autowired
private ConfigurationDao configurationDao;
private String dapiLogin;
private String dapiPassword;
public DrugBankDapiNoConnectionConfiguration() {
dapiLogin = System.getenv("DAPI_TEST_LOGIN");
dapiPassword = System.getenv("DAPI_TEST_PASSWORD");
}
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
Mockito.doReturn(false).when(mock).isValidConnection();
......
package lcsb.mapviewer.annotation.services.dapi;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
......@@ -16,17 +18,25 @@ public class DrugBankDapiWithProblemConfiguration {
@Autowired
private ConfigurationDao configurationDao;
private String dapiLogin;
private String dapiPassword;
public DrugBankDapiWithProblemConfiguration() {
dapiLogin = System.getenv("DAPI_TEST_LOGIN");
dapiPassword = System.getenv("DAPI_TEST_PASSWORD");
}
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
when(mock.getAuthenticatedContent(anyString()))
.thenThrow(new DapiConnectionException("Simulated connection problem", -1));
when(mock.getLatestReleaseUrl(anyString()))
.thenThrow(new DapiConnectionException("Simulated connection problem", -1));
Mockito.doThrow(new DapiConnectionException("Simulated connection problem", -1)).when(mock).getAuthenticatedContent(anyString());
Mockito.doThrow(new DapiConnectionException("Simulated connection problem", -1)).when(mock).getLatestReleaseUrl(anyString());
Mockito.doThrow(new DapiConnectionException("Simulated connection problem", -1)).when(mock).login();
Mockito.doReturn(true).when(mock).isValidConnection();
return mock;
......
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