From c92f0754bdf1ae90240d199ad533dac65ea8f691 Mon Sep 17 00:00:00 2001 From: Agaba Derrick Date: Tue, 13 Aug 2024 15:16:31 +0300 Subject: [PATCH 1/4] Add-Region-Test --- .../org/openelisglobal/AppTestConfig.java | 3 +- .../region/RegionServiceTest.java | 88 +++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/openelisglobal/region/RegionServiceTest.java diff --git a/src/test/java/org/openelisglobal/AppTestConfig.java b/src/test/java/org/openelisglobal/AppTestConfig.java index a5260620be..e1e37d3a8e 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -50,7 +50,8 @@ "org.openelisglobal.systemusermodule.service", "org.openelisglobal.rolemodule.service", "org.openelisglobal.systemusermodule.daoimpl", "org.openelisglobal.systemusermodule.service", "org.openelisglobal.login.service", "org.openelisglobal.view", "org.openelisglobal.search.service", - "org.openelisglobal.sample.daoimpl", }, excludeFilters = { + "org.openelisglobal.sample.daoimpl","org.openelisglobal.region.service", + "org.openelisglobal.region.dao" }, excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.patient.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.dictionary.controller.*.java"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.config.*"), diff --git a/src/test/java/org/openelisglobal/region/RegionServiceTest.java b/src/test/java/org/openelisglobal/region/RegionServiceTest.java new file mode 100644 index 0000000000..b2bad61787 --- /dev/null +++ b/src/test/java/org/openelisglobal/region/RegionServiceTest.java @@ -0,0 +1,88 @@ +package org.openelisglobal.region; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openelisglobal.BaseWebContextSensitiveTest; +import org.openelisglobal.region.service.RegionService; +import org.openelisglobal.region.valueholder.Region; +import org.springframework.beans.factory.annotation.Autowired; + +public class RegionServiceTest extends BaseWebContextSensitiveTest { + + @Autowired + RegionService regionService; + + @Before + public void init() throws Exception { + regionService.deleteAll(regionService.getAll()); + } + + @After + public void tearDown() { + regionService.deleteAll(regionService.getAll()); + } + + @Test + public void createRegion_shouldCreateNewRegion() throws Exception { + String regionName = "Midwest"; + String regionId = "1"; + + Region region = createRegion(regionName, regionId); + + Assert.assertEquals(0, regionService.getAll().size()); + String savedRegionId = regionService.insert(region); + Region savedRegion = regionService.get(savedRegionId); + + Assert.assertEquals(1, regionService.getAll().size()); + Assert.assertEquals(regionName, savedRegion.getRegion()); + Assert.assertNotNull(savedRegion.getId()); + } + + @Test + public void updateRegion_shouldUpdateRegionInformation() throws Exception { + String regionName = "Northeast"; + String regionId = "2"; + + Region region = createRegion(regionName, regionId); + String savedRegionId = regionService.insert(region); + Region savedRegion = regionService.get(savedRegionId); + + savedRegion.setRegion("Southeast"); + regionService.update(savedRegion); + + Region updatedRegion = regionService.get(savedRegionId); + + Assert.assertEquals("Southeast", updatedRegion.getRegion()); + } + + @Test + public void getAllRegions_shouldReturnAllRegions() throws Exception { + Region region = new Region(); + region.setRegion("Southwest"); + regionService.insert(region); + + Assert.assertEquals(1, regionService.getAll().size()); + } + + @Test + public void deleteRegion_shouldRemoveRegion() throws Exception { + Region region = new Region(); + region.setRegion("Northwest"); + regionService.insert(region); + + Assert.assertEquals(1, regionService.getAll().size()); + + regionService.delete(region); + + Assert.assertEquals(0, regionService.getAll().size()); + } + + private Region createRegion(String regionName, String regionId) { + Region region = new Region(); + region.setRegion(regionName); + region.setId(regionId); + return region; + } +} \ No newline at end of file From d019401f15607bd45c569cdf21fa26776badd74d Mon Sep 17 00:00:00 2001 From: Agaba Derrick Date: Tue, 13 Aug 2024 15:45:51 +0300 Subject: [PATCH 2/4] fix --- src/test/java/org/openelisglobal/AppTestConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/openelisglobal/AppTestConfig.java b/src/test/java/org/openelisglobal/AppTestConfig.java index e1e37d3a8e..c13f65c6aa 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -50,7 +50,7 @@ "org.openelisglobal.systemusermodule.service", "org.openelisglobal.rolemodule.service", "org.openelisglobal.systemusermodule.daoimpl", "org.openelisglobal.systemusermodule.service", "org.openelisglobal.login.service", "org.openelisglobal.view", "org.openelisglobal.search.service", - "org.openelisglobal.sample.daoimpl","org.openelisglobal.region.service", + "org.openelisglobal.sample.daoimpl", "org.openelisglobal.region.service", "org.openelisglobal.region.dao" }, excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.patient.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.dictionary.controller.*.java"), From d1c6e6e138cea745b78dcc17e3682589e95e5349 Mon Sep 17 00:00:00 2001 From: Agaba Derrick Date: Thu, 22 Aug 2024 19:24:25 +0300 Subject: [PATCH 3/4] remove-spaces --- .../org/openelisglobal/region/RegionServiceTest.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/test/java/org/openelisglobal/region/RegionServiceTest.java b/src/test/java/org/openelisglobal/region/RegionServiceTest.java index b2bad61787..ac5f41ded9 100644 --- a/src/test/java/org/openelisglobal/region/RegionServiceTest.java +++ b/src/test/java/org/openelisglobal/region/RegionServiceTest.java @@ -28,13 +28,10 @@ public void tearDown() { public void createRegion_shouldCreateNewRegion() throws Exception { String regionName = "Midwest"; String regionId = "1"; - Region region = createRegion(regionName, regionId); - Assert.assertEquals(0, regionService.getAll().size()); String savedRegionId = regionService.insert(region); Region savedRegion = regionService.get(savedRegionId); - Assert.assertEquals(1, regionService.getAll().size()); Assert.assertEquals(regionName, savedRegion.getRegion()); Assert.assertNotNull(savedRegion.getId()); @@ -44,16 +41,12 @@ public void createRegion_shouldCreateNewRegion() throws Exception { public void updateRegion_shouldUpdateRegionInformation() throws Exception { String regionName = "Northeast"; String regionId = "2"; - Region region = createRegion(regionName, regionId); String savedRegionId = regionService.insert(region); Region savedRegion = regionService.get(savedRegionId); - savedRegion.setRegion("Southeast"); regionService.update(savedRegion); - Region updatedRegion = regionService.get(savedRegionId); - Assert.assertEquals("Southeast", updatedRegion.getRegion()); } @@ -62,7 +55,6 @@ public void getAllRegions_shouldReturnAllRegions() throws Exception { Region region = new Region(); region.setRegion("Southwest"); regionService.insert(region); - Assert.assertEquals(1, regionService.getAll().size()); } @@ -71,11 +63,8 @@ public void deleteRegion_shouldRemoveRegion() throws Exception { Region region = new Region(); region.setRegion("Northwest"); regionService.insert(region); - Assert.assertEquals(1, regionService.getAll().size()); - regionService.delete(region); - Assert.assertEquals(0, regionService.getAll().size()); } From c5c2bef46f6bc930ade442184187ca84e4a532db Mon Sep 17 00:00:00 2001 From: Agaba Derrick Date: Mon, 4 Nov 2024 23:07:49 +0300 Subject: [PATCH 4/4] spotless:apply --- src/test/java/org/openelisglobal/AppTestConfig.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/openelisglobal/AppTestConfig.java b/src/test/java/org/openelisglobal/AppTestConfig.java index 6ba48bb363..d3d34c6499 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -73,13 +73,12 @@ "org.openelisglobal.systemusermodule.service", "org.openelisglobal.rolemodule.service", "org.openelisglobal.systemusermodule.daoimpl", "org.openelisglobal.systemusermodule.service", "org.openelisglobal.login.service", "org.openelisglobal.view", "org.openelisglobal.search.service", - "org.openelisglobal.region.service","org.openelisglobal.region.dao" , - "org.openelisglobal.sample.daoimpl", "org.openelisglobal.common.util", "org.openelisglobal.login.service", - "org.openelisglobal.view", "org.openelisglobal.search.service", "org.openelisglobal.sample", - "org.openelisglobal.sampleitem.", "org.openelisglobal.analysis", "org.openelisglobal.result.service", - "org.openelisglobal.result.daoimpl", "org.openelisglobal.resultlimit", "org.openelisglobal.resultlimits", - "org.openelisglobal.typeoftestresult", "org.openelisglobal.samplehuman", - "org.openelisglobal.role", }, excludeFilters = { + "org.openelisglobal.region.service", "org.openelisglobal.region.dao", "org.openelisglobal.sample.daoimpl", + "org.openelisglobal.common.util", "org.openelisglobal.login.service", "org.openelisglobal.view", + "org.openelisglobal.search.service", "org.openelisglobal.sample", "org.openelisglobal.sampleitem.", + "org.openelisglobal.analysis", "org.openelisglobal.result.service", "org.openelisglobal.result.daoimpl", + "org.openelisglobal.resultlimit", "org.openelisglobal.resultlimits", "org.openelisglobal.typeoftestresult", + "org.openelisglobal.samplehuman", "org.openelisglobal.role", }, excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.patient.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.sample.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.dictionary.controller.*.java"),