From 3fb92e01ceaf5cb66011936fbf177169e99e4e5d Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 8 Aug 2017 14:03:35 +0200 Subject: [PATCH] spring injection added --- .../resources/applicationContext-rest.xml | 1 + .../api/projects/models/AllModelsTests.java | 3 +- .../projects/models/ModelRestImplTest.java | 58 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 rest-api/src/test/java/lcsb/mapviewer/api/projects/models/ModelRestImplTest.java diff --git a/rest-api/src/main/resources/applicationContext-rest.xml b/rest-api/src/main/resources/applicationContext-rest.xml index 5cbacb6fc6..2642267ee9 100644 --- a/rest-api/src/main/resources/applicationContext-rest.xml +++ b/rest-api/src/main/resources/applicationContext-rest.xml @@ -15,6 +15,7 @@ <bean id="CommentRestImpl" class="lcsb.mapviewer.api.projects.comments.CommentRestImpl"/> <bean id="ProjectRestImpl" class="lcsb.mapviewer.api.projects.ProjectRestImpl"/> + <bean id="ModelRestImpl" class="lcsb.mapviewer.api.projects.models.ModelRestImpl"/> <bean id="BioEntitiesRestImpl" class="lcsb.mapviewer.api.projects.models.bioEntities.BioEntitiesRestImpl"/> <bean id="ChemicalRestImpl" class="lcsb.mapviewer.api.projects.chemicals.ChemicalRestImpl"/> <bean id="ElementsRestImpl" class="lcsb.mapviewer.api.projects.models.bioEntities.elements.ElementsRestImpl"/> diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/AllModelsTests.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/AllModelsTests.java index 58bce555cf..3cb26a74c6 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/AllModelsTests.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/AllModelsTests.java @@ -10,7 +10,8 @@ import lcsb.mapviewer.api.projects.models.publications.AllPublicationsTests; @RunWith(Suite.class) @SuiteClasses({ // AllBioeEntitiesTests.class, // - AllPublicationsTests.class// + AllPublicationsTests.class, // + ModelRestImplTest.class,// }) public class AllModelsTests { diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/ModelRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/ModelRestImplTest.java new file mode 100644 index 0000000000..8340abe87e --- /dev/null +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/ModelRestImplTest.java @@ -0,0 +1,58 @@ +package lcsb.mapviewer.api.projects.models; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; + +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; + +import lcsb.mapviewer.api.RestTestFunctions; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.services.interfaces.IModelService; + +public class ModelRestImplTest extends RestTestFunctions { + + @Autowired + ModelRestImpl _projectRestImpl; + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testModels() throws Exception { + try { + ModelRestImpl modelRest = createMockProjectRest("testFiles/model/sample.xml"); + List<ModelMetaData> result = modelRest.getModels("sample", token.getId()); + assertEquals(1, result.size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + private ModelRestImpl 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); + _projectRestImpl.setModelService(mockModelService); + return _projectRestImpl; + } + +} -- GitLab