Skip to content

Instantly share code, notes, and snippets.

@enterprisesaas
Created December 19, 2013 14:43
Show Gist options
  • Select an option

  • Save enterprisesaas/8040150 to your computer and use it in GitHub Desktop.

Select an option

Save enterprisesaas/8040150 to your computer and use it in GitHub Desktop.
Skeleton unit test for User dao operations
package concepts;
import config.MongoConfig;
import model.User;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;
import static org.junit.Assert.assertNotNull;
public class MongoUserDBTest {
private ApplicationContext applicationContext;
private MongoOperations mongoOperations;
private UserMongoDao dao;
@Test
public void testApplicationContext() {
assertNotNull("ApplicationContext was null", applicationContext);
System.out.printf("ApplicationContext-> %s%n", applicationContext);
}
@Test
public void testMongoOperations() {
assertNotNull("MongoOperations was null", mongoOperations);
System.out.printf("MongoOperations-> %s%n", mongoOperations);
}
@Test
public void testUserMongoDao() {
assertNotNull("UserMongoDao was null", dao);
System.out.printf("UserMongoDao-> %s%n", dao);
}
@Test
public void testMongoPersistence() {
}
@Test
public void testMongoQuery() {
}
private User testUser() {
// Create User - simulated data from the UI or some other service/app
User user = new User();
user.setFirstName("David");
user.setLastName("King");
user.setEmail("david.king@software.net");
return user;
}
@Before
public void setUp() {
applicationContext = new AnnotationConfigApplicationContext(MongoConfig.class);
mongoOperations = applicationContext.getBean("mongoTemplate", MongoOperations.class);
dao = applicationContext.getBean("userMongoDao", UserMongoDao.class);
}
@After
public void tearDown() {
applicationContext = null;
mongoOperations = null;
dao = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment