forked from cdos-rla/colorado-rla
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #127 from DemocracyDevelopers/queries-tests
Test for DB queries
- Loading branch information
Showing
15 changed files
with
1,144 additions
and
206 deletions.
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
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
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
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
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
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
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
93 changes: 93 additions & 0 deletions
93
...er/eclipse-project/src/test/java/us/freeandfair/corla/query/AdministratorQueriesTest.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,93 @@ | ||
package us.freeandfair.corla.query; | ||
|
||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testng.annotations.*; | ||
import us.freeandfair.corla.model.Administrator; | ||
import us.freeandfair.corla.model.County; | ||
import us.freeandfair.corla.persistence.Persistence; | ||
import us.freeandfair.corla.util.TestClassWithDatabase; | ||
|
||
import java.util.Properties; | ||
|
||
import static org.testng.AssertJUnit.assertEquals; | ||
import static org.testng.AssertJUnit.assertNull; | ||
|
||
@Test | ||
public class AdministratorQueriesTest extends TestClassWithDatabase { | ||
|
||
@Test | ||
public void testByUsernameState() { | ||
|
||
Administrator admin = new Administrator("testname", | ||
Administrator.AdministratorType.STATE, | ||
"fulltestname", | ||
null); | ||
|
||
Persistence.saveOrUpdate(admin); | ||
assertEquals(AdministratorQueries.byUsername("testname"), admin); | ||
} | ||
|
||
|
||
@Test | ||
public void testByUsernameCounty() { | ||
|
||
County county = new County("test", 1L); | ||
Persistence.saveOrUpdate(county); | ||
Administrator admin = new Administrator("testname", | ||
Administrator.AdministratorType.COUNTY, | ||
"fulltestname", | ||
county | ||
); | ||
|
||
Persistence.saveOrUpdate(admin); | ||
assertEquals(AdministratorQueries.byUsername("testname"), admin); | ||
} | ||
|
||
@Test | ||
public void testByUsernameStateAndCounty() { | ||
County county = new County("test", 1L); | ||
Persistence.saveOrUpdate(county); | ||
Administrator countyadmin = new Administrator("county", | ||
Administrator.AdministratorType.COUNTY, | ||
"countyfull", | ||
county); | ||
|
||
Persistence.saveOrUpdate(countyadmin); | ||
|
||
Administrator stateadmin = new Administrator("state", | ||
Administrator.AdministratorType.STATE, | ||
"statefull", | ||
null); | ||
|
||
Persistence.saveOrUpdate(stateadmin); | ||
|
||
assertEquals(AdministratorQueries.byUsername("county"),countyadmin); | ||
assertEquals(AdministratorQueries.byUsername("state"), stateadmin); | ||
} | ||
|
||
@Test | ||
public void testSameName() { | ||
|
||
Administrator first = new Administrator("state", | ||
Administrator.AdministratorType.STATE, | ||
"first", | ||
null); | ||
|
||
Administrator second = new Administrator("state", | ||
Administrator.AdministratorType.STATE, | ||
"second", | ||
null); | ||
Persistence.saveOrUpdate(first); | ||
Persistence.saveOrUpdate(second); | ||
|
||
assertNull(AdministratorQueries.byUsername("state")); | ||
} | ||
|
||
@Test | ||
public void testDBError() { | ||
// Close the DB | ||
Persistence.commitTransaction(); | ||
assertNull(AdministratorQueries.byUsername("username")); | ||
Persistence.beginTransaction(); | ||
} | ||
} |
Oops, something went wrong.