Skip to content

Instantly share code, notes, and snippets.

@davinkevin
Created September 5, 2015 11:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davinkevin/bb4f62aaec031b68b8f3 to your computer and use it in GitHub Desktop.
Save davinkevin/bb4f62aaec031b68b8f3 to your computer and use it in GitHub Desktop.
Init of Repository Test
package lan.dk.podcastserver.repository;
import com.ninja_squad.dbsetup.operation.Operation;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import static com.ninja_squad.dbsetup.Operations.deleteAllFrom;
import static com.ninja_squad.dbsetup.Operations.sequenceOf;
import static org.hibernate.search.jpa.Search.getFullTextEntityManager;
/**
* Created by kevin on 17/08/15 for Podcast Server
*/
@Configuration
@EnableJpaRepositories(basePackages = "lan.dk.podcastserver.repository")
@EntityScan(basePackages = "lan.dk.podcastserver.entity")
public class DatabaseConfiguraitonTest {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.build();
}
@Bean
@Autowired
public FullTextEntityManager fullTextEntityManager(EntityManager entityManager) {
return getFullTextEntityManager(entityManager);
}
public static final DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral(" ").append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();
public static final Operation DELETE_ALL_PODCASTS = deleteAllFrom("PODCAST");
public static final Operation DELETE_ALL_ITEMS = deleteAllFrom("ITEM");
public static final Operation DELETE_ALL_TAGS = sequenceOf(deleteAllFrom("PODCAST_TAG"), deleteAllFrom("TAG"));
public static final Operation DELETE_ALL = sequenceOf(DELETE_ALL_ITEMS, DELETE_ALL_TAGS, DELETE_ALL_PODCASTS, DELETE_ALL_TAGS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment