Skip to content

Instantly share code, notes, and snippets.

@debop
Created July 20, 2013 10:13
Show Gist options
  • Save debop/6044549 to your computer and use it in GitHub Desktop.
Save debop/6044549 to your computer and use it in GitHub Desktop.
package kr.hconnect.mongo.test.music.repositories;
import kr.hconnect.mongo.test.music.AbstractIntegrationTest;
import kr.hconnect.mongo.test.music.MongoConfiguration;
import kr.hconnect.mongo.test.music.model.Album;
import kr.hconnect.mongo.test.music.model.AlbumRepository;
import kr.hconnect.mongo.test.music.model.Stars;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
/**
* kr.hconnect.mongo.test.music.repositories.AlbumRepositoryIntegrationTest
*
* @author 배성혁 [email protected]
* @since 13. 7. 20. 오후 4:53
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MongoConfiguration.class })
public class AlbumRepositoryIntegrationTest extends AbstractIntegrationTest {
@Autowired
AlbumRepository repository;
@Before
public void purgeRepository() {
repository.deleteAll();
super.setup();
}
@Test
public void createAlbum() throws Exception {
repository.save(albums);
assertSingleGruxAlbum(repository.findOne(bigWhiskey.getId()));
}
@Test
public void findsAlbumByConcreteTrackName() throws Exception {
repository.save(albums);
assertSingleGruxAlbum(repository.findByTracksName("Grux"));
List<Album> albums = repository.findByTracksName("Foo");
assertThat(albums.isEmpty()).isTrue();
}
@Test
public void findsAllAlbumsByTrackNameLike() throws Exception {
repository.save(albums);
assertBothAlbums(repository.findByTracksNameLike("*it*"));
}
@Test
public void findsAlbumsByTrackRating() throws Exception {
bigWhiskey.getTracks().get(4).setRating(Stars.FOUR);
repository.save(albums);
assertSingleGruxAlbum(repository.findByTracksRatingGreaterThan(Stars.THREE));
List<Album> albums = repository.findByTracksRatingGreaterThan(Stars.FOUR);
assertThat(albums.isEmpty()).isTrue();
}
private void assertSingleGruxAlbum(List<Album> albums) {
Assert.assertThat(albums, CoreMatchers.is(CoreMatchers.notNullValue()));
Assert.assertThat(albums.size(), CoreMatchers.is(1));
Assert.assertThat(albums.get(0), CoreMatchers.is(CoreMatchers.notNullValue(Album.class)));
assertSingleGruxAlbum(albums.get(0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment