-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1450 from Agaba-derrick/RegionServiceTests
regionTestwith DataSets
- Loading branch information
Showing
3 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/test/java/org/openelisglobal/region/RegionServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.openelisglobal.region; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.List; | ||
import java.util.Map; | ||
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; | ||
|
||
private Map<String, String> testRegions; | ||
|
||
@Before | ||
public void init() throws Exception { | ||
executeDataSetWithStateManagement("testdata/region.xml"); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
List<Region> regions = regionService.getAll(); | ||
for (Region region : regions) { | ||
if (region.getLastupdated() == null) { | ||
region.setLastupdated(new Timestamp(System.currentTimeMillis())); | ||
} | ||
} | ||
regionService.deleteAll(regions); | ||
|
||
} | ||
|
||
@Test | ||
public void createRegion_shouldCreateNewRegion() throws Exception { | ||
String regionName = "Midwest"; | ||
String regionId = "1"; | ||
Region region = createRegion(regionName, regionId); | ||
|
||
String savedRegionId = regionService.insert(region); | ||
|
||
Region savedRegion = regionService.get(savedRegionId); | ||
Assert.assertEquals(regionName, savedRegion.getRegion()); | ||
Assert.assertNotNull(savedRegion.getId()); | ||
} | ||
|
||
@Test | ||
public void updateRegion_shouldUpdateExistingRegion() throws Exception { | ||
Region existingRegion = regionService.get("2"); | ||
Assert.assertNotNull(existingRegion); | ||
|
||
existingRegion.setRegion("Updated Northeast"); | ||
regionService.update(existingRegion); | ||
|
||
Region updatedRegion = regionService.get("2"); | ||
Assert.assertEquals("Updated Northeast", updatedRegion.getRegion()); | ||
} | ||
|
||
@Test | ||
public void getAllRegions_shouldReturnAllRegions() throws Exception { | ||
List<Region> regions = regionService.getAll(); | ||
Assert.assertEquals(5, regions.size()); | ||
} | ||
|
||
@Test | ||
public void deleteRegion_shouldRemoveAnExistingRegion() throws Exception { | ||
Region region = regionService.get("1"); | ||
Assert.assertNotNull(region); | ||
|
||
Assert.assertEquals(5, regionService.getAll().size()); | ||
|
||
regionService.delete(region); | ||
Assert.assertEquals(4, regionService.getAll().size()); | ||
} | ||
|
||
private Region createRegion(String regionName, String regionId) { | ||
Region region = new Region(); | ||
region.setRegion(regionName); | ||
region.setLastupdated(new Timestamp(System.currentTimeMillis())); | ||
return region; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- | ||
* The contents of this file are subject to the Mozilla Public License | ||
* Version 1.1 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://www.mozilla.org/MPL/ | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations under | ||
* the License. | ||
* | ||
* The Original Code is OpenELIS code. | ||
* | ||
* Copyright (C) ITECH, University of Washington, Seattle WA. All Rights Reserved. | ||
--> | ||
<dataset> | ||
<!-- Region Entries --> | ||
|
||
<region id="1" region="Midwest" lastupdated="2023-10-01 12:00:00.000" /> | ||
<region id="2" region="Northeast" lastupdated="2023-10-01 12:00:00.000" /> | ||
<region id="3" region="Southeast" lastupdated="2023-10-01 12:00:00.000" /> | ||
<region id="4" region="Southwest" lastupdated="2023-10-01 12:00:00.000" /> | ||
<region id="5" region="Northwest" lastupdated="2023-10-01 12:00:00.000" /> | ||
</dataset> |