Commit 816aadd2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

dapi mock fixed

parent 1a4c9acf
Pipeline #45306 failed with stage
in 33 minutes and 7 seconds
package lcsb.mapviewer.annotation.services.dapi;
import javax.annotation.PostConstruct;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
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;
@Profile("ctdTestProfile")
@Configuration
public class CtdDapiConfiguration {
@Autowired
DapiConnector dapiConnector;
private ConfigurationDao configurationDao;
private String dapiLogin;
private String dapiPassword;
......@@ -19,26 +24,25 @@ public class CtdDapiConfiguration {
public CtdDapiConfiguration() {
dapiLogin = System.getenv("DAPI_TEST_LOGIN");
dapiPassword = System.getenv("DAPI_TEST_PASSWORD");
}
@PostConstruct
public void init() {
}
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = (DapiConnectorImpl) Mockito.spy(dapiConnector);
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
Mockito.doReturn("https://dapi.lcsb.uni.lu/api/database/CTD/releases/2019.02/").when(mock)
.getLatestReleaseUrl("CTD");
.getLatestReleaseUrl("CTD");
Mockito.doReturn(true).when(mock).isValidConnection();
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock arg0) throws Throwable {
mock.login(dapiLogin, dapiPassword);
return null;
}
}).when(mock).login();
return mock;
}
......
package lcsb.mapviewer.annotation.services.dapi;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
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;
@Profile("drugBankTestProfile")
@Configuration
public class DrugBankDapiConfiguration {
@Autowired
DapiConnector dapiConnector;
private ConfigurationDao configurationDao;
private String dapiLogin;
private String dapiPassword;
......@@ -24,21 +27,14 @@ public class DrugBankDapiConfiguration {
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = (DapiConnectorImpl) Mockito.spy(dapiConnector);
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
Mockito.doReturn("https://dapi.lcsb.uni.lu/api/database/DrugBank/releases/5.1/").when(mock)
.getLatestReleaseUrl("DrugBank");
.getLatestReleaseUrl("DrugBank");
Mockito.doReturn(true).when(mock).isValidConnection();
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock arg0) throws Throwable {
mock.login(dapiLogin, dapiPassword);
return null;
}
}).when(mock).login();
return mock;
}
......
package lcsb.mapviewer.annotation.services.dapi;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
@Profile("dapiNotConnectedTestProfile")
@Configuration
public class DrugBankDapiNoConnectionConfiguration {
@Autowired
private ConfigurationDao configurationDao;
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnector mock = Mockito.mock(DapiConnector.class);
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(false).when(mock).isValidConnection();
......
......@@ -4,16 +4,22 @@ 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 lcsb.mapviewer.persist.dao.ConfigurationDao;
@Profile("dapiDownTestProfile")
@Configuration
public class DrugBankDapiWithProblemConfiguration {
@Autowired
private ConfigurationDao configurationDao;
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnector mock = Mockito.mock(DapiConnector.class, Mockito.CALLS_REAL_METHODS);
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
when(mock.getAuthenticatedContent(anyString()))
.thenThrow(new DapiConnectionException("Simulated connection problem", -1));
......
......@@ -5,13 +5,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import lcsb.mapviewer.annotation.services.dapi.*;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
@Profile("dapiUnavailableTestProfile")
@Configuration
public class DapiUnavailableConfiguration {
@Autowired
private DapiConnector dapiConnector;
private ConfigurationDao configurationDao;
public DapiUnavailableConfiguration() {
}
......@@ -19,7 +20,7 @@ public class DapiUnavailableConfiguration {
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = (DapiConnectorImpl) Mockito.spy(dapiConnector);
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(false).when(mock).isValidConnection();
......
......@@ -7,13 +7,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import lcsb.mapviewer.annotation.services.dapi.*;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
@Profile("ctdTestProfile")
@Configuration
public class ServiceCtdDapiConfiguration {
@Autowired
private DapiConnector dapiConnector;
private ConfigurationDao configurationDao;
private String dapiLogin;
private String dapiPassword;
......@@ -26,15 +27,15 @@ public class ServiceCtdDapiConfiguration {
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = (DapiConnectorImpl) Mockito.spy(dapiConnector);
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
Mockito.doReturn("https://dapi.lcsb.uni.lu/api/database/CTD/releases/2019.02/").when(mock)
.getLatestReleaseUrl(anyString());
Mockito.doReturn(true).when(mock).isValidConnection();
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
return mock;
}
......
......@@ -5,13 +5,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import lcsb.mapviewer.annotation.services.dapi.*;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
@Profile("drugBankTestProfile")
@Configuration
public class DrugBankDapiConfiguration {
@Autowired
private DapiConnector dapiConnector;
private ConfigurationDao configurationDao;
private String dapiLogin;
private String dapiPassword;
......@@ -24,15 +25,14 @@ public class DrugBankDapiConfiguration {
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = (DapiConnectorImpl) Mockito.spy(dapiConnector);
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
Mockito.doReturn("https://dapi.lcsb.uni.lu/api/database/DrugBank/releases/5.1/").when(mock)
.getLatestReleaseUrl("DrugBank");
Mockito.doReturn(true).when(mock).isValidConnection();
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
return mock;
}
......
......@@ -5,13 +5,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import lcsb.mapviewer.annotation.services.dapi.*;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
@Profile("webCtdTestProfile")
@Configuration
public class WebCtdDapiConfiguration {
@Autowired
private DapiConnector dapiConnector;
private ConfigurationDao configurationDao;
private String dapiLogin;
private String dapiPassword;
......@@ -24,12 +25,11 @@ public class WebCtdDapiConfiguration {
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = (DapiConnectorImpl) Mockito.spy(dapiConnector);
Mockito.doReturn(true).when(mock).isValidConnection();
DapiConnectorImpl mock = Mockito.spy(new DapiConnectorImpl(configurationDao));
Mockito.doReturn(dapiLogin).when(mock).getDapiLogin();
Mockito.doReturn(dapiPassword).when(mock).getDapiPassword();
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