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

services are mocked deeper

parent 2dffc17a
Pipeline #9639 passed with stage
in 9 minutes and 16 seconds
package lcsb.mapviewer.api;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
......@@ -32,6 +35,7 @@ import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.annotation.Rollback;
......@@ -46,6 +50,7 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.ComplexZipConverter;
import lcsb.mapviewer.converter.ComplexZipConverterParams;
......@@ -59,6 +64,8 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelSubmodelConnection;
import lcsb.mapviewer.model.map.model.SubmodelType;
import lcsb.mapviewer.persist.DbUtils;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IProjectService;
import lcsb.mapviewer.services.interfaces.IUserService;
@Transactional
......@@ -312,4 +319,21 @@ public abstract class RestTestFunctions {
return tmp.toString();
}
protected IProjectService createProjectMockServiceForModel(Model model) {
try {
IProjectService mockModelService = Mockito.mock(IProjectService.class);
Mockito.when(mockModelService.getProjectByProjectId(anyString(), anyString())).thenReturn(model.getProject());
return mockModelService;
} catch (lcsb.mapviewer.services.SecurityException e) {
throw new InvalidStateException(e);
}
}
protected IModelService createModelMockServiceForModel(Model model) throws lcsb.mapviewer.services.SecurityException {
IModelService mockModelService = Mockito.mock(IModelService.class);
Mockito.when(mockModelService.getLastModelByProjectId(anyString(), any())).thenReturn(model);
return mockModelService;
}
}
package lcsb.mapviewer.api.projects.drugs;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import java.util.List;
import java.util.Map;
......@@ -16,8 +16,11 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IProjectService;
public class DrugRestImplTest extends RestTestFunctions {
Logger logger = Logger.getLogger(DrugRestImplTest.class);
......@@ -53,7 +56,7 @@ public class DrugRestImplTest extends RestTestFunctions {
throw e;
}
}
@Test
public void testTargetWithEmptyMechanism() throws Exception {
try {
......@@ -69,9 +72,8 @@ public class DrugRestImplTest extends RestTestFunctions {
private DrugRestImpl createMockProjectRest(String string) throws Exception {
Model model = super.getModelForFile(string, true);
IModelService mockModelService = Mockito.mock(IModelService.class);
Mockito.when(mockModelService.getLastModelByProjectId(anyString(), any())).thenReturn(model);
_drugRestImpl.setModelService(mockModelService);
_drugRestImpl.setModelService(createModelMockServiceForModel(model));
_drugRestImpl.setProjectService(createProjectMockServiceForModel(model));
return _drugRestImpl;
}
......
......@@ -58,9 +58,8 @@ public class MiRnaRestImplTest extends RestTestFunctions {
private MiRnaRestImpl createMockProjectRest(String string) throws Exception {
Model model = super.getModelForFile(string, true);
IModelService mockModelService = Mockito.mock(IModelService.class);
Mockito.when(mockModelService.getLastModelByProjectId(anyString(), any())).thenReturn(model);
_miRnaRestImpl.setModelService(mockModelService);
_miRnaRestImpl.setModelService(createModelMockServiceForModel(model));
_miRnaRestImpl.setProjectService(createProjectMockServiceForModel(model));
return _miRnaRestImpl;
}
......
......@@ -19,4 +19,7 @@ log4j.logger.org.springframework=warn
log4j.logger.org.hibernate=warn
log4j.logger.lcsb=debug
log4j.logger.lcsb.mapviewer.annotation.cache=info
log4j.logger.lcsb.mapviewer.persist=info
\ No newline at end of file
log4j.logger.lcsb.mapviewer.persist=info
#There are plenty of useless warnings in jsbml library
log4j.logger.org.sbml.jsbml=error
\ No newline at end of file
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