Created
June 4, 2015 04:58
-
-
Save mnrasul/7859e254ba133f524306 to your computer and use it in GitHub Desktop.
Dropwizard test example
This file contains hidden or 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
import ca.nazim.NazimApplication; | |
import ca.nazim.NazimConfiguration; | |
import ca.nazim.auth.NazimUser; | |
import io.dropwizard.jdbi.DBIFactory; | |
import io.dropwizard.testing.junit.DropwizardAppRule; | |
import org.junit.Assert; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.skife.jdbi.v2.DBI; | |
public class UserDAOTest { | |
@Rule | |
public final DropwizardAppRule<NazimConfiguration> RULE = | |
new DropwizardAppRule<NazimConfiguration>(NazimApplication.class, | |
"/Users/nasir/sources/nazim/config.yml"); | |
@Test | |
public void testCreateAndRead() { | |
final DBIFactory factory = new DBIFactory(); | |
final DBI jdbi = factory.build(RULE.getEnvironment(), RULE.getConfiguration().getDataSourceFactory(), "postgresql"); | |
UserDAO userDAO = jdbi.onDemand(UserDAO.class); | |
String username = "haha"+System.currentTimeMillis(); | |
userDAO.insert(username, "password", "phone", false, false); | |
NazimUser nazimUser = userDAO.readUser(username); | |
Assert.assertNotNull(nazimUser); | |
Assert.assertEquals(nazimUser.getSubjectId(), username); | |
userDAO.delete(username); | |
nazimUser = userDAO.readUser(username); | |
Assert.assertNull(nazimUser); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment